Search code examples
c#.netwindowspinvoke

.NET signature to p/invoke GetSystemDEPPolicy function


I can't find any example signatures for .NET to use this function (GetSystemDEPPolicy).

http://msdn.microsoft.com/en-us/library/windows/desktop/bb736298(v=vs.85).aspx

It's a fairly simple function but I don't know how to create the signature to call it. Can someone please help?


Solution

  • GetSystemDEPPolicy is defined as

    DEP_SYSTEM_POLICY_TYPE WINAPI GetSystemDEPPolicy(void);
    

    and DEP_SYSTEM_POLICY_TYPE is an enum (see winbase.h assuming you have the C++ components installed in your development environment - if not try winbase.h) and enums in C default to int, as such I would go with

    [DllImport("kernel32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
    public static extern int GetSystemDEPPolicy();
    

    May I recommend you follow this tutorial on PInvoke