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++ function dll
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Snootae
Grandmaster Cheater
Reputation: 0

Joined: 16 Dec 2006
Posts: 969
Location: --->

PostPosted: Thu Apr 17, 2008 8:40 am    Post subject: C++ function dll Reply with quote

hey, i was wondering if anyone could give me an example of how to load a function from a dll or explain how to do it, and how to use it in a program, i have googled, but i got very confused because the examples i was looking at all involved returning a value
_________________
Back to top
View user's profile Send private message
DeletedUser14087
I post too much
Reputation: 2

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Thu Apr 17, 2008 8:54 am    Post subject: Reply with quote

you jsut want to export functions and call them on other programs ?
Back to top
View user's profile Send private message
systat
Advanced Cheater
Reputation: 0

Joined: 15 Feb 2008
Posts: 54

PostPosted: Thu Apr 17, 2008 10:49 am    Post subject: Reply with quote

Code:
http://www.codeproject.com/KB/DLL/loadingdll.aspx

_________________
uuuuuuuuuuuuu
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Thu Apr 17, 2008 1:44 pm    Post subject: Reply with quote

Theres 2 ways to do it.

You can typedef a new function pointer then declare a new instance of that pointer and then give it the value of the address of the function in the dll.

typedef (type __stdcall Name*)(Parameters);
Name FunctionName

FunctionName = (Name)GetProcAddress( LoadLibrary(_T("DllName" )), "Function" );

OR you can make your own new _declspec(naked) function that just jumps straight to the function addy.

DWORD AddyToFunction = (DWORD)GetProcAddress( LoadLibrary(_T("DllName" )), "Function" );
_declspec(naked) Type WINAPI FunctionName( Parameters );
{ _asm jmp dword ptr ds:[AddyToFunction] }

Once you have that, you can call it like a normal function, so you would call FunctionName


Heres an example for loading LoadLibrary from kernel32.dll

Code:
DWORD _LLW = (DWORD)GetProcAddress( LoadLibrary( _T("Kernel32.dll") ), "LoadLibraryW");
_declspec(naked) HMODULE WINAPI _LoadLibrary( __in  LPCTSTR lpFileName )
{
   _asm jmp dword ptr ds:[_LLW]
}


Then i just call _LoadLibrary with the same parameters as LoadLibrary

_________________
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: Thu Apr 17, 2008 2:46 pm    Post subject: Reply with quote

You really should avoid using inline ASM for such things like this. It's bad practice. Just call the API directly.

You can also export the functions and import them into your project to dynamically call to them. I made a signature scanner that is designed like this which you can check out here:

http://www.extalia.com/forums/viewtopic.php?f=21&t=2789

The function is exported based on:

Code:
#ifdef SIGSCAN_EXPORTS
#define SIGSCAN_API __declspec(dllexport)
#else
#define SIGSCAN_API __declspec(dllimport)
#endif


Inside the project properties under the preprocessor definitions, SIGSCAN_EXPORTS is defined. You only use that for the DLL project. Inside the project that imports the DLL you do not use it. This way the #ifdef is set to import the function in the real project.

Then the define would look like:

Code:
SIGSCAN_API DWORD __stdcall FindPattern(DWORD dwProcId, BYTE* bBaseAddress, DWORD dwModuleSize, TCHAR* tszPattern, int iOffset, TCHAR* tszMask);


Simple enough, just drop the .DLL in with the .exe your program makes and include the sigscan.h file and you are set.

That project should give you a general idea of how to do it.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Thu Apr 17, 2008 4:57 pm    Post subject: Reply with quote

Read the code project link it's very useful. But if you want heres the code, it was commented out so you should be able to understand it. But there are other scenarios where you can't do this so read the code project link.

Code:

//You need to declare types to point on classes/functions in LoadMe.dll

//Assume, you have a function in your LoadMe.dll with a name

//EntryPoint, which takes two parameters of types int and const char *,

//and is of type void. You need to create a new type as a

//pointer to that function as it is shown below.


typedef void (*EntryPointfuncPtr)(int argc, const char * argv ); 
 
//Declare an HINSTANCE and load the library dynamically. Don’t forget

//to specify a correct path to the location of LoadMe.dll


HINSTANCE LoadME;
LoadMe = LoadLibrary("..\\enter a Path To Your Dll here\\LoadMe.dll");
 
// Check to see if the library was loaded successfully

if (LoadMe != 0)
    printf("LoadMe library loaded!\n");
else
    printf("LoadMe library failed to load!\n");

//declare a variable of type pointer to EntryPoint function, a name of

// which you will later use instead of EntryPoint

EntryPointfuncPtr LibMainEntryPoint;           

// GetProcAddress – is a function, which returns the address of the

// specified exported dynamic-link library (DLL) function. After

// performing this step you are allowed to use a variable

// LibMainEntryPoint as an equivalent of the function exported in

// LoadMe.dll. In other words, if you need to call

// EntryPoint(int, const char *) function, you call it as

// LibMainEntryPoint(int, const char *)


LibMainEntryPoint = (EntryPointfuncPtr)GetProcAddress(LoadMe,"entryPoint");

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Noz3001
I'm a spammer
Reputation: 26

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

PostPosted: Thu Apr 17, 2008 5:27 pm    Post subject: Reply with quote

dont forget to
Code:
#pragma comment( lib, "libname.lib" )
Back to top
View user's profile Send private message MSN Messenger
Snootae
Grandmaster Cheater
Reputation: 0

Joined: 16 Dec 2006
Posts: 969
Location: --->

PostPosted: Thu Apr 17, 2008 7:16 pm    Post subject: Reply with quote

thanks guys, i think i've got it now

this is a great forum

_________________
Back to top
View user's profile Send private message
DeletedUser14087
I post too much
Reputation: 2

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Fri Apr 18, 2008 1:55 am    Post subject: Reply with quote

Just do it like this:

Code:
#ifdef __cplusplus
extern "C" { 
             
#endif

__declspec( dllexport ) void Hello;

#ifdef __cplusplus
}
#endif
Back to top
View user's profile Send private message
--Pillboi--
Grandmaster Cheater Supreme
Reputation: 0

Joined: 06 Mar 2007
Posts: 1383
Location: I don't understand the question. Is this a 1 to 10 thing?

PostPosted: Sun Apr 20, 2008 12:30 pm    Post subject: Reply with quote

oib111, sorry to bump this but... give your source! http://blog.empas.com/navylkh/read.html?a=1707462
I was just searching some of that in order to learn from it and boom. I found this.

_________________

Enter darkness, leave the light, Here be nightmare, here be fright...
Earth and Water, Fire and Air. Prepare to meet a creature rare.
Enter now if you dare, Enter now the dragon's lair.
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Sun Apr 20, 2008 12:37 pm    Post subject: Reply with quote

Lol. I did. I didn't give the link because it's already in this thread. I referred to it as the code project link. I'm pretty sure the first post in this thread. But w/e...http://www.codeproject.com/KB/DLL/loadingdll.aspx
_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
--Pillboi--
Grandmaster Cheater Supreme
Reputation: 0

Joined: 06 Mar 2007
Posts: 1383
Location: I don't understand the question. Is this a 1 to 10 thing?

PostPosted: Sun Apr 20, 2008 12:41 pm    Post subject: Reply with quote

Sorry, sorry, sorry. Your completely right. My full apologies, I didn't read it properly, and now feel like an idiot as a result.
_________________

Enter darkness, leave the light, Here be nightmare, here be fright...
Earth and Water, Fire and Air. Prepare to meet a creature rare.
Enter now if you dare, Enter now the dragon's lair.
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Sun Apr 20, 2008 12:48 pm    Post subject: Reply with quote

Haha. It's ok dude.
_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
--Pillboi--
Grandmaster Cheater Supreme
Reputation: 0

Joined: 06 Mar 2007
Posts: 1383
Location: I don't understand the question. Is this a 1 to 10 thing?

PostPosted: Sun Apr 20, 2008 12:53 pm    Post subject: Reply with quote

Thanks Embarassed
_________________

Enter darkness, leave the light, Here be nightmare, here be fright...
Earth and Water, Fire and Air. Prepare to meet a creature rare.
Enter now if you dare, Enter now the dragon's lair.
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Sun Apr 20, 2008 12:55 pm    Post subject: Reply with quote

np Smile
_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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