Sign in to follow this  

Unity opening dialog box from lib

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 ) thanks sorry for duplicate post

Share this post

Link to post
Share on other sites
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"
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Announcements

  • Forum Statistics

    • Total Topics
    • Total Posts
  • Similar Content

    • By abarnes
      I am a game development student in my second year of a three year program and I would like to start building my portfolio. I was thinking of creating some games to show what I can do to potential employers since I wont have any work related experience when I graduate. But as I'm sure you all know there are tons of ways to approach developing/designing a game and I'm curious if anyone had any insight as to any "standards" that come with this? Is it okay to use game engines like Unity, Unreal, Game Maker etc? Or would it be better to make a game from scratch to better show case your skills? Any and all advice will be greatly appreciated!
    • By Hilster
      Hello 2D Artists,
      I've started making a 2D Puzzle Adventure game for mobile and I'm looking for someone who would want in on creating assets for the game. The core of the programming is pretty much complete, you can walk within the grid laid out and push boxes, when there is an object on top of a pressure pad it will activate the linked objects or if there is one object with multiple linked pressure pads it requires you to activate all points for the object to become active. 

      The level iteration for the game is quick and simple, a Photoshop file that is made of individual pixels that represents objects is put into the game and it creates the level out of those pixels with the assigned objects.
      The objects that need sprites created so far is the character, box, pressure pad, door, trap door, the walls, the stairs and the tiled background.
      I intend to add more objects so the amount I'd like to add will be extended.
      My motivations for posting here is to have something that looks nice to be able to display on my portfolio, so if you're looking for a working game that you can place your art into and improve the look of your portfolio then we're in business.
      Please reply with a few past examples of your art below and I'll be in touch!
    • By thefollower
      I have set up my TcpClient to connect to my server and that works fine. But i am a bit confused how i read messages from the network stream with it continuously running via async, without ever closing the connection ?
      My TcpClient Manager class has:
      public async Task<bool> Connect(string address, int port) { try { await _tcpClient.ConnectAsync(address, port); IsConnected = true; return true; } catch(Exception e) { Debug.Log(e); return false; } } public async Task<int> Read(byte[] readBuffer) { if (!IsConnected) return -1; using (var networkStream = _tcpClient.GetStream()) { try { var bytesRead = await networkStream.ReadAsync(readBuffer, 0, readBuffer.Length); return bytesRead; } catch (Exception e) { Debug.Log(e); IsConnected = false; return -1; } } }  
      So i thought to just run a co-routine and call Read constantly to get the most recent message, but that doesn't make much sense to me since a co-routine would be blocked with the await. How is this actually done? The MS Docs don't have very good Async examples with the TcpClient class so i don't know fully get how to keep calling Read correctly.
    • By NUITGaming
      Landscaping back ground maid in Unreal 4.18
  • Popular Now