Here are the steps I took to add a text file as a resource: 1. Right click project, add New Item 2. Choose text file, click add 3. Go to project properties, configuration properties->Linker->Input->Embed Managed Resource File 4. I then added my text file "items.txt in that textbox
Then in my .rc file, I put the following code:
#include "resource.h"
IDR_DATA1 TEXTFILE "Items.txt"
In my resource.h file, I put:
#define TEXTFILE 256
#define IDR_DATA1 255
In my form1.cpp method:
std::string result;
char* data = NULL;
HINSTANCE hInst = GetModuleHandle(NULL);
HRSRC hRes = FindResource(hInst, MAKEINTRESOURCE(IDR_DATA1), MAKEINTRESOURCE(TEXTFILE));
if (NULL != hRes)
{
HGLOBAL hData = LoadResource(hInst, hRes);
if (hData)
{
DWORD dataSize = SizeofResource(hInst, hRes);
data = (char*)LockResource(hData);
}
else
{
MessageBox::Show("hData is null");
return "";
}
char* pkcSearchResult = strstr(data, "2000000");
if (pkcSearchResult != NULL)
MessageBox::Show(gcnew String(pkcSearchResult));
}
else
MessageBox::Show("hRes is null");
return result;
I keep getting hRes is null no matter what, for some reason FindResource is not finding Items.txt even though I added it as a resource using the steps above, anyone know why FindResource() isn't working? Btw it compiles with no errors and the above code is in a method that is supposed to return the line of text that contains "2000000" (which I'm changed for testing purposes)