从注入的dll中创建一个窗口

时间:2012-01-22 13:29:23

标签: winforms dll hook inject

好吧,我创建了一个dll绕道连接并从ws2_32发送游戏功能。在身份验证期间,我需要客户端输入一些东西,所以我需要一个对话框,一个对话框,我想在发送功能中完全在我需要的时候产生。

#include "dialog.h"

HINSTANCE hinst;

LRESULT CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch(uMsg)
    {
        case WM_INITDIALOG:
            /*
             * TODO: Add code to initialize the dialog.
             */
            return TRUE;

        case WM_CLOSE:
            EndDialog(hwndDlg, 0);
            return TRUE;

        case WM_COMMAND:
            switch(LOWORD(wParam))
            {
                /*
                 * TODO: Add more control ID's, when needed.
                 */
                case IDC_BTN_QUIT:
                    EndDialog(hwndDlg, 0);
                    return TRUE;

                case IDC_BTN_TEST:
                    MessageBox(hwndDlg, "You clicked \"Test\" button!", "Information", MB_ICONINFORMATION);
                    return TRUE;
            }
    }

    return FALSE;
}

BOOL InitApplication(HINSTANCE hinstance) 
{ 
    WNDCLASSEX wcx; 

    // Fill in the window class structure with parameters 
    // that describe the main window. 

    wcx.cbSize = sizeof(wcx);          // size of structure 
    wcx.style = CS_HREDRAW | 
        CS_VREDRAW;                    // redraw if size changes 
    wcx.lpfnWndProc = DialogProc;     // points to window procedure 
    wcx.cbClsExtra = 0;                // no extra class memory 
    wcx.cbWndExtra = 0;                // no extra window memory 
    wcx.hInstance = hinstance;         // handle to instance 
    wcx.hIcon = LoadIcon(NULL, 
        IDI_APPLICATION);              // predefined app. icon 
    wcx.hCursor = LoadCursor(NULL, 
        IDC_ARROW);                    // predefined arrow 
    wcx.hbrBackground = (HBRUSH)GetStockObject( 
        WHITE_BRUSH);                  // white background brush 
    wcx.lpszMenuName =  "MainMenu";    // name of menu resource 
    wcx.lpszClassName = "MainWClass";  // name of window class 
    wcx.hIconSm = (HICON)LoadImage(hinstance, // small class icon 
        MAKEINTRESOURCE(5),
        IMAGE_ICON, 
        GetSystemMetrics(SM_CXSMICON), 
        GetSystemMetrics(SM_CYSMICON), 
        LR_DEFAULTCOLOR); 

    // Register the window class. 

    return RegisterClassEx(&wcx); 
} 

BOOL InitInstance(HINSTANCE hinstance, int nCmdShow) 
{ 
    HWND hwnd; 

    // Save the application-instance handle. 

    hinst = hinstance; 

    // Create the main window. 

    hwnd = CreateWindow( 
        "MainWClass",        // name of window class 
        "Sample",            // title-bar string 
        WS_OVERLAPPEDWINDOW, // top-level window 
        CW_USEDEFAULT,       // default horizontal position 
        CW_USEDEFAULT,       // default vertical position 
        CW_USEDEFAULT,       // default width 
        CW_USEDEFAULT,       // default height 
        (HWND) NULL,         // no owner window 
        (HMENU) NULL,        // use class menu 
        hinstance,           // handle to application instance 
        (LPVOID) NULL);      // no window-creation data 

    if (!hwnd) 
        return FALSE; 

    // Show the window and send a WM_PAINT message to the window 
    // procedure. 

    ShowWindow(hwnd, nCmdShow); 
    UpdateWindow(hwnd); 
    return TRUE; 

} 

char* InitWinForm(HINSTANCE hinstance)
{
    //This is one choice
    DialogBox(hinstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DialogProc);
    return " ";
    //Second choice
    MSG msg; 

    if (!InitApplication(hinstance)) 
        return FALSE; 

    if (!InitInstance(hinstance, 0)) 
        return FALSE; 

    BOOL fGotMessage;
    while ((fGotMessage = GetMessage(&msg, (HWND) NULL, 0, 0)) != 0 && fGotMessage != -1) 
    { 
        TranslateMessage(&msg); 
        DispatchMessage(&msg); 
    } 
    return "asdada";
    //return msg.wParam; 
}

我会像这样调用InitWinForm:

HINSTANCE hinst = GetModuleHandle(NULL);
variable = InitWinForm(hinst);
  • 在做了一些调试之后我发现如果我选择第一个选择它返回-1,如果我选择第二个选项,那么在InitInstance中,CreateWindow返回NULL。

有人有任何想法吗?

0 个答案:

没有答案