Skip to main content
gamedev.net
🔒 Locked

Reading string from .DLL

Started by Revelation60 Apr 13, 2007 at 2:13 PM 2 replies 400+ views
Original Post
Revelation60
Revelation60
Hi, I am writing a language pack for my OpenGL game, and I thought that it'd be a good idea to store the data in a .dll. (If it is not, please let me know!) That looks like this: #define EXP __declspec(dllexport) extern const char * EXP LANG_NewGame = "Nieuw spel" Now, I try to load the char* like this, but it fails: string temp = stAppDirectory + "Dutch.dll"; LoadMe = LoadLibrary(temp.c_str()); if (LoadMe != NULL) { strcpy(LANG_NewGame, (char*)GetProcAddress(LoadMe, "LANG_NewGame")); // int* lol = (int*)GetProcAddress(LoadMe, "LANG_NewGame"); // LANG_NewGame = (char*)lol; FreeLibrary(LoadMe); } I can't include a .def file, because I don't know in design time what language pack a player wants.
Currently working on WalledIn
Kwizatz
Kwizatz
Can't you just have a function that returns the string address?

IE:
const char somestring[]="hello!";const char* GetString(int id){switch(id){// ...case 123:return somestring;// ...}return NULL;}


Then you GetProcAddress to the GetString function and you're all set.
Revelation60
Revelation60
I have thought of that, but then I must give every string an ID. MSDN claimed that GetProcAddress can return a pointer to a variable too.

Well, if I can't find another method, I'll use the ID method.
Currently working on WalledIn
Kwizatz
Kwizatz
Well, I think you can do it, probably thru windows resource files rather than code though, I think there is a tutorial somwhere on how to create resource only DLLs (cards.dll is an example of a resource only dll). The system to retrieve resources is very similar to the id and string method, so I wonder if you will get much gain.

Now, consider this:

enum GameStrings{NewGame=0,Save,Load,Quit,StringCount};unsigned char* StringConstants[StringCount];for(int i=0;i<StringCount;++i){  Menu=GetString(i);}fprintf(stdout,"%s\n",StringConstants[NewGame]);fprintf(stdout,"%s\n",StringConstants[Save]);fprintf(stdout,"%s\n",StringConstants[Load]);fprintf(stdout,"%s\n",StringConstants[Quit]);


Not so unreadable [smile].

Topic Locked

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

Sign in to reply to this topic.