embed dll (no src code) into exe, but shouldn't dump dll to disk while exe running RRS feed

  • 问题

  • 1. There is a function void func1() in destDll.dll. I don't have any source code of the dll.

    2. I want create a project1.exe, which embed the destDll.dll(it means while exe runing, destDll.dll must not exsist).And it is not allowed that destDll.dll dump to a disk.Because I want the operator is not able to get the destDll.dll.

    3. I have embedded dll with "insert bmp to resource" and get the binary of dll from memory while exe running and it's the same as the origin.

    4. However, I don't know how to loadlibrary, GetProcAddress from memory.

    5. Any more, it's supported that dll_attach_main, global variable initing may run while LoadLibrary. And the data in memory while running and the data of dll in disk is different. So it should be useless to call the address of offset.

    Thank you for your help!

    #include <Windows.h>
    #include <tchar.h>
    #include <cstdio>
    #include "resource.h"
    int main() {
            HMODULE aHmodule = LoadLibrary("../release/destDll.dll");
            if (aHmodule) {
                    FARPROC aFarproc = GetProcAddress(aHmodule, "func1");
                    printf("aFarproc=%u\n", aFarproc);//success
            HRSRC hRsrc = FindResource(NULL, MAKEINTRESOURCE(IDR_RDLL1), "Rdll");
            FARPROC aFarproc = GetProcAddress(HMODULE(hRsrc), "func1");
            printf("aFarproc=%u\n", aFarproc);//fail
            if (hRsrc) {
                    HGLOBAL hGlobal = LoadResource(NULL, hRsrc);
                    FARPROC aFarproc = GetProcAddress(HMODULE(hGlobal), "func1");
                    printf("aFarproc=%u\n", aFarproc);//fail
                    DWORD dwSize = SizeofResource(NULL, hRsrc);
                    LPVOID pBuffer = LockResource(hGlobal);
                    if (pBuffer) {
                            FILE *fp = fopen(_T("1.x"), _T("wb"));
                            DWORD szWrite = fwrite(pBuffer, sizeof(char), dwSize, fp);
                            if (dwSize == szWrite) {
                                    printf("write %u\n", szWrite);//1.x and destDll.dll are same
            return 0;

    2017年10月23日 7:14


  • Hi sculida,


    >>embed dll (no src code) into exe, but shouldn't dump dll to disk while exe running




    Best Regards,
    Sera Yu

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    • 已建议为答案 Baron Bi 2017年12月12日 7:14
    • 已标记为答案 sculida 2018年8月8日 2:12
    2017年10月24日 8:25