开发者

Win32 DLL Window not showing

I've recently come up with some code that logic (and various places on the internet) says should work. When injecting my Win32 DLL into any program though to test it, the Window I've create doesn't appear. I have no idea why this is, my code is as follows:

main.cpp

#include "stdafx.h"
#include "resource.h"
#include <tchar.h>

HWND PGHWND;

BOOL CALLBACK EventHandler(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
    return 0;
}

DWORD WINAPI MainWin(HMODULE hMod)
{
    DialogBox(hMod, MAKEINTRESOURCE(IDD_DIALOG1), NULL, (DLGPROC)EventHandler);
    ExitThread(0);
    return 0;
}

void GetWnd()
{
    DialogBox(0,MAKEINTRESOURCE(IDD_DIALOG1),0,0);
    for(;;)
    {
        PGHWND = FindWindow(NULL, "3D Pinball for Windows - Space Cadet");
        if(PGHWND)
        {
            break;
        }
    }
}

__declspec(dllexport) bool __stdcall DllMain(HMODULE hModule,DWORD Reason,LPVOID lpv) //DllMain
{      
    switch (Reason){ //What happened?
        case DLL_PROCESS_ATTACH: //Did the DLL attach?
            DisableThreadLibraryCalls(hModule); //Disable THREAD_ATTACH and THREAD_DETACH
            CreateThread(NULL, 0, (开发者_StackOverflow社区LPTHREAD_START_ROUTINE)MainWin, hModule, 0, NULL); //Start the thread to create the dialog
            CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)&GetWnd,NULL,0,NULL); //Start our thread to get the window
            MessageBox(0, _T("This program was created by Joe Savage"), _T("Pinball Modifications!"), 0);
            break;
        break;
    }
    return true;
}

Main.rc

// Generated by ResEdit 1.5.4
// Copyright (C) 2006-2010
// http://www.resedit.net

#include <windows.h>
#include <commctrl.h>
#include <richedit.h>
#include "resource.h"




//
// Dialog resources
//
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG1 DIALOG 0, 0, 55, 24
STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU
CAPTION "Dialog"
FONT 8, "Ms Shell Dlg"
{
    DEFPUSHBUTTON   "OK", IDOK, 3, 3, 50, 14
}

resource.h

#ifndef IDC_STATIC
#define IDC_STATIC (-1)
#endif

#define IDD_DIALOG1                             100


In function GetWnd() the statement DialogBox(0,MAKEINTRESOURCE(IDD_DIALOG1),0,0); is wrong.

it must be something like :

DialogBox( hInst ,MAKEINTRESOURCE(IDD_DIALOG1),0 ,EventHandler );

where hInst is the instance-handle of your dll.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜