FindResource() not working, need help.

This is a discussion on FindResource() not working, need help. within the Windows Programming forums, part of the Platform Specific Boards category; Was messing around with some code and came accross a problem that I've been trying to solve for a bit. ...

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    38

    FindResource() not working, need help.

    Was messing around with some code and came accross a problem that I've been trying to solve for a bit.

    In theory, how could this not work:

    Code:
       if(IS_INTRESOURCE(101) == FALSE){
           printf("101 is not a resource identifier...\n");
           return -1;
       }
       
       hResource = FindResource(hLibrary, MAKEINTRESOURCE(101), RT_RCDATA);
       if(hResource == NULL){
           printf("Error finding resource\n");
           return -1;
       }
    hLibrary loads fine, and IS_INTRESOURCE does not fail but FindResource does. :/ Any idea as to what could be wrong?
    I like to play pocket pool.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    2

  3. #3
    Registered User
    Join Date
    Feb 2005
    Posts
    38
    Umm, thanks? But you don't know how long I've been studying that same msdn code :/ I still can't figure out the reason...
    I like to play pocket pool.

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Where does the resource come from? (a DLL or the exe)
    Have you tried NULL as the hModule?

    Is hLibrary still valid?

    What does GetLastError() return?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    Registered User
    Join Date
    Feb 2005
    Posts
    38
    Quote Originally Posted by novacain
    Where does the resource come from? (a DLL or the exe)
    Resource comes from the exe.

    Have you tried NULL as the hModule?
    Yea that's what I'm using. Check the code at the bottom of this post.

    Is hLibrary still valid?
    Why would it become invalid?

    What does GetLastError() return?
    1812: ERROR_RESOURCE_DATA_NOT_FOUND :/

    code:

    Code:
       char shortpath[MAX_PATH] = {""},longpath[MAX_PATH] = {""};
       HMODULE modhandle;
       modhandle = GetModuleHandle(NULL);
       GetModuleFileName(modhandle,longpath,MAX_PATH);
       GetShortPathName(longpath,shortpath,MAX_PATH);
       
       HMODULE hLibrary;
       HRSRC hResource;
       HGLOBAL hResourceLoaded;
       LPBYTE lpBuffer;
       hLibrary = LoadLibrary(shortpath);
       
       if (hLibrary == NULL){
           printf("Error loading hlibrary\n");
           return -1;
       }
       printf("longpath: %s\n", longpath);
       printf("shortpath: %s\n", shortpath);
       
       if(IS_INTRESOURCE(101) == FALSE){
           printf("101 is not a resource identifier...\n");
           return -1;
       }
       
       hResource = FindResource(hLibrary, MAKEINTRESOURCE(101), RT_RCDATA);
       if(hResource == NULL){
           printf("%d\n", GetLastError());
           printf("Error finding resource\n");
           return -1;
       }
    Thanks for the help, thus far.
    Last edited by NoUse; 10-24-2005 at 07:11 PM.
    I like to play pocket pool.

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Sounds like there is a resource defined as 101 but it is not binary data...
    Remember that the resource ID# has to be uneque only to a dialog/window NOT the app.
    In practice ID# can be repeated in a dialog depending on the msg handlers used.

    Have you looked in the resource.h and found what is defined as 101?
    Could be there is more than one resource with the ID# 101.

    Try using the defined string rather than a number.
    What type of resource are you trying to extract?


    >>Yea that's what I'm using. Check the code at the bottom of this post.
    Have you tried
    hResource = FindResource(NULL, MAKEINTRESOURCE(101), RT_RCDATA);

    >>Why would it become invalid?
    Depending on the code, hLibrary could have lost scope ie non static variable in a callback function.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function not working
    By sloopy in forum C Programming
    Replies: 31
    Last Post: 11-12-2005, 07:08 PM
  2. Program Not working Right
    By raven420smoke in forum C++ Programming
    Replies: 2
    Last Post: 09-16-2005, 03:21 AM
  3. Trying to eject D drive using code, but not working... :(
    By snowfrog in forum C++ Programming
    Replies: 3
    Last Post: 05-07-2005, 07:47 PM
  4. x on upper right corner not working
    By caduardo21 in forum Windows Programming
    Replies: 1
    Last Post: 02-20-2005, 07:35 PM
  5. cygwin -> unix , my code not working properly ;(
    By CyC|OpS in forum C Programming
    Replies: 4
    Last Post: 05-18-2002, 04:08 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21