I get Error Code 1813, "The specified resource type cannot be found in the image file."


  • I'm getting this error with this code:
    #include "windows.h"
    #include <string>
    #include <fstream>
    #include <iostream>

    BOOL WINAPI DllMain ( HANDLE hModule,
                           DWORD  ul_reason_for_call,
                           LPVOID lpReserved

    if( ul_reason_for_call == DLL_PROCESS_ATTACH )
        HGLOBAL hResourceLoaded;     
        HRSRC hRes;                       
        char *lpResLock;               
        DWORD dwSizeRes;

    hRes = FindResource(NULL, MAKEINTRESOURCE(101), TEXT("Exehead"));
    if(hRes == NULL)
            char error_msg[100];
            sprintf(error_msg, "FindResource failed with code: %d", GetLastError());
            MessageBox(0, error_msg, "failed", 0);
            return true;
    hResourceLoaded = LoadResource( NULL, hRes );
    if(hResourceLoaded == NULL)
            MessageBox(0, "LoadResource failed", "failed", 0);
            return true;
    lpResLock = (char*)LockResource( hResourceLoaded );
    if(lpResLock == NULL)
            MessageBox(0, "LockResource failed", "failed", 0);
            return true;
    dwSizeRes = SizeofResource(NULL, hRes );
    if(dwSizeRes == 0)
            MessageBox(0, "SizeofResource failed", "failed", 0);
            return true;
        std:Surprisefstream outputFile("c:\\peewee.exe", std::ios::binary);

        outputFile.write(lpResLock, dwSizeRes);
          return true;

    I am 100% sure that the type and ID of the resource is correct and exist. This code worked in EXE format, but with DLL it's returning this error.

    I'd be more than happy to upload my project files if someone is up for helping

    Any Ideas?!

    Friday, April 18, 2008 7:27 PM


  • FindResource takes a HINSTANCE as first parameter. NULL means the executable used to create the process. If you want to load from your DLL pass your HMODULE (the first parameter of DllMain).




    Friday, April 18, 2008 10:31 PM