|
-
Dec 16th, 2000, 02:38 PM
#1
Thread Starter
Lively Member
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
-
Dec 16th, 2000, 04:56 PM
#2
Monday Morning Lunatic
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
-
Dec 16th, 2000, 05:14 PM
#3
Thread Starter
Lively Member
Thanks!
thanks alot man.. works great =)
-
Dec 16th, 2000, 05:20 PM
#4
Thread Starter
Lively Member
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.
-
Dec 16th, 2000, 05:37 PM
#5
Thread Starter
Lively Member
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.
-
Dec 16th, 2000, 05:44 PM
#6
Thread Starter
Lively Member
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?
-
Dec 16th, 2000, 05:46 PM
#7
Thread Starter
Lively Member
It works!
i just had to use RT_HTML
since it was defined as a HTML resource
doh!
ok man thanks tons again!
-
Dec 16th, 2000, 06:37 PM
#8
Monday Morning Lunatic
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
-
Sep 25th, 2002, 03:49 AM
#9
Hyperactive Member
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
-
Sep 25th, 2002, 08:03 AM
#10
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.
-
Sep 25th, 2002, 03:39 PM
#11
Hyperactive Member
I did, but I found that the problem comes when the program gets to memcpy.
-
Sep 26th, 2002, 02:59 AM
#12
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.
-
Sep 26th, 2002, 03:38 AM
#13
Hyperactive Member
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!
-
Sep 26th, 2002, 11:27 AM
#14
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|