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
Printable View
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
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: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);
That's as long as the data in the resource ends with '\0'. Otherwise, you'd need to use:Code:cout << pubData << endl;
Code:for(int i = 0; i < ulLen; i++)
cout << pubData[i];
}
thanks alot man.. works great =)
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.
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.
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?
i just had to use RT_HTML
since it was defined as a HTML resource
doh!
ok man thanks tons again!
To get a module handle under MFC, use AfxGetResourceHandle().
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
You have to insert a user-defined resource.
I did, but I found that the problem comes when the program gets to memcpy.
Are you sure you use the correct resource name? Have you tested the raw pointer for NULL?
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!
What you specify is not only the group, but also the individual resources name, I think you got those two confused.