Nebula3 in CLR

Source: Internet
Author: User

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 ):

  1. Workaround steps:
  2. In the project properties:
  3. 1. Set linker/advanced/entry point to "" (empty string)
  4. 2. Set linker/system/subsystem to not set
  5. 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.
  6. 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 ().
  7. Thanks
  8. Sarita bafna
  9. Visual c ++ team

 

Test procedure:

  1. // N3clr. cpp: Main project file.
  2. # Include "stdafx. H"
  3. # Include "mainform. H"
  4. # Include "stdneb. H"
  5. # Include "Core/coreserver. H"
  6. # Include "IO/ioserver. H"
  7. Using namespace n3clr;
  8. [Stathreadattribute]
  9. Int main (array <system: String ^> ^ ARGs)
  10. {
  11. // Enabling Windows XP visual effects before any controls are created
  12. Application: enablevisualstyles ();
  13. Application: setcompatibletextrenderingdefault (false );
  14. PTR <core: coreserver> coreserver = core: coreserver: Create ();
  15. Coreserver-> open ();
  16. N_printf ("Hello CLR! ");
  17. Coreserver-> close ();
  18. Coreserver = NULL;
  19. // Create the main window and run it
  20. Application: Run (gcnew mainform ());
  21. Return 0;
  22. }

 

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:

  1. // Set the cooperative level of the device, we're friendly
  2. // Note: Use Win32's findwindow () to find our top level window because
  3. // The displaydevice may be running in a different thread
  4. Hwnd = findwindow (nebula3_window_class, null );
  5. If (0 = hwnd)
  6. {
  7. Hwnd = displaydevice: instance ()-> getparentwnd ();
  8. }
  9. N_assert (0! = Hwnd );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.