Skip to main content
gamedev.net
🔒 Locked

DLL Problems

Started by Drezard 8 replies 950+ views
Original Post
Drezard
Drezard
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
LessBread
LessBread
BOOL, DWORD, LPVOID are Windows types. Include "windows.h" and that error should go away.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Drezard
Drezard
Okay cheers.
Drezard
Drezard
Nope sorry it doesnt. What else could cause it
LessBread
LessBread
#include didn't make that error go away? That's odd.

BOOL HANDLE DWORD LPVOID

These are Windows types.

APIENTRY

This is a Windows calling convention macro.

You need to include windows.h to use these.

"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Drezard
Drezard
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
bakery2k1
bakery2k1
Why do you have APIENTRY in your definition of DllMain? The correct prototype for DllMain is given here.
silvermace
silvermace
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
LessBread
LessBread
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 ‘@'
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
sp1k
sp1k
Quote:
Original post by Drezard
BOOl APIENTRY DllMain( HANDLE hModule,


Just something I saw, maybe it is a miss by you when writing the post. Otherwise if that line is identical to your code then the error is caused by BOOl. All letters sould be uppercase so it reads BOOL.
._.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.