ITPub博客

首页 > > > 如何使用DllImport调用这个c++函数?

如何使用DllImport调用这个c++函数?

作者:古月雪 时间:2019-09-25 10:17:29 0 删除 编辑

c++声明如下:

typedef struct _TOAST_MESSAGE{ CLSID guid; LPCWSTR lpTitle; LPCWSTR lpContent; LPCWSTR lpUri; LPCWSTR lpType;

} TOAST_MESSAGE;

extern"C"WINADVAPI

VOID

APIENTRYShell_PostMessageToast(_In_ TOAST_MESSAGE* toastMessage);

我想在C#中使用P/Invoke调用它,于是这样写的:

public struct _TOAST_MESSAGE{

public Guid guid;

public string lpTitle;

public string lpContent;

public string lpUri;

public string lpType;

}

[DllImport("ShellChromeApi.dll")]

private static extern void Shell_PostMessageToast(ref _TOAST_MESSAGE data);

    

 

 

发现这个代码并没有正常工作:正常情况下界面上应该有lpTitle,lpContent这两行文字的,但我这样调用,界面上这两行文字是空的,也没有提示错误,我不知道c++中的 LPCWSTR在c#中对应什么类型,但在c#中改为char*指针类型,又会提示项目部能使用指针(这是windows运行时组件项目),

我该怎么办呢?

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/3711/viewspace-3159539/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-07-09

  • 博文量
    160
  • 访问量
    1173