Results 1 to 14 of 14

Thread: Program Resources

  1. #1

    Thread Starter
    Lively Member ExciteMouse's Avatar
    Join Date
    Jul 2000
    Location
    Dallas, TX
    Posts
    78

    Question

    I am making a program that needs to load a resource other than a BMP,ICO,CUR,String.. or any basic resource.. its an HTML file..

    So i added it to the resources of my program, so how to i load it into a varible.. lets say a char or CString?

    thanks

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Code:
    unsigned long ulLen;
    unsigned char *pubData;
    void *pRawData;
    HRSRC hRes;
    HGLOBAL hStub;
    
    hRes = FindResource(hModule, MAKEINTRESOURCE(IDR_DATA1), RT_RCDATA);
    ulLen = SizeofResource(hModule, hRes);
    hStub = LoadResource(hModule, hRes);
    pRawData = LockResource(hStub);
    pubData = new unsigned char[ulLen];
    memcpy(pubData, pRawData, ulLen);
    After that, pubData is a pointer to a memory block with your data in it, of length ulLen. So, if it's a character string, you could do:
    Code:
    cout << pubData << endl;
    That's as long as the data in the resource ends with '\0'. Otherwise, you'd need to use:
    Code:
    for(int i = 0; i < ulLen; i++)
        cout << pubData[i];
    }
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Lively Member ExciteMouse's Avatar
    Join Date
    Jul 2000
    Location
    Dallas, TX
    Posts
    78

    Cool Thanks!

    thanks alot man.. works great =)

  4. #4

    Thread Starter
    Lively Member ExciteMouse's Avatar
    Join Date
    Jul 2000
    Location
    Dallas, TX
    Posts
    78

    Question hmmm one more question

    i need to know how to get the `hModule` of my app.
    in order to load resource the first parameter has to be a HMODULE..
    im using MFC.

  5. #5

    Thread Starter
    Lively Member ExciteMouse's Avatar
    Join Date
    Jul 2000
    Location
    Dallas, TX
    Posts
    78

    this?

    would this be the correct way?

    const char* mes = AfxGetApp()->m_pszAppName;
    char APP_PATH[MAX_PATH];
    memset(&APP_PATH, 0x0, MAX_PATH);
    sprintf(APP_PATH, "%s.EXE", mes);

    HMODULE hModule = LoadLibrary(APP_PATH);

    that would get the APP name and then load it. It doesnt return NULL.. so i guess its working.

  6. #6

    Thread Starter
    Lively Member ExciteMouse's Avatar
    Join Date
    Jul 2000
    Location
    Dallas, TX
    Posts
    78

    damn!

    ok nothing is working... im sure your code works.. but i cant get the HMODULE of my app...
    when i call LoadLibrary.. it returns 0x00400000
    so i assumed it works.. then when i use your code FindResource returns NULL.

    any other ideas?

  7. #7

    Thread Starter
    Lively Member ExciteMouse's Avatar
    Join Date
    Jul 2000
    Location
    Dallas, TX
    Posts
    78

    It works!

    i just had to use RT_HTML
    since it was defined as a HTML resource
    doh!
    ok man thanks tons again!

  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    To get a module handle under MFC, use AfxGetResourceHandle().
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  9. #9
    Hyperactive Member
    Join Date
    Jul 2002
    Location
    WGTN, New Zealand
    Posts
    338
    Hello!

    I did a search (rather than reposting an already-asked question) and saw this, but I can't get it to work... is there some way I have to add the resource (I'm using MSVC++)?

    Thanks

  10. #10
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    You have to insert a user-defined resource.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  11. #11
    Hyperactive Member
    Join Date
    Jul 2002
    Location
    WGTN, New Zealand
    Posts
    338
    I did, but I found that the problem comes when the program gets to memcpy.

  12. #12
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Are you sure you use the correct resource name? Have you tested the raw pointer for NULL?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  13. #13
    Hyperactive Member
    Join Date
    Jul 2002
    Location
    WGTN, New Zealand
    Posts
    338
    Yeah I fixed it, instead of RT_RCUSER I had to use (LPTSTR)"BINARY"... I dunno why, under the resource view it doesn't have any groups called binary but oh well it works now!

  14. #14
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    What you specify is not only the group, but also the individual resources name, I think you got those two confused.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

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