What might cause SHChangeNotifyRegister to fail on Windows Mobile?

随声附和 提交于 2020-01-17 13:57:12

问题


I have the following code:

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);

My code is crashing at the SHChangeNotifyRegister. I am trying to register a form for file change notification in Windows Mobile.

I think I may be passing incorrect parameters to SHChangeNotifyRegister.


回答1:


pinvoke.net is handy for finding out dllimport and structure definitions, or at the very least getting a starting point for them :)

SHChangeNotifyEntry

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
struct SHChangeNotifyEntry
{
    public IntPtr pIdl;
    [MarshalAs(UnmanagedType.Bool)] public Boolean Recursively;
}

SHChangeNotifyRegister

[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)

As others have said, try posting the dllimports you have, and the structure definitions that you are passing into the p/invokes, and the exact error messages/exceptions you are getting.



来源:https://stackoverflow.com/questions/1470062/what-might-cause-shchangenotifyregister-to-fail-on-windows-mobile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!