typedef struct _NOTIFYICONDATA {
DWORD cbSize;
HWND hWnd;
UINT uID;
UINT uFlags;
UINT uCallbackMessage;
HICON hIcon;
TCHAR szTip[64];
DWORD dwState;
DWORD dwStateMask;
TCHAR szInfo[256];
union {
UINT uTimeout;
UINT uVersion;
};
TCHAR szInfoTitle[64];
DWORD dwInfoFlags;
GUID guidItem;
HICON hBalloonIcon;
} NOTIFYICONDATA, *PNOTIFYICONDATA;
这是我自己写的,去掉了union的实现果然出错了:
internal struct NOTIFYICONDATA
{
public UInt32 cbSize;
public IntPtr hWnd;
public UInt32 uID;
public UInt32 uFlags;
public UInt32 uCallbackMessage;
public IntPtr hIcon;
public Char szTip;
public UInt32 dwState;
public UInt32 dwStateMask;
public Char szInfo;
public UInt32 uTimeout;
public UInt32 uVersion;
public Char szInfoTitle;
public UInt32 dwInfoFlags;
public Guid guidItem;
}
报错:
我在想能不能只给出前三个位置,然而还是错。
ShellAPI.h头文件中结构还是有 union
typedef struct _NOTIFYICONDATAA {
DWORD cbSize;
HWND hWnd;
UINT uID;
UINT uFlags;
UINT uCallbackMessage;
HICON hIcon;
#if (NTDDI_VERSION >= NTDDI_WIN2K)
CHAR szTip[128];
DWORD dwState;
DWORD dwStateMask;
CHAR szInfo[256];
union {
UINT uTimeout;
UINT uVersion; // used with NIM_SETVERSION, values 0, 3 and 4
} DUMMYUNIONNAME;
CHAR szInfoTitle[64];
DWORD dwInfoFlags;
#endif
#if (NTDDI_VERSION >= NTDDI_WINXP)
GUID guidItem;
#endif
#if (NTDDI_VERSION >= NTDDI_VISTA)
HICON hBalloonIcon;
#endif
} NOTIFYICONDATAA, *PNOTIFYICONDATAA;
.
.
.
之后看了网上的一种说法,改了下函数:
[DllImport("shell32.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern bool Shell_NotifyIcon(uint dwMessage, NOTIFYICONDATA lpdata);
问题依旧。
如果确实是结构体的问题,那我只能老老实实去看union的C#实现方法去了。
------解决思路----------------------