前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Nebula3 in CLR

Nebula3 in CLR

作者头像
逍遥剑客
发布2019-02-20 12:49:18
5000
发布2019-02-20 12:49:18
举报
文章被收录于专栏:逍遥剑客的游戏开发

有用N3 + CLR做界面的冲动

新建一个CLR WinForm工程, 直接引入N3的头文件和库进行编译........

编译不过, 找了半天才发现原因

晕死, .Net和N3都有个System命名空间, 没法改Microsoft的东西, 只好把N3的System改成了NSystem

然后就是链接不过

一是__fastcall不被CLR支持, 改成__cdecl (/Gd)重遍

二是Multi-threaded Debug (/MTd)跟/clr冲突, 改成Multi-threaded Debug DLL (/MDd)

终于链接过了.............

启动程序, Crash掉

拿着关键字就去问google, 没想到MSDN论坛上还真有解决方法(感谢我的先驱们, 我成功是了站在你们的"尸体"上)

原因是N3的对象系统在ImplementClass时定义了一些静态对象, 如果直接用CLR会导致不能正解地进行初始化

解决方案(引用原文):

  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 calls main() 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

测试程序:

  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. }

如果想嵌入到WinForm中的话, 需要更改DisplayDevice中的hWnd, 我的做法是把DisplayDevice创建的窗口做为WinForm的子窗口.

注意InputDevice需要最顶层的窗口句柄来创建:

  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 hWnd = FindWindow(NEBULA3_WINDOW_CLASS, NULL);
  5. if (0 == hWnd)
  6.     {
  7.         hWnd = DisplayDevice::Instance()->GetParentWnd();
  8.     }
  9.     n_assert(0 != hWnd);
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2008年11月18日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档