应用程序注册服务StillImage
操作系统 - Windows XP SP3 编程环境 - Delphi 2010
我制作了接口模块:
unit StillImage;
interface
uses
Windows;
const
STI_VERSION = $00000002;
type
IStillImageW = interface(IUnknown)
['{641BD880-2DC8-11D0-90EA-00AA0060F86C}']
.......
function RegisterLaunchApplication(AppName, CommandLine: LPWSTR): HRESULT; stdcall;
.......
end;
PIStillImageW = ^IStillImageW;
function StiCreateInstanceW(hinst: HINST; dwVer: DWORD; ppSti: PIStillImageW; punkOuter: IUnknown): HResult; stdcall; external 'sti.dll' name 'StiCreateInstanceW';
implementation
end.
我尝试调用方法StiCreateInstanceW:
var
Still_Image: IStillImageW;
H_Res: HResult;
pwszAppName: PWideChar;
pwszCommandLine: PWideChar;
wszAppName: array[0..1000] of WideChar;
wszCommandLine: array[0..1000] of WideChar;
........
begin
........
H_Res := StiCreateInstanceW(GetModuleHandle(nil), STI_VERSION, @Still_Image, nil);
if H_Res <> S_OK then raise ...............
FillChar(wszAppName, SizeOf(wszAppName), 0);
FillChar(wszCommandLine, SizeOf(wszCommandLine), 0);
pwszAppName := StringToWideChar('Calculator', @wszAppName, SizeOf(wszAppName)-1);
pwszCommandLine := StringToWideChar('c:\WINDOWS\system32\calc.exe', @wszCommandLine, SizeOf(wszCommandLine)-1);
H_Res := 0;
H_Res := Still_Image.RegisterLaunchApplication(pwszAppName, pwszCommandLine);
if H_Res <> S_OK then raise ...............
...............
...............
结果我得到了:
H_Res = 0x80070057
这意味着:E_INVALIDARG
(一个或多个参数无效)
或:STIERR_INVALID_PARAM
我完成了与此处所写的完全相同的事情:
http://msdn.microsoft.com/en-us/library/windows/desktop/cc836550%28v=vs.85%29.aspx http://msdn.microsoft.com/en-us/library/windows/hardware/ff543798%28v=vs.85%29.aspx http://msdn.microsoft.com/en-us/library/windows/desktop/cc836552%28v=vs.85%29.aspx
我尝试了以下几行:
'c:\WINDOWS\system32\calc.exe'
'"c:\WINDOWS\system32\calc.exe"'
'\"c:\WINDOWS\system32\calc.exe\"'
'c:\\WINDOWS\\system32\\calc.exe'
'\"c:\\WINDOWS\\system32\\calc.exe\"'
没有区别。
始终是错误 - E_INVALIDARG
/ STIERR_INVALID_PARAM