Postdll does not work! WTF?!

Posts 17 of 7 · Page 1 of 1
dll does not work! WTF?!
I made a dll to inject to diablo 2. First time making a dll so I somewhat copied someones code . But I dont understand the code makes perfect sense to me it should work but when I inject it to dll with my injector I made my self, ce or winject it doesnt write the text file. Im just doing the text file to check if the dll initialized.

Code:
#include "main.h"

#define game "Diablo II"

HWND hWnd;
HANDLE HndThread;

int Thread() {
	while(1) {
		ofstream file;
		file.open("test.txt");
		file << "worked";
		file.close();
		Sleep(1);
	}
}

BOOL APIENTRY DllMain(HMODULE hModule,DWORD reason,LPVOID lpReserved) {
	if(reason == DLL_PROCESS_ATTACH) {
		hWnd = FindWindow(NULL,game);
		if(hWnd == NULL) {
			return false;
		} else {
			HndThread = CreateThread(0,0,(LPTHREAD_START_ROUTINE)Thread,NULL,0,NULL);
		}
	}
	return true;
}
Plox help
1. the file test.txt would be in your system directory. use "C://test.txt" instead to make the txt file be created in ur c drive
2. remove the while lopp, u dont need it
3. use
Code:
BOOL WINAPI DllMain( HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved )
{
	if( dwReason == DLL_PROCESS_ATTACH )
	{
		CreateThread( NULL, NULL, (LPTHREAD_START_ROUTINE)Thread, NULL, NULL, NULL);
	}
	return TRUE;
}
instead. u dont need handles etc in dlls
4. make int Thread to void Thread

pm me if u need more help
Quote Originally Posted by kibbles18 View Post
1. the file test.txt would be in your system directory. use "C://test.txt" instead to make the txt file be created in ur c drive
2. remove the while lopp, u dont need it
3. use
Code:
BOOL WINAPI DllMain( HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved )
{
	if( dwReason == DLL_PROCESS_ATTACH )
	{
		CreateThread( NULL, NULL, (LPTHREAD_START_ROUTINE)Thread, NULL, NULL, NULL);
	}
	return TRUE;
}
instead. u dont need handles etc in dlls
4. make int Thread to void Thread

pm me if u need more help
thanks it worked now im gonna use BitBlt to draw to the diablo 2 window to make somewhat a menu DDDDD
Actually, the correct prototype for ThreadProc is DWORD WINAPI ThreadProc(__in LPVOID lpParameter);

Excerpt from ThreadProc Callback Function (Windows)

Do not declare this callback function with a void return type and cast the function pointer to LPTHREAD_START_ROUTINE when creating the thread. Code that does this is common, but it can crash on 64-bit Windows.
msdn is overly cautious i use void thread all the time. i have 64 bit as well
Quote Originally Posted by kibbles18 View Post
msdn is overly cautious i use void thread all the time. i have 64 bit as well
overly cautious? i think consistency is good.
nice have fun
Posts 17 of 7 · Page 1 of 1

Post a Reply

Tags for this Thread

Need help?