|
|
String table resource with static library |
|
Author |
Message |
Smriti
|
Posted: Visual C++ Express Edition, String table resource with static library |
Top |
Hi all,
I want to use string table resiurce with my static library. Is it possible to embed the resource file in library And as per what I have read, we use Loadstring() method to load the string, but this requires HINSTANCE handle, how do I get it in my library Any help will be greatly appreciated.
Regards,
Smriti
Visual Studio Express Editions22
|
|
|
|
|
nobugz
|
Posted: Visual C++ Express Edition, String table resource with static library |
Top |
You get it from LoadLibrary(), you'll need to call this API function to load the DLL before you can retrieve the string...
|
|
|
|
|
Smriti
|
Posted: Visual C++ Express Edition, String table resource with static library |
Top |
Hi,
Yes I will take care not to post in multiple forums... As regards to your reply, mine is a static library and not a dll... Also LoadLibrary() requires HINSTANCE handle, so how do I get this handle If I use GetModuleHandle(), this function requires the name of application or dll, I could not find any way of getting HINSTANCE handle to my static library....
Regards,
Smriti
|
|
|
|
|
nobugz
|
Posted: Visual C++ Express Edition, String table resource with static library |
Top |
Forget about my previous reply. When you make a .lib, you don't know yet how it is going to be used. It can be linked to a .exe or a .dll. If it is a .exe, you can use a 0 for the instance handle and Windows automatically uses the process instance. If it is a .dll, you need the hInstance value from the DllMain() entrypoint.
Best thing to do probably is to force the programmer that uses your .lib to supply you with the instance handle. That will also remind him/her to provide you with the string resource: extern HINSTANCE hResourceModule;
If they forget, they'll get a linker error...
|
|
|
|
|
Smriti
|
Posted: Visual C++ Express Edition, String table resource with static library |
Top |
Thanks for your reply. My lib will be finally linked to exe, that has
int WINAPI WinMain(HINSTANCE hInstance) as the starting point. Can i use this handle inside my library (Tried this, but this too does not load the required string) Also is it posible that my string table resource resides in library I have already tried passing null as parameter to GetModuleHandle () inside my lib ,and call LoadString with the handle returned, but that simply does not load the string....
|
|
|
|
|
nobugz
|
Posted: Visual C++ Express Edition, String table resource with static library |
Top |
Well, that oughta work, either with a NULL or the hInstance you got in WinMain. Next, make sure that the string resource ID number matches the one you used when you created the resource with the resource editor.
|
|
|
|
|
Smriti
|
Posted: Visual C++ Express Edition, String table resource with static library |
Top |
Ok, I figured out the problem, the loadString() method tries to look up into string able resource of my application rather than trying to locate it in library. I guess thats the default behaviour. Is there any way that I can force it to find the string in string table included in my library
Regards,
Smriti.
|
|
|
|
|
nobugz
|
Posted: Visual C++ Express Edition, String table resource with static library |
Top |
A static library can't have resources, only a .dll or .exe. Surprisingly, VS2005 does actually let you create resources for a .lib, I would never have thought to try it if it wasn't for your question. The linker doesn't know how to handle it though, as you found out...
|
|
|
|
|
|
|