Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C++] Creating Window through dll injection

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Sun Sep 28, 2008 10:46 am    Post subject: [C++] Creating Window through dll injection Reply with quote

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
View user's profile Send private message
TraxMate
Master Cheater
Reputation: 0

Joined: 01 Mar 2008
Posts: 363

PostPosted: Sun Sep 28, 2008 11:16 am    Post subject: Reply with quote

Try putting the ExitWindow() before the loop .
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Sun Sep 28, 2008 11:25 am    Post subject: Reply with quote

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
View user's profile Send private message
TraxMate
Master Cheater
Reputation: 0

Joined: 01 Mar 2008
Posts: 363

PostPosted: Sun Sep 28, 2008 11:31 am    Post subject: Reply with quote

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
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Sun Sep 28, 2008 11:49 am    Post subject: Reply with quote

yea you were right, it doesn't attach properly but the code you gave me didn't helped too Confused
_________________
Stylo
Back to top
View user's profile Send private message
TraxMate
Master Cheater
Reputation: 0

Joined: 01 Mar 2008
Posts: 363

PostPosted: Sun Sep 28, 2008 11:51 am    Post subject: Reply with quote

that code worked for me :S
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Sun Sep 28, 2008 11:55 am    Post subject: Reply with quote

yea... mine is working too the problem was that i wrote it in dev C++ and when i copied it to msvc++ it works fine...
i don't know why it didn't work using Dev c++ Confused

_________________
Stylo
Back to top
View user's profile Send private message
TraxMate
Master Cheater
Reputation: 0

Joined: 01 Mar 2008
Posts: 363

PostPosted: Sun Sep 28, 2008 12:01 pm    Post subject: Reply with quote

Dev C++ sucks so hard ... Don't use it use MSVC++ instead it's better and looks alot better : P
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Sun Sep 28, 2008 12:11 pm    Post subject: Reply with quote

actually i moved from MSVC++ to dev just to try it out
dev is pretty good though.. i don't think it that sucks Surprised

_________________
Stylo
Back to top
View user's profile Send private message
Anden100
Grandmaster Cheater
Reputation: 0

Joined: 20 Apr 2007
Posts: 668

PostPosted: Sun Sep 28, 2008 12:39 pm    Post subject: Reply with quote

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 Surprised


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
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Sun Sep 28, 2008 4:01 pm    Post subject: Reply with quote

The MS compiler is far, far better.
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Sun Sep 28, 2008 5:37 pm    Post subject: Reply with quote

yea i know that, just wanted to try other compilers O_O
_________________
Stylo
Back to top
View user's profile Send private message
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Mon Sep 29, 2008 1:48 am    Post subject: Reply with quote

1qaz wrote:
yea i know that, just wanted to try other compilers O_O


http://www.intel.com/cd/software/products/asmo-na/eng/279578.htm
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites