老是说参数不对,请教一个Win32 API在C#中引用的写法!
迷死特兔 2005-04-08 05:38:18 Win32 API:
UINT MsiGetProductInfo(
LPCTSTR szProduct,
LPCTSTR szProperty,
LPTSTR lpValueBuf,
DWORD* pcchValueBuf
);
我这样写:
[System.Runtime.InteropServices.DllImport("msi.dll")]
public static extern uint MsiGetProductInfo(
//[MarshalAs(UnmanagedType.LPTStr)]
string productCode,
//[MarshalAs(UnmanagedType.LPTStr)]
string property,
StringBuilder shortPath,
int shortPathLength);
运行后报错:“未将对象引用设置到对象的实例”。我取消上面的注释,则可以运行程序,函数返回87,我查了一下SDK,这样说的:
// MessageId: ERROR_INVALID_PARAMETER
//
// MessageText:
//
// The parameter is incorrect.
//
#define ERROR_INVALID_PARAMETER 87L // dderror
请问,我该如何写参数呢?