tags:

views:

22

answers:

1

Hi All,

I have one VC++ project that is compiled and generated .dll file. I have made one application that uses above vc++ .dll file. Can i build my new application .exe and .dll statically i want only one .exe file that include .dll file (statically) How is it possible in visula studio ?

Thanks, Neel

+1  A: 

Why have a DLL at all then if you just want to embed it inside the EXE?

[snip, edit]

So, to do this, you just need to add the DLL file as a resource, and use FindResource / LoadResource to extract it somewhere. You will need to write it to the filesystem if you want to load the DLL. Here's a function (C++) I use in a project to load a text file from a resource. You should be able to easily modify this for your purposes. NOTE that there is no error checking here; it's just to show you the basic idea.

std::string LoadTextFileResource(HINSTANCE hInstance, LPCTSTR szResName, LPCTSTR szResType)
{
    HRSRC hrsrc=FindResource(hInstance, szResName, szResType);
    if(!hrsrc) return L"";
    HGLOBAL hg1 = LoadResource(hInstance, hrsrc);
    DWORD sz = SizeofResource(hInstance, hrsrc);
    void* ptr1 = LockResource(hg1);

    // assume the encoding is ASCII.
    return std::string((const char*)ptr1, sz);
} 
tenfour
see i want to give only one .exe file to other and i have to use .dll file of another application that's why i want to embed .dll into my .exe file.Is there any other way then copy .dll to temp directory ?without copy can i build ?
Neel Patel