|
-
February 14th, 2011, 03:11 AM
#1
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!
-
February 14th, 2011, 04:18 AM
#2
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.
-
February 14th, 2011, 06:00 AM
#3
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?
-
February 14th, 2011, 06:35 AM
#4
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.
-
February 14th, 2011, 01:22 PM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|