0

在我的应用程序中,我正在加载(例如)Device_Manager.dll,这Device_Manager取决于所选模型开始加载正确的 Devices.dll。

在我的 Device_Manager.dll 中,我创建了一个窗口以供handle以后使用,Devices因为当他们想要向应用程序发送消息时使用它。Deviceshandle

所以,我做了新thread的,Device_Manager.dll以便在它们到达时收到这些信息!

(我也使用 QT 来创建/加载 .dll。)

创建线程后,我收到此错误:

Windows 已在 sepanta.agent.exe 中触发断点。

这可能是由于堆损坏,这表明 sepanta.agent.exe 或其已加载的任何 DLL 中存在错误。

这也可能是由于用户在 sepanta.agent.exe 具有焦点时按 F12。

输出窗口可能有更多诊断信息。

我使用这两种方法来初始化和启动我的设备管理器:

(这些方法在我成功加载 .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;

}

这是我的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;
}

我在这里做错了什么?我错过了什么?如果您对我即将做的事情有更好的解决方案,请随时与我分享。

4

0 回答 0