CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 19

Threaded View

  1. #15
    Join Date
    Nov 2003
    Posts
    1,902

    Re: Question about linking in VS 2008.

    You could go through the trouble of linking the source staticaly... or
    >> you could embedd the DLL inside the EXE as a binary resource
    which is probably *much* easier....
    Code:
    bool SaveResourceFile(int res_id, const wchar_t *pathname)
    {
        HMODULE hmod = GetModuleHandle(0);
        HRSRC hr = FindResource(hmod, MAKEINTRESOURCE(res_id), RT_RCDATA);
        if (!hr)
        {
            LogMessage(L"FindResource(%d) failed, le = %u", res_id, GetLastError());
            return false;
        }//if
    
        DWORD hrsz = SizeofResource(hmod, hr);
        if (!hrsz)
        {
            LogMessage(L"SizeofResource() failed, le = %u", GetLastError());
            return false;
        }//if
    
        HGLOBAL hg = LoadResource(hmod, hr);
        if (!hg)
        {
            LogMessage(L"LoadResource() failed, le = %u", GetLastError());
            return false;
        }//if
    
        void *pfile = LockResource(hg);
        if (!pfile)
        {
            LogMessage(L"LockResource() failed, le = %u", GetLastError());
            return false;
        }//if
    
        FILE *f = _wfopen(pathname, L"wb");
        if (!f)
        {
            LogMessage(L"Failed to open %s for writting, le = %u", 
                       pathname, GetLastError());
            return false;
        }//if
    
        bool res = (fwrite(pfile, hrsz, 1, f) == 1);
        fclose(f);
    
        if (!res)
        {
            LogMessage(L"Failed to write resource data to file, le = %u", 
                       GetLastError());
        }//if
    
        return res;
    }//SaveResourceFile
    
    /*
    In your RC file:
    IDR_DLL RCDATA DISCARDABLE "pircbotcpp-mt.dll"
    */
    gg
    Last edited by Codeplug; May 25th, 2008 at 01:00 AM.

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