views:

212

answers:

1
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 getting crashed at SHChangeNotifyRegister.. i am trying to register a form for file change notification in windows mobile.. i think i am passing incorrect parameters to SHChangeNotifyRegister.. please help me if u know..

+3  A: 

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.

Matt
I have to add that these are for the desktop rather than device, I've since got the device working as an answer to this question (http://stackoverflow.com/questions/1470247/my-sample-app-is-getting-crash-while-registering-to-filechangeinfo-notification)
Matt
yup matt u r right :-)..Thank U for answer
Shadow