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
|