You can use the LoadString WinAPI like this:
HMODULE hMod = GetModuleHandle(NULL);
char myString[512];
LoadString(hMod, IDS_STRING101, myString, 512);
MessageBox(NULL, myString, "", MB_OK);
IDS_STRING101 has been defined in your .rc file
Question
I am trying to read char pointer/string from resource, and then show it from messagebox. However it seems to be blank and I don't know if I am reading it correctly.
Here's my resources:
And here's the code that I am using to read it:
void main()
{
HGLOBAL G1, G2;
HMODULE hMod = GetModuleHandle(NULL);
G1 = LoadResource(hMod, FindResource(NULL, MAKEINTRESOURCE(RT_RCDATA), "RESOURCE1"));
G2 = LoadResource(hMod, FindResource(NULL, MAKEINTRESOURCE(RT_RCDATA), "RESOURCE2"));
//G1 = LoadResource(NULL, FindResource(NULL, "RCData", "RESOURCE1"));
//G2 = LoadResource(NULL, FindResource(NULL, "RCData", "RESOURCE2"));
MessageBoxA(NULL, (char*)LockResource(G1), (char*)LockResource(G1), MB_OK);
MessageBoxA(NULL, (char*)LockResource(G2), (char*)LockResource(G2), MB_OK);
/*char *strURL;
HMODULE hModule = GetModuleHandle(NULL);
HRSRC hResource = FindResource(hModule, "RESOURCE1", "RCData"); //HRSRC hResource = FindResource(hModule, "RCData", "RESOURCE1");
HGLOBAL hMemory = LoadResource(hModule, hResource);
DWORD dwSize = SizeofResource(hModule, hResource);
LPVOID lpAddress = LockResource(hMemory);
memcpy(strURL, lpAddress, dwSize);
MessageBoxA(0, strURL, strURL, MB_OK);*/
ExitProcess(0);
}
The commented parts are alternatives that I tried for reading it properly. What is going wrong? I know that the RT_RCDATA
is not correct, because in the resources it's clearly "RCDATA"
but then I also tried using just LPCSTR
in quotes, but that didn't help either.
Also, I am not releasing the resource(FreeResource) because this is what MSDN says:
This function is obsolete and is only supported for backward compatibility with 16-bit Windows. For 32-bit Windows applications, it is not necessary to free the resources loaded using LoadResource.
What is going wrong or what am I doing incorrectly?
Edit: Bad tags because apparently I need some kind of reputation to add correct tags for this, makes absolutely no sense to me.
No correct solution
OTHER TIPS
You can use the LoadString WinAPI like this:
HMODULE hMod = GetModuleHandle(NULL);
char myString[512];
LoadString(hMod, IDS_STRING101, myString, 512);
MessageBox(NULL, myString, "", MB_OK);
IDS_STRING101 has been defined in your .rc file