CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2010
    Posts
    25

    How include dll's in exe file?

    Hello,

    I have solution, which uses Qt dll's for GUI. When I build my solutin in MSVC++ 2008 Express Edition it will create .exe file, which I can run fine. But when I try to execute this .exe on another PC without installed Qt library, it will tell me, that some Qt dll's are missing and my app didn't start.

    So I ask one question - how to iclude these dll's into one stand alone .exe file, which could be run on different PCs without need to install Qt library?

    Thanks for answer!

  2. #2
    Join Date
    Jul 2009
    Location
    India
    Posts
    835

    Re: How include dll's in exe file?

    Resource binding is your answer.

    First of all build your vc++ application with /MT compiler switch and bind dlls as resource, then before calling 3rd party dll s from your application just create those file. Sample code for binding binary files as resource goes here..

    Code:
     
    void LoadResFile (int ResID, LPCWSTR ResFileName)
    {
          	DWORD lpNumBytes;
    	HRSRC hRes = FindResource (NULL, MAKEINTRESOURCE (ResID), RT_RCDATA);
    	
    	HGLOBAL hResLoad = LoadResource (NULL, hRes);
    	LPVOID lpResLock = LockResource (hResLoad);
    	DWORD dwSizeRes = SizeofResource(NULL, hRes);
    	
    	HANDLE hFile = CreateFile (ResFileName, GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    	WriteFile(hFile, lpResLock, dwSizeRes, &lpNumBytes, NULL);
    	
    	FreeResource (hRes);
    	FreeResource (hResLoad);
    	CloseHandle (hFile);
    }
    Edited due to simplicity.
    Last edited by hypheni; February 14th, 2011 at 06:37 AM.

  3. #3
    Join Date
    Oct 2010
    Posts
    25

    Re: How include dll's in exe file?

    Thanks for answer - I don't understand that code, does it mean, that I need to add something in my code?

    I tried to build it with \MT switch (set it in project properties C++\Code generation\Runtime library), but it wrote me hundreds of errors at the end of building.

    I also don't know, how to bind those dll's files as a resource?

  4. #4
    Join Date
    Jul 2009
    Location
    India
    Posts
    835

    Re: How include dll's in exe file?

    So you never worked with resource ?.

    /MT switch I said just to sure about that your exe wont depend on any vs runtime lib.

    And about resource binding you need to add ur dll s as resource in resource editor then set its type to RC_DATA.

    For more details how to do these google your self. By using the above code you can create the actual file on disk from its resource id.

  5. #5
    Join Date
    Jun 2009
    Location
    oklahoma
    Posts
    199

    Re: How include dll's in exe file?


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured