PC Review


Reply
 
 
Rene
Guest
Posts: n/a
 
      24th Nov 2005
When you build an exe application, you can count on that the "static void
Main()" function will bee the first one to be called when the application
starts up.

Is there something similar for dlls? Is there a "Main" entry point that is
called when the dll is first loaded?

Thanks.


 
Reply With Quote
 
 
 
 
Patrice
Guest
Posts: n/a
 
      24th Nov 2005
What are you trying to do ?

In .NET you are working on classes. A shared constructor could perhaps help.
Or do you mean a "classic" DLL ? (which have a DLLMain function if I
remember) ?

--
Patrice

"Rene" <(E-Mail Removed)> a écrit dans le message de
news:(E-Mail Removed)...
> When you build an exe application, you can count on that the "static void
> Main()" function will bee the first one to be called when the application
> starts up.
>
> Is there something similar for dlls? Is there a "Main" entry point that is
> called when the dll is first loaded?
>
> Thanks.
>
>



 
Reply With Quote
 
Adam Cooper
Guest
Posts: n/a
 
      24th Nov 2005
No.

Class library's (DLLs) can not be started directly. They are only to
be referenced from an exe (WinForm/Console/etc).

Cheers,
Adam Cooper
-------------------------------------------------------------------------------------------
J-Integra Interoperability Solutions
http://j-integra.intrinsyc.com/
high performance interop middleware for java, corba, com & .net

 
Reply With Quote
 
Mattias Sjögren
Guest
Posts: n/a
 
      24th Nov 2005

>When you build an exe application, you can count on that the "static void
>Main()" function will bee the first one to be called when the application
>starts up.


No you can't. Static constructors may run before Main for example.


>Is there something similar for dlls?


..NET v2.0 supports having a "module initializer", but that feature
isn't available i C# since it doesn't support global methods. Usually
you can use a static constructor instead, like Patrice suggested.


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
 
Reply With Quote
 
Rene
Guest
Posts: n/a
 
      25th Nov 2005
> A shared constructor could perhaps help.
How do you specify a Shared Constructor.

I would like to accomplish something similar to what Mattias motioned on the
other post, something that works as a "module initializer". Would a Shared
Constructor work like that? Do I have to declare this constructor on every
class because I don't know which class will be access first?

Thanks.


 
Reply With Quote
 
Patrice
Guest
Posts: n/a
 
      25th Nov 2005
Could you describe from a non technical point of view what you are after ?

I don't see for now why you would have to do that on each and every class
i.e. my first thought would be to put the functionalities that needs some
kind of initialization in its own class so that you'll guarantee that the
constructor for this class runs before other classes uses it.

For shared or static constructors see :
http://msdn.microsoft.com/library/de...spec_10_11.asp
(C#) or
http://msdn.microsoft.com/library/de...BSpec7_2_2.asp

Are your using 1.1 or 2.0. Another response said that 2.0 might have
something that could be of some interest for you...

--
Patrice

"Rene" <(E-Mail Removed)> a écrit dans le message de
news:(E-Mail Removed)...
> > A shared constructor could perhaps help.

> How do you specify a Shared Constructor.
>
> I would like to accomplish something similar to what Mattias motioned on

the
> other post, something that works as a "module initializer". Would a Shared
> Constructor work like that? Do I have to declare this constructor on every
> class because I don't know which class will be access first?
>
> Thanks.
>
>



 
Reply With Quote
 
Richard Grimes
Guest
Posts: n/a
 
      25th Nov 2005
Rene wrote:
> When you build an exe application, you can count on that the "static
> void Main()" function will bee the first one to be called when the
> application starts up.
>
> Is there something similar for dlls? Is there a "Main" entry point
> that is called when the dll is first loaded?


Your assembly can have a class called <Module> which represents the
module itself. Managed C++ allows you to create global methods, and
these are part of the <Module> class. ILDASM does not show this class
but Reflector does. Managed C++ (/clr or /clrure) will use the static
constructor of this class to perform once only module initialization.

You can do something similar if you write IL. C# and VB.NET treat
<Module> as an invalid name for a class. Although managed C++ will
create a <Module> class you cannot add such a class to your code (the
name is treated as being invalid).

Richard
--
http://www.grimes.demon.co.uk/workshops/fusionWS.htm
http://www.grimes.demon.co.uk/workshops/securityWS.htm


 
Reply With Quote
 
Metallikanz!
Guest
Posts: n/a
 
      27th Nov 2005
I am not exactly sure what could be the use case where you require assembly level initialization.

Anyways, if you need this to be done in a single project, a dirty way of doing this will be to handle the AssemblyLoad event of the AppDomain and selectively invoking some initialization routine.

HTH, Metallikanz!


"Rene" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> When you build an exe application, you can count on that the "static void
> Main()" function will bee the first one to be called when the application
> starts up.
>
> Is there something similar for dlls? Is there a "Main" entry point that is
> called when the dll is first loaded?
>
> Thanks.
>
>

 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      27th Nov 2005
Metallikanz! <NoSpam---(E-Mail Removed)> wrote:
> I am not exactly sure what could be the use case where you require
> assembly level initialization.


I've wanted it a couple of times. For instance, if many plugins are
contained in an assembly, it would be nice to be able to make the
assembly itself register the plugins against the loader, rather than
make the loader find them all.

> Anyways, if you need this to be done in a single project, a dirty way
> of doing this will be to handle the AssemblyLoad event of the
> AppDomain and selectively invoking some initialization routine.


Except you'd have to subscribe to the event *before* the assembly is
loaded...

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Requery main form after subform update and not lose place in main form. Michael Microsoft Access Form Coding 1 23rd Nov 2010 09:26 PM
Link Subforms to Main Form - 2 Linked Combo Boxes in Main Form =?Utf-8?B?Sm9obiBE?= Microsoft Access Form Coding 3 4th Feb 2007 02:08 AM
Re: Referencing main/sub then sub/main report controls for Calcs =?Utf-8?B?SmF5?= Microsoft Access Reports 0 22nd Oct 2004 05:19 PM
Where I can get Add-in to create a main menu (or main form) S.Hoa Microsoft Access 1 2nd Sep 2004 02:55 PM
How to rename sub main to function main Rody Reulen Microsoft VB .NET 8 12th Feb 2004 08:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:36 PM.