C# 什么可能导致在Windows Mobile上注册失败?

C# 什么可能导致在Windows Mobile上注册失败?,c#,.net-3.5,windows-mobile,visual-c++,C#,.net 3.5,Windows Mobile,Visual C++,我有以下代码: SHChangeNotifyEntry changeentry = new SHChangeNotifyEntry(); changeentry.pIdl = GetPidlFromFolderID(this.Handle, CSIDL.CSIDL_DESKTOP); changeentry.Recursively = true; uint notifyid = SHChangeNotifyRegister(

我有以下代码:

SHChangeNotifyEntry changeentry = new SHChangeNotifyEntry();




        changeentry.pIdl = GetPidlFromFolderID(this.Handle, CSIDL.CSIDL_DESKTOP);
        changeentry.Recursively = true;


             uint notifyid = SHChangeNotifyRegister(
             this.Handle,
             SHCNF.SHCNF_PATHA ,
             SHCNE.SHCNE_ALLEVENTS,
             WM_SHNOTIFY,
             1,
             ref changeentry);

我的代码在SHChangeNotifyRegister上崩溃了。我正在尝试在Windows Mobile中注册文件更改通知表单 我想我可能向SHChangeNotifyRegister传递了不正确的参数。

pinvoke.net很方便找到dlliport和结构定义,或者至少为它们找到一个起点:)


正如其他人所说,请尝试发布您拥有的dllimports、您正在传递到p/invokes的结构定义,以及您获得的确切错误消息/异常。

Nativie exception发生在smaple.exe中,它说。。。它甚至不来抓布洛克…你在这里用平沃克吗?如果是这样,您至少应该展示如何定义SHChangeNotifyEnty、GetPidlFromFolderID和SHChangeNotifyRegister。如果SHChangeNotifyEntry是类而不是结构,则SHChangeNotifyRegister中的ref关键字错误。这是SHChangeNotifyEnty结构,公共结构SHChangeNotifyEntry{public IntPtr pIdl;[Marshallas(UnmanagedType.Bool)]公共布尔递归;}这是GetPidlFromFolderID。。公共静态IntPtr GetPidlFromFolderID(IntPtr hWnd,CSIDL Id){IntPtr pIdl=IntPtr.Zero;SHGetFolderLocationReturnValues res=(SHGetFolderLocationReturnValues)SHGetSpecialFolderLocation(hWnd,Id,out pIdl);return(pIdl);}为什么不编辑问题以反映注释中的所有拒绝。它将更具可读性。您能显示您正在使用的Pinvoke签名/结构吗?我必须补充的是,这些签名/结构是用于桌面而不是设备的,我已经将设备作为这个问题的答案()
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
struct SHChangeNotifyEntry
{
    public IntPtr pIdl;
    [MarshalAs(UnmanagedType.Bool)] public Boolean Recursively;
}
[DllImport("shell32.dll", SetLastError=true, EntryPoint="#2", CharSet=CharSet.Auto)]
static extern UInt32 SHChangeNotifyRegister(
            IntPtr hWnd,
            SHCNF fSources,
            SHCNE fEvents,
            uint wMsg,
            int cEntries,
            ref SHChangeNotifyEntry pFsne)