Updated: 1/22/2004; 8:04:39 PM.
ronpih I guess...
Your guess is as good as mine...
        

Monday, March 18, 2002

(BTW, the previous post was not the contrived example I mentioned yesterday.)
8:55:02 PM    comment []

More learning:

My March 11th post on how to fix the Managed C++ Winforms samples didn't tell the whole story.  If you do what I said and look at the resultant .exe file using ILDASM you will see that the entry point for the CRT is not listed in the metadata.  There could be problems if you use any CRT functions in your program.  This isn't a big problem for the samples since they are just ports of C# samples and don't use any native C++ functionality.

So how do you get the CRT properly initialized and not have the console window come up?  It's a bit ugly....

Here's what I had to do for BirthdayPicker:

1. Change the entry point function from 

void main()

 to

int __stdcall WinMain(W32::HINSTANCE,W32::HINSTANCE,W32::LPSTR,int)

2. Include the windows.h file like this:

namespace W32
{
    #include <windows.h>
}

Do this before the #using <mscorlib.dll>

3. Because BirthdayPicker uses a framework API that is defined by a macro somewhere in windows.h, I needed to undef the symbol immediately after including windows.h and before bringing in the Managed system stuff:

#undef GetObject

(The .NET framework itself does this in its fwcommon.h file.)

4. Change the linker SubSystem setting to /SUBSYSTEM:WINDOWS.  You don't need to set the entry point since WinMain is the default entry point when /SUBSYSTEM:WINDOWS is specified.

Now if you build and look at the .exe in ILDASM you will see the metadata for _WinMainCRTStartup.


8:31:12 PM    comment []

© Copyright 2004 Ronald Pihlgren.
 
March 2002
Sun Mon Tue Wed Thu Fri Sat
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
Feb   Apr

Weblogs
Microsoft Testers
VC++ Bloggers
Links
Note:This is a personal weblog. All opinions expressed here are mine alone.


Click here to visit the Radio UserLand website.

Subscribe to "ronpih I guess..." in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.