我在Delphi 7中的代码中有以下代码:
var
objServiceConfig: PQueryServiceConfigA;
...
...
objServiceConfig:= AllocMem(anySize);
...
...
QueryServiceConfig(hSCService, objServiceConfig, anySize, anySize2)
.....
.....
Run Code Online (Sandbox Code Playgroud)
我收到错误: E2010 Incompatible types: 'LPQUERY_SERVICE_CONFIGW' and 'PQueryServiceConfigA'
在Delphi 7中一切正常但是将它迁移到Delphi XE4,我收到了这个错误.
当我改变上述声明objServiceConfig: PQueryServiceConfigA;给objServiceConfig: LPQUERY_SERVICE_CONFIG;它的工作原理.是对还是我还要做什么?
更新:
在Delphi XE4 WinSvc中,QueryServiceConfig声明如下
function QueryServiceConfig(hService: SC_HANDLE;
lpServiceConfig: LPQUERY_SERVICE_CONFIG; cbBufSize: DWORD;
var pcbBytesNeeded: DWORD): BOOL; stdcall;
{$EXTERNALSYM QueryServiceConfigA}
function QueryServiceConfigA(hService: SC_HANDLE;
lpServiceConfig: LPQUERY_SERVICE_CONFIGA; cbBufSize: DWORD;
var pcbBytesNeeded: DWORD): BOOL; stdcall;
{$EXTERNALSYM QueryServiceConfigW}
function QueryServiceConfigW(hService: SC_HANDLE;
lpServiceConfig: LPQUERY_SERVICE_CONFIGW; cbBufSize: DWORD;
var pcbBytesNeeded: DWORD): BOOL; stdcall;
Run Code Online (Sandbox Code Playgroud)
在Delphi7,WinSvc中,QueryServiceConfig声明如下
function QueryServiceConfig(hService: SC_HANDLE;
lpServiceConfig: PQueryServiceConfig; cbBufSize: DWORD;
var pcbBytesNeeded: DWORD): BOOL; stdcall;
{$EXTERNALSYM QueryServiceConfigA}
function QueryServiceConfigA(hService: SC_HANDLE;
lpServiceConfig: PQueryServiceConfigA; cbBufSize: DWORD;
var pcbBytesNeeded: DWORD): BOOL; stdcall;
{$EXTERNALSYM QueryServiceConfigW}
function QueryServiceConfigW(hService: SC_HANDLE;
lpServiceConfig: PQueryServiceConfigW; cbBufSize: DWORD;
var pcbBytesNeeded: DWORD): BOOL; stdcall;
Run Code Online (Sandbox Code Playgroud)
这意味着Delphi 7的第二个参数是PQueryServiceConfig/ A/W型,而Delphi XE4的类型是LPQUERY_SERVICE_CONFIG/ A/W
你应该简单地使用
var
objServiceConfig: PQueryServiceConfig;
Run Code Online (Sandbox Code Playgroud)
PQueryServiceConfigA在Delphi 7中声明为(ANSI版本),PQueryServiceConfigW在Delphi XE4中声明为(Unicode版本).
编辑:
除非你打开了"Typed @ operator"编译器选项({$T+}),否则这会E2010 Incompatible types: 'LPQUERY_SERVICE_CONFIGW' and 'PQueryServiceConfigW'在Delphi XE4中产生编译器错误.所以要么使用该选项,要么只是重新声明这样的函数:
function QueryServiceConfig(hService: SC_HANDLE; lpServiceConfig: PQueryServiceConfig; cbBufSize: DWORD;
var pcbBytesNeeded: DWORD): BOOL; stdcall;
external advapi32 name {$IFDEF UNICODE}'QueryServiceConfigW'{$ELSE}'QueryServiceConfigA'{$ENDIF};
Run Code Online (Sandbox Code Playgroud)
这样它应该在Delphi 7和XE4中编译.
| 归档时间: |
|
| 查看次数: |
645 次 |
| 最近记录: |