dllmain

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael Roper

    #1

    dllmain

    In Jesse Liberty's "Programmin g in C#" he says that "...an assembly must
    have exactly one entry point: DLLMain, WinMain, or Main. DLLMain is the
    entry point for DLLs..."

    In the MSDN ".Net Framework Developer's Guide" it says that "...each
    assembly can have only one entry point (that is, DllMain, WinMain, or
    Main..."

    So we've got "must" vs. "can" and "DLLMain" vs. "DllMain."

    In playing with this, it doesn't appear to make any difference whether it's
    included or not, or how it's spelled. It also never seems to get called
    automatically upon loading. Since there aren't any variables living outside
    of class scope in C#, it further seems that there wouldn't be much call (eh,
    sorry) for DllMain anyway.

    Can someone enlighten me as to the purpose and usage of DllMain in a pure
    managed-code class library assembly? Is it possible to get it called
    automatically when the assembly is loaded if one had reason to need such a
    feature?

    Thanks.

    Michael Roper


  • Frank Eller [MVP]

    #2
    Re: dllmain

    Hi Michael,

    [color=blue]
    > In Jesse Liberty's "Programmin g in C#" he says that "...an assembly must
    > have exactly one entry point: DLLMain, WinMain, or Main. DLLMain is the
    > entry point for DLLs..."
    >
    > In the MSDN ".Net Framework Developer's Guide" it says that "...each
    > assembly can have only one entry point (that is, DllMain, WinMain, or
    > Main..."
    >
    > So we've got "must" vs. "can" and "DLLMain" vs. "DllMain."
    >
    > In playing with this, it doesn't appear to make any difference whether[/color]
    it's[color=blue]
    > included or not, or how it's spelled. It also never seems to get called
    > automatically upon loading. Since there aren't any variables living[/color]
    outside[color=blue]
    > of class scope in C#, it further seems that there wouldn't be much call[/color]
    (eh,[color=blue]
    > sorry) for DllMain anyway.[/color]

    The only entry point you really need is Main(). In C# this method is already
    part of the application, in dll's it's not needed. In VB.NET, a sub "Main"
    doesn't seem to exist but is created in IL-Code automatically. In managed
    code dlls you don't need to specify an entry point.

    Regards,

    --
    Frank Eller [.NET MVP]
    another blog about programming with all things related to .NET

    ..NET Developers Group Munich- www.munichdot.net



    Comment

    • Chris Capel

      #3
      Re: dllmain

      Is this Mr. Liberty's book based on a beta version of the framework? Is that
      quote from the MSDN a current one? If so, could you give us a link to the
      online page? I suspect this is all based on a beta version of the framework.

      Chris


      Comment

      • Michael Roper

        #4
        Re: dllmain

        Chris Capel writes:[color=blue]
        > Is this Mr. Liberty's book based on a beta version of the
        > framework?[/color]

        3rd edition, (c) 2003. "Updated for .NET 1.1 & Visual Studio .NET 2003"
        [color=blue]
        > Is that quote from the MSDN a current one?[/color]

        http://tinyurl.com/n64h
        [color=blue]
        > I suspect this is all based on a beta version of the framework.[/color]

        Doesn't seem so.

        So, is the answer to my question then, that DllMain is vestigial and has no
        purpose in a managed class library? Is there ever a need to perform
        initialization work when a library is loaded, and if so, how is that done in
        the absence of DllMain?

        Thanks again.

        Michael Roper


        Comment

        • Chris Capel

          #5
          Re: dllmain

          > So, is the answer to my question then, that DllMain is vestigial and has
          no[color=blue]
          > purpose in a managed class library? Is there ever a need to perform
          > initialization work when a library is loaded, and if so, how is that done[/color]
          in[color=blue]
          > the absence of DllMain?[/color]

          Don't know. I know that windows DLLs have a DLLMain (not sure about the
          spelling) and that's called to initialize global variables when the library
          is loaded using LoadLibrary or by other methods, but I'm not sure that any
          of that is necessary in .NET. Perhaps if you're doing some advanced P/Invoke
          in a .NET dll you'd need to do some of this, but I don't see why. It may be
          more of a method to support a couple of necessary hacks here and there in
          the framework itself to get a nice tight integration with the GUI or other
          native code.

          Chris


          Comment

          Working...