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++] Loading functions from a DLL

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

Joined: 25 Jun 2007
Posts: 695

PostPosted: Mon Jul 06, 2009 8:27 pm    Post subject: [C++] Loading functions from a DLL Reply with quote

WOS.exe is the executable and WML.dll is the library. WOS loads up the library and attempts to load up the function, but fails UNLESS the name of the function name is "main".

Here is the code that is functional:

Code:

bool main();
{
   /* code */
}

funcAddr = (FUNC)GetProcAddress(hinstDLL, "main");


This code results in WOS unable to load up the function address:

Code:

bool loop()
{
   /* code */
}

funcAddr = (FUNC)GetProcAddress(hinstDLL, "loop");


And this is the error handler I'm using:

Code:

if(NULL != funcAddr);
   cout << "Function loaded." << endl;
else
   cout << "Unable to load function." << endl;


What could I be doing wrong? And also, is there a way to _declspec(dllexport) all of the functions at once?

Edit: It looks like CEF's code parser has gone crazy. I'll add a pastebin link.

http://pastebin.com/me202092
Back to top
View user's profile Send private message
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Mon Jul 06, 2009 8:54 pm    Post subject: Reply with quote

Check and see if the export names are right. MSVC tends to change the export's name.
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Mon Jul 06, 2009 9:39 pm    Post subject: Reply with quote

If you do not include a .def file with the dll and state the library & exports in that file the compiler will mangle the export names up.

Module.def:

Code:
LIBRARY libName
EXPORTS
    ExportFunction1
    ExportFunction2


Main.cpp:

Code:
DWORD dwExportFunction1Addy = GetProcAddress(LoadLibrary(_T("libName.dll")), "ExportFunction1");

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

Joined: 25 Jun 2007
Posts: 695

PostPosted: Mon Jul 06, 2009 10:07 pm    Post subject: Reply with quote

Is there a way to _declspec(dllexport) all of the functions at once?
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Tue Jul 07, 2009 11:22 am    Post subject: Reply with quote

No you must include the prefix before each function you wish to export.
_________________
Back to top
View user's profile Send private message
nwongfeiying
Grandmaster Cheater
Reputation: 2

Joined: 25 Jun 2007
Posts: 695

PostPosted: Tue Jul 07, 2009 11:35 am    Post subject: Reply with quote

lurc wrote:
No you must include the prefix before each function you wish to export.


I feared so Sad

Anyhow, after I saw your reply, I researched .DEF files on MSDN and I got this result:

http://msdn.microsoft.com/en-us/library/a90k134d(VS.80).aspx

The point of _declspec(dllexport) is to remove the need for .DEF files?
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Tue Jul 07, 2009 7:59 pm    Post subject: Reply with quote

hmm... That is indeed correct.

Have you tried to include the .DEF file anyways to see if it demangles the export names?

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

Joined: 25 Jun 2007
Posts: 695

PostPosted: Tue Jul 07, 2009 9:52 pm    Post subject: Reply with quote

I have not yet, but I'm going to try soon. I've been juggling work on my website and my projects.
Back to top
View user's profile Send private message
edwin5254
How do I cheat?
Reputation: 0

Joined: 31 Aug 2008
Posts: 3

PostPosted: Wed Jul 08, 2009 12:25 am    Post subject: Reply with quote

try
extern "C" _declspec(dllexport)
Back to top
View user's profile Send private message
BanMe
Master Cheater
Reputation: 0

Joined: 29 Nov 2005
Posts: 375
Location: Farmington NH, USA

PostPosted: Wed Jul 08, 2009 5:38 pm    Post subject: Reply with quote

yea after you get the dll "exports" worked out you can include the "lib" inside your exe and use extern "C" __declspec(dllimport) in the declarations to the function in the exe..this can be done if the dll is in the "search path" for the loader Smile may not be as cool as dynamic loading as is lurc's method, but it works Smile
_________________
don't +rep me..i do not wish to have "status" or "recognition" from you or anyone.. thank you.
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