在我的应用程序中,我正在加载(例如)Device_Manager.dll,而此Device_Manager
依赖于所选的模型开始加载正确的Devices.dll。
在我的Device_Manager.dll中,我创建了一个窗口,以便稍后在我的handle
上使用其Devices
,因为当Devices
想要向其发送消息时handle
使用此thread
应用
所以,我在Device_Manager.dll
中制作了新的bool DeviceManagerPlugin::initializeDeviceManager()
{
EventManager pEventManager = new EventManager();
bool init_result = pEventManager->initilize_window();
...
if(initilize_status == S_OK)
{
return true;
}
else
{
return false;
}
}
void DeviceManagerPlugin::startDeviceManager()
{
handle_of_thread = 0;
int data_of_thread = 1;
handle_of_thread = CreateThread(NULL, 0,listenToIncomingWFSMessages2, &data_of_thread, 0, NULL);
my_thread_handle = handle_of_thread;
}
,以便在他们到达时获取这些消息!
(我也在使用QT创建/加载.dlls。)
创建线程后,我收到此错误:
Windows在sepanta.agent.exe中触发了断点。
这可能是由于堆损坏,这表示sepanta.agent.exe或其加载的任何DLL中存在错误。
这也可能是由于用户在sepanta.agent.exe具有焦点时按下F12。
输出窗口可能包含更多诊断信息。
我使用这两种方法初始化并启动我的设备管理器:
(成功加载.dll后,在主应用程序中调用这些方法。)
EventManager
这是我的LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
...
default:
return DefWindowProc(hWnd, msg, wParam, lParam );
}
}
bool EventManager::initialize_window()
{
WNDCLASS Wclass;
HWND gHwnd = NULL;
HINSTANCE gHinstance = NULL;
ZeroMemory(&Wclass, sizeof(WNDCLASS));
Wclass.hInstance = gHinstance;
Wclass.cbClsExtra = 0;
Wclass.cbWndExtra = 0;
Wclass.lpszClassName = TEXT("Device_Manager_Class_Name");
Wclass.lpszMenuName = NULL;
Wclass.lpfnWndProc = WndProc;
Wclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
Wclass.hCursor = LoadIcon(NULL, IDC_ARROW);
Wclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
Wclass.style = CS_OWNDC;
if(!RegisterClass(&Wclass))
{
cout<<"Unable to Register Class";
return false;
}
ULONG Window_Width;
ULONG Window_Height;
DWORD style;
bool full_screen = false;
if(full_screen)
{
Window_Width = GetSystemMetrics(SM_CXSCREEN);
Window_Height = GetSystemMetrics(SM_CYSCREEN);
style = WS_POPUP;
}
else
{
Window_Width = SCREEN_WIDTH;
Window_Height = SCREEN_HEIGHT;
style = WS_OVERLAPPED|WS_SYSMENU;
}
gHwnd = CreateWindow(TEXT("Device_Manager_Class_Name")
, TEXT("Device_Manager_Class_Title")
, style
, 0
, 0
, Window_Width
, Window_Height
, GetDesktopWindow()
, NULL
, gHinstance
, NULL);
if(!gHwnd)
{
cout<<"Unable to create the main window";
return false;
}
//ShowWindow(gHwnd, SW_SHOW);
//UpdateWindow(gHwnd);
//SetFocus(gHwnd);
return true;
}
DWORD WINAPI listenToIncomingWFSMessages2(LPVOID lpParam)
{
MSG msg;
SecureZeroMemory(&msg, sizeof(MSG));
BOOL bRet;
HWND windows_handle;
SecureZeroMemory(&windows_handle, sizeof(HWND));
windows_handle = FindWindow(TEXT("Device_Manager_Class_Name"), 0);
while( (bRet = GetMessage( &msg, windows_handle, 0, 0 )) != 0)
{
if (bRet == -1)
{
// handle the error and possibly exit
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return 0;
}
类,它创建了windows:
{{1}}
我在这里做错了什么?我错过了什么?如果您有更好的解决方案,我可以随时与我分享。