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 


DLL Problem (Not a CE issue)

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
The0neThe0nly
Expert Cheater
Reputation: 0

Joined: 08 Dec 2009
Posts: 119
Location: In a box

PostPosted: Tue Dec 27, 2011 8:28 pm    Post subject: DLL Problem (Not a CE issue) Reply with quote

Hey I wanted to test a dll that I built.

When injected, it should show up with a window with a menubar

Instead, it simply crashes the program that I am injecting into.

I injected it into Notepad, still didn't work. (I thought it may have been detected in the program earlier)

I did get a warning when I built this, it said that attempt 3.cpp(36): warning C4715: 'RegisterDLLWindowClass' : not all control paths return a value

Does the warning have to do anything with the crashes?

How do I fix this issue?


Code:

#include "stdafx.h"
#include "windows.h"

#define MYMENU_EXIT         (WM_APP + 101)
#define MYMENU_MESSAGEBOX   (WM_APP + 102)

HINSTANCE  inj_hModule;          //Injected Modules Handle
HWND       prnt_hWnd;            //Parent Window Handle

//WndProc for the new window
LRESULT CALLBACK DLLWindowProc (HWND, UINT, WPARAM, LPARAM);

//Register our windows Class
BOOL RegisterDLLWindowClass(wchar_t szClassName[])
{
    WNDCLASSEX wc;
    wc.hInstance =  inj_hModule;
   wc.lpszClassName = (LPCWSTR)L"InjectedDLLWindowClass";
    wc.lpszClassName = (LPCWSTR)szClassName;
    wc.lpfnWndProc = DLLWindowProc;
    wc.style = CS_DBLCLKS;
    wc.cbSize = sizeof (WNDCLASSEX);
    wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wc.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor (NULL, IDC_ARROW);
    wc.lpszMenuName = NULL;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
    if (!RegisterClassEx (&wc))
      return 0;
}
//Creating our windows Menu
HMENU CreateDLLWindowMenu()
{
   HMENU hMenu;
   hMenu = CreateMenu();
   HMENU hMenuPopup;
    if(hMenu==NULL)
        return FALSE;
    hMenuPopup = CreatePopupMenu();
   AppendMenu (hMenuPopup, MF_STRING, MYMENU_EXIT, TEXT("Exit"));
    AppendMenu (hMenu, MF_POPUP, (UINT_PTR) hMenuPopup, TEXT("File"));

   hMenuPopup = CreatePopupMenu();
    AppendMenu (hMenuPopup, MF_STRING,MYMENU_MESSAGEBOX, TEXT("MessageBox"));
    AppendMenu (hMenu, MF_POPUP, (UINT_PTR) hMenuPopup, TEXT("Test"));
   return hMenu;
}

//The new thread
DWORD WINAPI ThreadProc( LPVOID lpParam )
{
    MSG messages;
   wchar_t *pString = reinterpret_cast<wchar_t * > (lpParam);
   HMENU hMenu = CreateDLLWindowMenu();
   RegisterDLLWindowClass(L"InjectedDLLWindowClass");
   prnt_hWnd = FindWindow(L"Window Injected Into ClassName", L"Window Injected Into Caption");
   HWND hwnd = CreateWindowEx (0, L"InjectedDLLWindowClass", pString, WS_EX_PALETTEWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 400, 300, prnt_hWnd, hMenu,inj_hModule, NULL );
   ShowWindow (hwnd, SW_SHOWNORMAL);
    while (GetMessage (&messages, NULL, 0, 0))
    {
      TranslateMessage(&messages);
        DispatchMessage(&messages);
    }
    return 1;
}
//Our new windows proc
LRESULT CALLBACK DLLWindowProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
      case WM_COMMAND:
               switch(wParam)
               {
                    case MYMENU_EXIT:
                  SendMessage(hwnd, WM_CLOSE, 0, 0);
                        break;
                    case MYMENU_MESSAGEBOX:
                  MessageBox(hwnd, L"Test", L"MessageBox",MB_OK);
                        break;
               }
               break;
      case WM_DESTROY:
         PostQuitMessage (0);
         break;
      default:
         return DefWindowProc (hwnd, message, wParam, lParam);
    }
    return 0;
}

BOOL APIENTRY DllMain( HMODULE hModule, DWORD  ul_reason_for_call,LPVOID lpReserved)
{
   if(ul_reason_for_call==DLL_PROCESS_ATTACH) {
      inj_hModule = hModule;
      CreateThread(0, NULL, ThreadProc, (LPVOID)L"Window Title", NULL, NULL);
   }
   return TRUE;
}
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Wed Dec 28, 2011 2:33 pm    Post subject: Reply with quote

If you don't understand that warning you should probably be learning the language rather then copying code and just pasting it assuming it's going to work.

Code is from:
http://sim0n.wordpress.com/2009/03/29/c-creating-a-window-from-a-dll/

RegisterDLLWindowClass warns because there is no return at the end of the function. You also shouldn't call CreateRemoteThread from the entry point.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking 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