如何在Windows窗体中显示过量窗口?关于C#表单的OpenGL视图
glutCreateWindow( “实施例”)创建另一种形式中,
glutCreateSubWindow(HWND,0,0,100,100),其中hwnd是处理在C#我的主窗口的形式,我得到一个AccessViolation异常。
Glut程序在C++ DLL中。我的应用程序在C#WPF上。我需要在我的C#形式显示过剩视图
C++代码:
extern "C"
{
__declspec(dllexport) int InitGlut(int hwnd, int top, int left, int width, int height)
{
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(top,left);
glutInitWindowSize(320,320);
//glutCreateWindow("Example");
glutCreateSubWindow(hwnd, top, left, width, height);
glutDisplayFunc(renderScene);
glutMainLoop();
return 0;
}
}
C#代码:
const string pathToDll = "../../../Release/MyDLL.dll";
[DllImport(pathToDll)]
public static extern int InitGlut(IntPtr hwnd, int top, int left, int width, int height);
private void Window_Loaded(object sender, RoutedEventArgs e)
{
IntPtr hwnd = new WindowInteropHelper(Application.Current.MainWindow).Handle;
InitGlut(hwnd, 0, 0, 100, 100);
}
我没有足够的信心张贴作为回答,但一对夫妇的想法... 1. /在你的C#代码中尝试在Window_Loaded和InitGlut中添加'unsafe'。 2.确保您使用的是全部3个元素(GLUT库,C++代码和C#代码)的64位版本。 – 2011-04-21 20:24:10
您的代码中存在签名不匹配,这将导致64位操作系统崩溃。 C++方面希望hwnd是一个'int'(这也是错误的 - 它们是指针大小的),C#将它作为'IntPtr'传递(正确,但不是C++期望的)。 – ChrisV 2011-04-21 21:05:33