Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / December 2005

Tip: Looking for answers? Try searching our database.

MFC dll and CLR 2.0

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Frank Samuel - 20 Dec 2005 11:28 GMT
Hi,
we found a problem with the way managed MFC dlls work:

CWinApp::InitInstance is sometimes just called when the managed
initialization is done (cctor).
This is the case if one of the files using /clr is including afxdisp.h

The problem is that the managed initialization is just executed if a managed
object is required.
If an unmanaged function is called (like DllRegisterServer), CWinApp is not
yet initialized which causes funny problems in our application.

Does anybody have a good idea how to solve this?

Thanks,
Frank
Willy Denoyette [MVP] - 20 Dec 2005 16:33 GMT
> Hi,
> we found a problem with the way managed MFC dlls work:
[quoted text clipped - 12 lines]
> Thanks,
> Frank

Frank,
What exactly do you mean with "managed initialization is done"? And what
exactly are "Funny problems"?
You CWinApp is a native class so it's instance is not handled by the CLR,
but by MFC. As your MFC app. is a mixed application, that is the MFC libary
linked in is still unmanaged code, your classes are still native, all there
is done by the CLR is JITting your applications code from IL to native X86
code.

Willy.
PS. As this relates to VC++ I would suggest you post to the more appropriate
NG at microsoft.public.dotnet.languages.vc.
Frank Samuel - 20 Dec 2005 17:21 GMT
Hi Willy,
thanks for your answer.

This is mainly what we found out so far:
If a cpp which is compiled with /clr includes afxdisp.h, the MFC include
files tell the linker to also link with postdllmain.obj
If the postdllmain.obj is linked, some static variable inside MFC (something
like usemanagedinitialization) is set to 1.
When the dll is loaded the dllmain of MFC constructs all the unamanged
globals, and if the variable is 1 it skips InitInstance totally
The initinstance is later executed using "internaldllmain" call from .cctor
of managed global object which is inside the postdllmain.obj

The funny effects are mainly based on our construction code, which is
usually executed in InitInstance.
But I'm also not sure if MFC behaves correctly if we call AFX_MANAGE_STATE()
and InitInstance is not yet called.

Frank

>> Hi,
>> we found a problem with the way managed MFC dlls work:
[quoted text clipped - 25 lines]
> PS. As this relates to VC++ I would suggest you post to the more
> appropriate NG at microsoft.public.dotnet.languages.vc.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.