| View previous topic :: View next topic |
| Author |
Message |
nwongfeiying Grandmaster Cheater
Reputation: 2
Joined: 25 Jun 2007 Posts: 695
|
Posted: Mon Jul 06, 2009 8:27 pm Post subject: [C++] Loading functions from a DLL |
|
|
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 |
|
 |
&Vage Grandmaster Cheater Supreme
Reputation: 0
Joined: 25 Jul 2008 Posts: 1053
|
Posted: Mon Jul 06, 2009 8:54 pm Post subject: |
|
|
| Check and see if the export names are right. MSVC tends to change the export's name.
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Mon Jul 06, 2009 9:39 pm Post subject: |
|
|
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 |
|
 |
nwongfeiying Grandmaster Cheater
Reputation: 2
Joined: 25 Jun 2007 Posts: 695
|
Posted: Mon Jul 06, 2009 10:07 pm Post subject: |
|
|
| Is there a way to _declspec(dllexport) all of the functions at once?
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Tue Jul 07, 2009 11:22 am Post subject: |
|
|
No you must include the prefix before each function you wish to export.
_________________
|
|
| Back to top |
|
 |
nwongfeiying Grandmaster Cheater
Reputation: 2
Joined: 25 Jun 2007 Posts: 695
|
Posted: Tue Jul 07, 2009 11:35 am Post subject: |
|
|
| lurc wrote: | | No you must include the prefix before each function you wish to export. |
I feared so
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 |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Tue Jul 07, 2009 7:59 pm Post subject: |
|
|
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 |
|
 |
nwongfeiying Grandmaster Cheater
Reputation: 2
Joined: 25 Jun 2007 Posts: 695
|
Posted: Tue Jul 07, 2009 9:52 pm Post subject: |
|
|
| 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 |
|
 |
edwin5254 How do I cheat?
Reputation: 0
Joined: 31 Aug 2008 Posts: 3
|
Posted: Wed Jul 08, 2009 12:25 am Post subject: |
|
|
try
extern "C" _declspec(dllexport)
|
|
| Back to top |
|
 |
BanMe Master Cheater
Reputation: 0
Joined: 29 Nov 2005 Posts: 375 Location: Farmington NH, USA
|
|
| Back to top |
|
 |
|