 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
TraxMate Master Cheater
Reputation: 0
Joined: 01 Mar 2008 Posts: 363
|
Posted: Sun Oct 19, 2008 1:13 pm Post subject: [C++] How do I use a function from a separate dll? |
|
|
| The title says it all. I've searched and I didn't come up with a way to do it.
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Sun Oct 19, 2008 1:41 pm Post subject: |
|
|
Here's some sample code that I'll quickly code for ya here (sorry for errors if they occur.)
EXE:
| Code: | #include <Windows.h>
#include <Tchar.h>
typedef INT (WINAPI * _Add)(__in INT nNum1, __in INT nNum2);
_Add Add;
BOOL WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nShowCmd)
{
UNREFERENCED_PARAMETER(hInstance);
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
UNREFERENCED_PARAMETER(nShowCmd);
HMODULE hDLL = NULL;
int nAdded = NULL;
LPTSTR lpAdded = (LPTSTR)HeapAlloc(GetProcessHeap(), 0, sizeof(TCHAR)*5);
if (lpAdded != NULL)
{
hDLL = LoadLibrary(_T("Add.dll"));
Add = (_Add)GetProcAddress(hDLL, "Add");
if ((DWORD)Add != NULL)
{
nAdded = Add(10, 15);
wsprintf(lpAdded, _T("%d"), nAdded);
MessageBox(NULL, lpAdded, _T("Add function ret"), MB_OK);
}
HeapFree(GetProcessHeap(), 0, (LPVOID)lpAdded);
}
return 0;
} |
DLL:
| Code: | #include <Windows.h>
__declspec(dllexport) INT WINAPI Add(__in INT nNum1, __in INT nNum2)
{
return (nNum1 + nNum2);
}
BOOL WINAPI DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
{
UNREFERENCED_PARAMETER(hModule);
UNREFERENCED_PARAMETER(dwReason);
UNREFERENCED_PARAMETER(lpReserved);
return TRUE;
} |
_________________
|
|
| Back to top |
|
 |
TraxMate Master Cheater
Reputation: 0
Joined: 01 Mar 2008 Posts: 363
|
Posted: Sun Oct 19, 2008 2:57 pm Post subject: |
|
|
Thx . Now it's time to study the code and learn ^^-
EDIT: When I'm adding this to the dll:
| Code: | void omg()
{
MessageBox(NULL, _T("Test"), _T("Test"), MB_OK);
} | and add a CreateThread like this | Code: | BOOL WINAPI DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
{
UNREFERENCED_PARAMETER(hModule);
UNREFERENCED_PARAMETER(dwReason);
UNREFERENCED_PARAMETER(lpReserved);
CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)omg, NULL, NULL, NULL);
return TRUE;
} | Why does it spam the messagebox like in a loop? And it's not like a normal loop when you click OK it pops up again, now it's popping up all the time lagging up my comp so i have to restart it.
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Sun Oct 19, 2008 3:02 pm Post subject: |
|
|
Because DllMain has 4 different ways of being called.
DLL_PROCESS_ATTACH
DLL_PROCESS_DETACH
DLL_THREAD_ATTACH
DLL_THREAD_DETACH
so if you wanted to make it message box once, do
| Code: | if (dwReason == DLL_PROCESS_ATTACH)
CreateThread(...) |
_________________
|
|
| Back to top |
|
 |
TraxMate Master Cheater
Reputation: 0
Joined: 01 Mar 2008 Posts: 363
|
Posted: Mon Oct 20, 2008 8:09 am Post subject: |
|
|
oh yeah.. forgot that . Thanks again lurc, i would +rep you if i could.
|
|
| Back to top |
|
 |
|
|
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
|
|