Dll String loading Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Estien77
Knows some wx things
Knows some wx things
Posts: 31
Joined: Tue Jan 13, 2009 8:38 pm
Location: Canada, eh?

Dll String loading

Post by Estien77 » Mon Aug 03, 2009 1:14 pm

Is there a crossplatform way to load strings from a dll file? I looked at the classes for Dll files, but it didn't have a string load function.
if(work == fun)
{
pigsCanFly = true;
}

leiradella
I live to help wx-kind
I live to help wx-kind
Posts: 172
Joined: Sun Sep 07, 2008 9:49 pm
Location: Rio de Janeiro, Brazil

Post by leiradella » Mon Aug 03, 2009 1:51 pm

I think you can only get function addresses from DLLs, but if you're the one creating the DLL you can export a function that will return the address of the strings (untested):

Code: Select all

/* This goes into the DLL */
static const char *strings[] =
{
    "one",
    "two",
    NULL
};

extern "C" __declspec(dllexport) __stdcall const char *
getStrings(void)
{
    return strings;
}
and then in the main app you get the address of getString and, by calling it, the address of the strings.

Cheers,

Andre

Estien77
Knows some wx things
Knows some wx things
Posts: 31
Joined: Tue Jan 13, 2009 8:38 pm
Location: Canada, eh?

Post by Estien77 » Mon Aug 03, 2009 1:53 pm

Unfortunately, I'm just importing strings from a game's dll file. I'm working on a modding program for it. I'll see if I can find some other cross platform way of doing it outside of wxWidgets. If I find one, I'll post it here for future reference.
if(work == fun)
{
pigsCanFly = true;
}

leiradella
I live to help wx-kind
I live to help wx-kind
Posts: 172
Joined: Sun Sep 07, 2008 9:49 pm
Location: Rio de Janeiro, Brazil

Post by leiradella » Mon Aug 03, 2009 2:00 pm

I see.

Well, if the strings are resources in the DLL, you can access them via resource loading functions at least on Windows. Dunno how to do it in other platforms.

If they're just arrays of characters inside the DLL file maybe you won't have any means to access them except by looking into the DLL and extracting them by hand.

Cheers,

Andre

Estien77
Knows some wx things
Knows some wx things
Posts: 31
Joined: Tue Jan 13, 2009 8:38 pm
Location: Canada, eh?

Post by Estien77 » Mon Aug 03, 2009 3:33 pm

Yes they are resources in a stringtable. Do other platforms use such things?
if(work == fun)
{
pigsCanFly = true;
}

ninja9578
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 236
Joined: Thu Jan 29, 2009 3:33 pm

Post by ninja9578 » Mon Aug 03, 2009 4:51 pm

I doubt it. I've never heard of such a thing in OSX, then again I don't use dynamic libs very much.

rodrigod
I live to help wx-kind
I live to help wx-kind
Posts: 172
Joined: Thu Jun 26, 2008 8:50 pm

Post by rodrigod » Tue Aug 04, 2009 6:48 pm

A cross-platform solution is the .po file. It can be used to translate aplications but I use it as a string table.

I have an aplication for windows that I am porting so what I did was a short aplication that read the resource aplication and created the po file. So when on linux instead of reading the resource i read po file.

If you are instested in this solution I can post the code for the aplication for the conversion here.

See ya

Estien77
Knows some wx things
Knows some wx things
Posts: 31
Joined: Tue Jan 13, 2009 8:38 pm
Location: Canada, eh?

Post by Estien77 » Wed Aug 05, 2009 1:23 pm

I ended up just writing code that checks if it's being compiled on windows, then runs the winapi code for loading strings from a dll library. It only uses the dll file when it is compiled under windows.
if(work == fun)
{
pigsCanFly = true;
}

maxlondon
In need of some credit
In need of some credit
Posts: 4
Joined: Wed Aug 05, 2009 1:26 pm

Post by maxlondon » Wed Aug 05, 2009 1:40 pm

IMHO DLLs (not dynamic libraries in general) and this type of resources are Win(32) specific.

If you are loading this from a game's DLL, why does it need to be cross-platform?

Estien77
Knows some wx things
Knows some wx things
Posts: 31
Joined: Tue Jan 13, 2009 8:38 pm
Location: Canada, eh?

Post by Estien77 » Wed Aug 05, 2009 1:44 pm

Someone had asked me to make a cross platform version, not really sure why, but it made for a good learning experience ;) I had to rewrite the code from scratch anyway, because it was my first program and the code had become unmanagable, with many bugs. I have a much better understanding of writing programs now, so much less bugs this time I hope. Especially since the first one was direct winapi calls *shudder*
if(work == fun)
{
pigsCanFly = true;
}

maxlondon
In need of some credit
In need of some credit
Posts: 4
Joined: Wed Aug 05, 2009 1:26 pm

Post by maxlondon » Wed Aug 05, 2009 2:05 pm

Maybe just move the string loading into a separate module, which is platform specific, and keep the rest of your program generic.

Estien77
Knows some wx things
Knows some wx things
Posts: 31
Joined: Tue Jan 13, 2009 8:38 pm
Location: Canada, eh?

Post by Estien77 » Wed Aug 05, 2009 2:16 pm

Well the two places it is used, the objects have internal names as well, so if compiled under windows it will try and get the dll string, but if compiled under something else, it will not even know that the game has dll files (since that is the only reason I load them at all). It seems to work rather well, and only requires three or four "#ifdef __WINDOWS__" plus the ones for the header includes.
if(work == fun)
{
pigsCanFly = true;
}

Post Reply