Thread: Resources

  1. #16
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Moved to Windows.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  2. #17
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Code:
    #include <windows.h>
    #include "Resource.h"
    
    int WINAPI WinMain (HINSTANCE hInstance,
                        HINSTANCE hPrevInstance,
                        LPSTR lpCmdLine,
                        int iCmdShow)
    {
        HMODULE hModule = GetModuleHandle(NULL);
        DWORD err = 0;
    
        HRSRC hrsrc = ::FindResource( hModule, MAKEINTRESOURCE(MYTXTFILE), TEXT("BIN"));
        ::GetLastError(); if(err) { TCHAR bug[256]; wsprintf(bug, TEXT("%d"), err); ::MessageBox(0, bug, bug, 0); }
        HGLOBAL rsc = ::LoadResource( NULL, hrsrc );
        err = ::GetLastError(); if(err) { TCHAR bug[256]; wsprintf(bug, TEXT("%d"), err); ::MessageBox(0, bug, bug, 0); }
        LPVOID lock = ::LockResource( rsc );
        err = ::GetLastError(); if(err) { TCHAR bug[256]; wsprintf(bug, TEXT("%d"), err); ::MessageBox(0, bug, bug, 0); }
        DWORD size  = ::SizeofResource( NULL, hrsrc );
        err = ::GetLastError(); if(err) { TCHAR bug[256]; wsprintf(bug, TEXT("%d"), err); ::MessageBox(0, bug, bug, 0); }
        
        MessageBox( HWND_DESKTOP, (const char*) lock, "", MB_OK );
        
        return 0;
    }
    Not a graceful error handling system, but it'll tell you what happened.

  3. #18
    Registered User
    Join Date
    Jan 2007
    Posts
    9
    I'm still having problems with loading resources, here is the most up to date code:

    main.cpp:
    Code:
    #include <windows.h>
    #include "Resource.h"
    
    int WINAPI WinMain (HINSTANCE hInstance,
                        HINSTANCE hPrevInstance,
                        LPSTR lpCmdLine,
                        int iCmdShow)
    {
        HMODULE hModule = GetModuleHandle(NULL);
        DWORD err = 0;
    
        HRSRC hrsrc = ::FindResource( NULL, MAKEINTRESOURCE(MYTXTFILE), TEXT("TEXT"));
        err = ::GetLastError(); if(err) { TCHAR bug[256]; wsprintf(bug, TEXT("%d"), err); ::MessageBox(0, bug, "1", 0); }
        HGLOBAL rsc = ::LoadResource( NULL, hrsrc );
        err = ::GetLastError(); if(err) { TCHAR bug[256]; wsprintf(bug, TEXT("%d"), err); ::MessageBox(0, bug, "2", 0); }
        LPVOID lock = ::LockResource( rsc );
        err = ::GetLastError(); if(err) { TCHAR bug[256]; wsprintf(bug, TEXT("%d"), err); ::MessageBox(0, bug, "3", 0); }
        DWORD size  = ::SizeofResource( NULL, hrsrc );
        err = ::GetLastError(); if(err) { TCHAR bug[256]; wsprintf(bug, TEXT("%d"), err); ::MessageBox(0, bug, "4", 0); }
        
        MessageBox( HWND_DESKTOP, (const char*) &lock, "", MB_OK );
        
        return 0;
    }
    resources.rc:
    Code:
    #include "Resource.h"
    
    MYTXTFILE TEXT "mytextfile.txt"
    Resource.h:
    Code:
    #ifndef RLOADER_RESOURCE_H
    #define RLOADER_RESOURCE_H
    
    #define MYTXTFILE                  10001
    
    #endif
    And mytextfile.txt simply contains "ABC". The first GetLastError function used returns two, which according to msdn means "The system cannot find the file specified." I can't work out how to fix this though, maybe it's a problem with devcpp but I'm out of ideas. Do you (or anyone really) know how to get this program to work? Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Resources in Dev C++
    By JJFMJR in forum Windows Programming
    Replies: 7
    Last Post: 08-27-2007, 05:14 AM
  2. measuring system resources used by a function
    By Aran in forum C Programming
    Replies: 1
    Last Post: 03-13-2006, 05:35 PM
  3. Getting resources from another program.
    By Queatrix in forum C++ Programming
    Replies: 3
    Last Post: 02-11-2006, 09:00 PM
  4. Storing resources into a single file
    By LuckY in forum Game Programming
    Replies: 20
    Last Post: 08-14-2004, 11:28 PM
  5. Adding resources
    By nima_ranjbar in forum Windows Programming
    Replies: 0
    Last Post: 04-14-2002, 11:36 PM