RE: [aus-dotnet] DllImport


    [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
    • From: Nick Wienholt
    • Subject: RE: [aus-dotnet] DllImport
    • Date: Sun, 29 Jan 2006 19:21:57 -0800

    > Is this how you access unmanaged code?

     

    Yes

     

    > Is that the right name for it? code outside of .net is not managed by the framework right?)

     

    Yes

     

    > 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?

     

    The full Win32 API is huge compared to the .NET Framework – it will take a lot of versions of the Framework before the majority of Win32 is covered.  There is a new namespace - System.DirectoryServices.ActiveDirectory – that covers AD, but I don’t think it offers login services.

     

    Nick Wienholt, C# MVP

     

    Maximizing .NET Performance

    http://www.apress.com/book/bookDisplay.html?bID=217

     

    A Programmer's Introduction to C# 2.0, Third Edition

    http://www.apress.com/book/bookDisplay.html?bID=454

     

    Sydney Deep .NET User Group

    www.sdnug.org

     

    www.dotnetperformance.com

     


    From: peter@xxxxxxxxxxx [mailto:peter@xxxxxxxxxxx] On Behalf Of Stephen Price
    Sent: Monday, 30 January 2006 1:50 PM
    To: dotnet@xxxxxxxxxxx
    Subject: [aus-dotnet] DllImport

     

    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

     

     

    http://support.microsoft.com/default.aspx?scid=KB;en-us;q306158

     

    [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)