DLL injection to open a dialog box

Hi, I'm having a difficulty writing a dynamic link library code that will open a dialog box when it's injected into a process. I've googled a lot and changed my codes many times without success. It's really baffling since I copied and pasted a supposedly working code one time. Here's my code.

dllmain.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "dll.h"
#include <windows.h>
DWORD WINAPI CreateGUIThread(LPVOID lParam);
INT_PTR CALLBACK DialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam);
HINSTANCE g_h_main_instance;

DllClass::DllClass()
{

}


DllClass::~DllClass ()
{

}

DWORD WINAPI ThreadProc(LPVOID lpParam)
{
	DialogBox(g_h_main_instance, MAKEINTRESOURCE(IDD_ABOUT), 0, DialogProc);
}

INT_PTR CALLBACK DialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
    switch(uMsg) {
        case WM_INITDIALOG: //To initiate the dialog box
            return TRUE;
        case WM_COMMAND:
            switch(LOWORD(wParam))
            {
                case IDOK:
                    EndDialog(hwndDlg, IDOK);
                break;
                case IDCANCEL:
                    EndDialog(hwndDlg, IDCANCEL);
                break;
            }
        break;
        case WM_CLOSE:// end your dialog if you click the X button.
            EndDialog(hwndDlg, 0);
            break;
    }
    return 0;
}

BOOL APIENTRY DllMain (HINSTANCE hInst     /* Library instance handle. */ ,
                       DWORD reason        /* Reason this function is being called. */ ,
                       LPVOID reserved     /* Not used. */ )
{
    DWORD dwThreadID=0;
    g_h_main_instance=hInst;
    
    switch (reason)
    {
      case DLL_PROCESS_ATTACH:
        DisableThreadLibraryCalls(hInst);
        CreateThread(NULL,0,ThreadProc,0,0,&dwThreadID);
        break;

      case DLL_PROCESS_DETACH:
        break;

      case DLL_THREAD_ATTACH:
        break;

      case DLL_THREAD_DETACH:
        break;
    }

    /* Returns TRUE on success, FALSE on failure */
    return TRUE;
}




dll.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#ifndef _DLL_H_
#define _DLL_H_

#include <Windows.h>
#include <stdlib.h>
#include <CommCtrl.h>
#include "resource.h"

#if BUILDING_DLL
# define DLLIMPORT __declspec (dllexport)
#else /* Not BUILDING_DLL */
# define DLLIMPORT __declspec (dllimport)
#endif /* Not BUILDING_DLL */


class DLLIMPORT DllClass
{
  public:
    DllClass();
    virtual ~DllClass(void);
};


#endif /* _DLL_H_ */ 


resource.h
1
2
3
4
5
#define IDD_ABOUT 1000

#define DG_W 300
#define DG_H 200


NewProject.rc
1
2
3
4
5
6
7
8
9
10
11
12
13
#include "resource.h"
#include "windows.h"

IDD_ABOUT DIALOG DISCARDABLE  0, 0, DG_W, DG_H
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION
CAPTION "My About Box"
FONT 8, "MS Sans Serif"
BEGIN
    DEFPUSHBUTTON   "&OK",IDOK,DG_W/2-52,DG_H-20,50,14
    PUSHBUTTON      "&Cancel",IDCANCEL,DG_W/2+3,DG_H-20,50,14
END

Maybe it's Dev C++'s problem. I've had a few problems writing Win32 applications with Dev C++, particularly with .rc files. Anybody have any idea?
You don't show us how exactly inject this dll in a 3rd party process, maybe with CreateRemoteThread and WriteProcessMemory ?
Topic archived. No new replies allowed.