Impulse to use N3 + CLR for interface
Create a CLR winform project and directly introduce the N3 header file and library for compilation ........
Compilation failed. I found the cause for a while
Dizzy,. NET and N3 both have a system namespace and cannot change Microsoft's stuff, so we had to change the N3 system to the nsystem
Then the link does not work.
First, _ fastcall is not supported by CLR. Change it to _ cdecl (/Gd) for repeat.
Second, the multi-threaded debug (/MTD) Conflicts with/Clr and is changed to multi-threaded debug DLL (/MDD)
The link has finally passed .............
Start the program, crash off
Ask Google with the keyword. I didn't expect a solution on the msdn Forum (thanks to my pioneers, I succeeded in standing on your "corpse)
The reason is that the N3 object system defines some static objects during implementclass. If you use CLR directly, initialization cannot be performed correctly.
Solution (reference original ):
- Workaround steps:
- In the project properties:
- 1. Set linker/advanced/entry point to "" (empty string)
- 2. Set linker/system/subsystem to not set
- Step 1: makes sure that the CRT startup code is invoked. this is because, if no entry point is specified, the linker will automatically use maincrtstartup, which is defined in the CRT libraries. maincrtstartup will make sure that the global object is initialized correctly.
- Step 2: makes sure that the linker will look for the symbol "Main ". the linker looks for "Main" because maincrtstartup callmain () in its body. the default option for a winforms application is subsystem: Windows and this makes the linker look for winmain ().
- Thanks
- Sarita bafna
- Visual c ++ team
Test procedure:
- // N3clr. cpp: Main project file.
- # Include "stdafx. H"
- # Include "mainform. H"
- # Include "stdneb. H"
- # Include "Core/coreserver. H"
- # Include "IO/ioserver. H"
- Using namespace n3clr;
- [Stathreadattribute]
- Int main (array <system: String ^> ^ ARGs)
- {
- // Enabling Windows XP visual effects before any controls are created
- Application: enablevisualstyles ();
- Application: setcompatibletextrenderingdefault (false );
- PTR <core: coreserver> coreserver = core: coreserver: Create ();
- Coreserver-> open ();
- N_printf ("Hello CLR! ");
- Coreserver-> close ();
- Coreserver = NULL;
- // Create the main window and run it
- Application: Run (gcnew mainform ());
- Return 0;
- }
If you want to embed data into winform, you need to change the hwnd in displaydevice. In this case, use the window created by displaydevice as the Child Window of winform.
Note that the inputdevice must be created using the top-level window handle:
- // Set the cooperative level of the device, we're friendly
- // Note: Use Win32's findwindow () to find our top level window because
- // The displaydevice may be running in a different thread
- Hwnd = findwindow (nebula3_window_class, null );
- If (0 = hwnd)
- {
- Hwnd = displaydevice: instance ()-> getparentwnd ();
- }
- N_assert (0! = Hwnd );