[aus-dotnet] DllImport


    [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
    • From: Stephen Price
    • Subject: [aus-dotnet] DllImport
    • Date: Sun, 29 Jan 2006 18:56:06 -0800

    I'm looking at some code to do with impersonation and a nagging question popped up (its done it before so here i am asking why).
     
    Why do you use DllImport? I understand what it does... ie allows you to use methods in a dll, but what i don't quite get is why is this not part of some .net namespace? Is this how you access unmanaged code? (Is that the right name for it? code outside of .net is not managed by the framework right?) I would have thought the framework would have had somekind of wrapper for OS level stuff. I mean it has it for accessing files and memory streams etc, why not AD?
     
    Seeking illumination. :)
     
    Cheers,
     
    Stephen
     
     
     
    [DllImport("advapi32.dll")]
    public static extern int LogonUserA(String lpszUserName,
    String lpszDomain,
    String lpszPassword,
    int dwLogonType,
    int dwLogonProvider,
    ref IntPtr phToken);
    [DllImport("advapi32.dll", CharSet=CharSet.Auto, SetLastError=true)]
    public static extern int DuplicateToken(IntPtr hToken,
    int impersonationLevel,
    ref IntPtr hNewToken);



    (Click here for more information on the aus-dotnet mailling list)