我正在用 C++ 编写一个带有 Direct3D 和 Python 的小程序。我创建了我的窗口,一切正常。但如果我尝试调用“Py_Initialize();” 我的程序关闭。
(它以代码 1 结束)有什么问题?
编辑:这是我的代码的一些部分。
MainIncludes.h
#include "Windows.h"
#include <d3d9.h>
#pragma comment (lib, "d3d9.lib")
#include <d3dx9.h>
#pragma comment (lib, "d3dx9.lib")
main_d3dwindow.cpp
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
HWND hWnd;
WNDCLASSEX wc;
ZeroMemory(&wc, sizeof(WNDCLASSEX));
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.lpszClassName = L"WindowClass";
RegisterClassEx(&wc);
hWnd = CreateWindowEx(NULL,
L"WindowClass",
L"Program",
WS_OVERLAPPEDWINDOW,
300, 300,
800, 600,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hWnd, nCmdShow);
mainWindow = hWnd;
initD3D(hWnd);
init_python();
MSG msg;
while(TRUE)
{
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if(msg.message == WM_QUIT)
break;
render_frame();
}
cleanD3D();
return msg.wParam;
}
main_python.cpp
#include "Python.h"
void init_python() {
Py_Initialize();
}