问题
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