老是说参数不对,请教一个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

请问,我该如何写参数呢?
...全文
87 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Jim3 2005-04-08
  • 打赏
  • 举报
回复
调用的代码贴出来

DWORD* pcchValueBuf

应该用 ref int shortPathLength
The_Gathering 2005-04-08
  • 打赏
  • 举报
回复
最后一个参数是DWORD* 的话,肯定不能传int 进去啊

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧