| View previous topic :: View next topic |
| Author |
Message |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Sun Sep 28, 2008 10:46 am Post subject: [C++] Creating Window through dll injection |
|
|
i'm trying to create a simple window that will pop up through dll injection
but for some reason it doesn't pop up any window or creating any process in the process list
here's the code
| Code: |
#include <windows.h>
#include <tchar.h>
HMODULE Module;
LRESULT CALLBACK WndProc (HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
switch (iMsg)
{
case WM_CREATE:
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd,iMsg,wParam,lParam);
}
void ExitWindow()
{
UnregisterClass(_T("WindowClass"), Module);
FreeLibraryAndExitThread(Module, 0);
}
void Window()
{
HWND hWnd;
MSG iMsg;
WNDCLASSEX wc;
ZeroMemory(&wc,sizeof(WNDCLASSEX));
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)COLOR_BTNSHADOW;
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hInstance = Module;
wc.lpfnWndProc = WndProc;
wc.lpszMenuName = NULL;
wc.lpszClassName = _T("WindowClass");
wc.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
if (!RegisterClassEx(&wc)){
MessageBox(0,_T("Failed"),0,0);
ExitWindow();
}
hWnd = CreateWindowEx(WS_EX_APPWINDOW | WS_EX_TOOLWINDOW,_T("WindowClass"),_T("DLL Window"),WS_SYSMENU,CW_USEDEFAULT,CW_USEDEFAULT,200,200,0,0,Module,0);
ShowWindow(hWnd,SW_SHOWNORMAL);
UpdateWindow(hWnd);
while (GetMessage(&iMsg,0,0,0))
{
TranslateMessage(&iMsg);
DispatchMessage(&iMsg);
}
ExitWindow();
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpvReserved)
{
if (dwReason == DLL_PROCESS_ATTACH)
{
Module = hModule;
CreateThread(0,0,(LPTHREAD_START_ROUTINE)&Window,0,0,0);
}
}
|
any suggestions what could be the problem?
_________________
Stylo |
|
| Back to top |
|
 |
TraxMate Master Cheater
Reputation: 0
Joined: 01 Mar 2008 Posts: 363
|
Posted: Sun Sep 28, 2008 11:16 am Post subject: |
|
|
| Try putting the ExitWindow() before the loop .
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Sun Sep 28, 2008 11:25 am Post subject: |
|
|
why would i want to do that?
then i won't get any message and the window will be close right after it will be created
_________________
Stylo |
|
| Back to top |
|
 |
TraxMate Master Cheater
Reputation: 0
Joined: 01 Mar 2008 Posts: 363
|
Posted: Sun Sep 28, 2008 11:31 am Post subject: |
|
|
Found the problem. It doesn't attach properly. Use this instead | Code: | BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
if (ul_reason_for_call == DLL_PROCESS_ATTACH)
{
Module = hModule;
CreateThread(0,0,(LPTHREAD_START_ROUTINE)&Window,0,0,0);
}
return TRUE;
} |
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
|
| Back to top |
|
 |
TraxMate Master Cheater
Reputation: 0
Joined: 01 Mar 2008 Posts: 363
|
Posted: Sun Sep 28, 2008 11:51 am Post subject: |
|
|
| that code worked for me :S
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
|
| Back to top |
|
 |
TraxMate Master Cheater
Reputation: 0
Joined: 01 Mar 2008 Posts: 363
|
Posted: Sun Sep 28, 2008 12:01 pm Post subject: |
|
|
| Dev C++ sucks so hard ... Don't use it use MSVC++ instead it's better and looks alot better : P
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
|
| Back to top |
|
 |
Anden100 Grandmaster Cheater
Reputation: 0
Joined: 20 Apr 2007 Posts: 668
|
Posted: Sun Sep 28, 2008 12:39 pm Post subject: |
|
|
| 1qaz wrote: | actually i moved from MSVC++ to dev just to try it out
dev is pretty good though.. i don't think it that sucks  |
Dev C++ doesnt suck, its just out-dated. It might work fine for many things, but keep in mind that most peoples at this forum is using msvc++.
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Sun Sep 28, 2008 4:01 pm Post subject: |
|
|
| The MS compiler is far, far better.
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Sun Sep 28, 2008 5:37 pm Post subject: |
|
|
yea i know that, just wanted to try other compilers O_O
_________________
Stylo |
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
|
| Back to top |
|
 |
|