none
DllImport Kernel32.dll Problem with C#

    Question

  • Hello,

    I want to create a mobile 5.0 app with C# .NET. But when I use the DllImport I met some problem. My project can be build successfully. After I run it, It has a run time error! the error message is "Can't find PInvoke DLL Kernel32.dll", I can't figure out what the problem is. Below is my code

     [DllImport("KERNEL32.DLL", SetLastError = true)]
            private static extern IntPtr CreateToolhelp32Snapshot(uint dwFlags, uint th32ProcessID);

    handle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

    ^^^^^^^^

    error happened

                                                                                                               thx

    Thursday, August 10, 2006 9:29 AM

Answers

  • Here is the correct P/Invoke signature:

    [DllImport("toolhelp.dll", SetLastError=true)]
    private static extern IntPtr CreateToolhelp32Snapshot(uint flags, uint processid);

    Thursday, August 10, 2006 2:45 PM
    Moderator

All replies

  • Hi,

    kernel32.dll is a desktop dll - try using coredll.dll instead

    Pete

    Thursday, August 10, 2006 9:48 AM
  • Here is the correct P/Invoke signature:

    [DllImport("toolhelp.dll", SetLastError=true)]
    private static extern IntPtr CreateToolhelp32Snapshot(uint flags, uint processid);

    Thursday, August 10, 2006 2:45 PM
    Moderator
  • thanks a lot. It works now
    Monday, August 14, 2006 3:14 AM