🔒 Locked
DLL Problems
Advertisement
Original Post
Im trying to make a static DLL using Dev-C++. Now heres my code for it so far: CODE: #include #include #include using namespace std; extern "C" __declspec(dllexport)void new_user(string username, string password , string charname); BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { return TRUE; } void new_user(string username, string password , string charname) { string filename = username + ".txt"; ofstream file( filename.c_str() ); } Now this is just a bases but Im getting this error from trying to compile it: ERROR: Line 9 - 'BOOL' does not name a type
Oh wait its a new error:
Line 10 - Expected constructor, destructor, or type conversion before "DllMain"
Line 10 - Expected ',' or ';' before 'DLLmain'
And heres my updated code:
#include
#include
#include
#include
using namespace std;
extern "C" __declspec(dllexport)void new_user(string username, string password , string charname);
BOOl APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved)
{
return TRUE;
}
void new_user(string username, string password , string charname) {
string filename = username + ".txt";
ofstream file( filename.c_str() );
string output = username + " ";
output = output + password;
output = output + " ";
output = output + charname;
file<
}
- cheers, Daniel
Line 10 - Expected constructor, destructor, or type conversion before "DllMain"
Line 10 - Expected ',' or ';' before 'DLLmain'
And heres my updated code:
#include
#include
#include
#include
using namespace std;
extern "C" __declspec(dllexport)void new_user(string username, string password , string charname);
BOOl APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved)
{
return TRUE;
}
void new_user(string username, string password , string charname) {
string filename = username + ".txt";
ofstream file( filename.c_str() );
string output = username + " ";
output = output + password;
output = output + " ";
output = output + charname;
file<
}
- cheers, Daniel
I strongly advise you to not pass STL containers (e.g. string) between a DLL and its linking application - change them to null terminated strings (const char*).
There are massive issues with DLL's having their own stacks and more importantly the fact that the STL implementation linked to the application must be identical (or at least binary compatible) with the one linked with the DLL - this is extremely hard to guarantee unless you are authoring the DLL and the EXE at the same time, but this may be defeatist as no one else can develop new DLL's so the approach unwontedly eliminates most of the benefits of the DLL/EXE architecture.
some sound advice in this past thread: http://www.gamedev.net/community/forums/topic.asp?topic_id=190602
likewise (near the end): http://www.codeguru.com/forum/archive/index.php/t-229394.html
There are massive issues with DLL's having their own stacks and more importantly the fact that the STL implementation linked to the application must be identical (or at least binary compatible) with the one linked with the DLL - this is extremely hard to guarantee unless you are authoring the DLL and the EXE at the same time, but this may be defeatist as no one else can develop new DLL's so the approach unwontedly eliminates most of the benefits of the DLL/EXE architecture.
some sound advice in this past thread: http://www.gamedev.net/community/forums/topic.asp?topic_id=190602
likewise (near the end): http://www.codeguru.com/forum/archive/index.php/t-229394.html
Quote:
Original post by bakery2k1
Why do you have APIENTRY in your definition of DllMain? The correct prototype for DllMain is given here.
Um...
#define APIENTRY WINAPI
#define WINAPI __stdcall
_stdcall
* Arguments Passed from Right to Left
* Called Function Clears the Stack
* ‘this' pointer passed via Stack Last
* Functions Using _stdcall are preceded by a ‘_' and end with ‘@'
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement