Jump to content
  • Advertisement
Sign in to follow this  
elih1

Unity opening dialog box from lib

This topic is 3712 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello all i want to open dialog box from my static library. and when I call FindResourceEx it returns the "the specified recource type can not be found in the image file". HINSTANCE inst=(HINSTANCE)GetModuleHandle(NULL); HRSRC hRSRC = FindResourceEx ( inst , RT_DIALOG , szResource , MAKELANGID ( LANG_NEUTRAL , SUBLANG_NEUTRAL ) ) ; I'm using GetModuleHandle to get the instance but this doesnot work. When i am doing this from dll instead static library everything works fine cause I get the HINSTANCE from DllMain i.e. I'm not using GetModuleHandle.But I can't have DllMain in static library am I How to do this to work with static library?(I found similar post but it seems not to have any solution http://www.gamedev.net/community/forums/topic.asp?topic_id=173005 ) thanks sorry for duplicate post

Share this post


Link to post
Share on other sites
Advertisement
Are you sure your dialog resource gets included in the static lib? And also linked into the main app? You can check this with a tool like ResHacker.

The instance you get with GetModuleHandle will return the HINSTANCE of the main app (which AFAIK is the only HINSTANCE if you use a static lib - in opposition to a dll).

Share this post


Link to post
Share on other sites
As Endurion said, you're passing in the HINSTANCE of the main EXE. If you call GetModuleHandle(NULL); from a DLL, you also get the HINSTANCE of the main EXE.
If you need the HINSTANCE of the DLL, you'll have to pass it in to the function, or else do some really hacky things that probably won't work (E.g. getting the value of the ESP register, enumerating all modules loaded for the current process, and finding the module that has a base address closest to the ESP register).

Share this post


Link to post
Share on other sites
if i use my library as dll I get the HINSTANCE from the DllMain function ,and pass that instance to the function to load the resource, and everything works fine.

But the problem is when I am trying to use the library as static (only in that case I am using GetModuleHandle(NULL) to get the instance of the main exe.) but the resource is not loaded. And why is this? When I compile my files should not all code and resource files be added to the static library and then linked in the main exe from the static library? And if not how to do that so the resource file is added to the lib and my main app?
Also I checked the .exe that links with static lib with ResHacker and the resources are not included in the .exe( ResHacker refused to check the .lib itself with the meassage this is not win32 executable, but I assume that the resources are not included in the lib since they are not included in the .exe that uses the lib ). What to do to bring them included,should i do some additional steps when compiling the lib, for resources to be inluded in it?


[Edited by - elih1 on October 11, 2008 6:15:15 AM]

Share this post


Link to post
Share on other sites
I just tried and i'm running onto the same problem.

If i create a static library, add a dialog box and one function to call the DialogBox, i get a message from the resource compiler:

LibTest.res : warning LNK4221: no public symbols found; archive member will be inaccessible

I have no idea how to force it to include the resource. There seems to be no switch or project property.

Share this post


Link to post
Share on other sites
I find the following link in net
"You receive the linker tools warning "LNK4221" message when you try to add resources to a static library" http://support.microsoft.com/kb/815773
about the problem. But I don't seem to understand how this will solve the problem. If someone have time to read it and say something about it
thanks u all a alot

Share this post


Link to post
Share on other sites
Neat. The link has a "solution" in the last line: Note When you want to share the resources, put the resources in a DLL.

This is not the help you're looking for :)

I found one way to do it but it's basically not what you want:

Include the .lib the normal way and add the compiled .res file (inside the debug/release folder) to the resource folder of the main apps solution.

Any other threads i find on this topic didn't find any better solution.


Another, really ugly possibility:

Compile the resource script once (to a .res file), add it into your code as simple binary array, create a global heap memory block of the same size, copy the array data into that block and call CreateDlgIndirect or DialogBoxIndirect on it.

A lot of work but it should work in that you only need to include the library. But you would have to call the array copy code before creating the dialog. Urg.

Share this post


Link to post
Share on other sites
ok thank u. The solutions I found were similar ,like making a new blank resource file in the main application and adding include reference to the original resource file.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!