I want to add a text file as resource in VC++ 2005. I am not able to find text as option in resource template.
Also once added how can I refer to that file while programming?
That's pretty simple: In your solution, switch to resource view, right click on your RC file, select "Add Resource", click on "Import", select "All files" then open the file you want. You're prompted to type in a custom resource type. Enter "TEXT" for example.
You can now load your custom resource like this:
HRSRC hRes = FindResource(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_TEXT1), _T("TEXT"));
DWORD dwSize = SizeofResource(GetModuleHandle(NULL), hRes);
HGLOBAL hGlob = LoadResource(GetModuleHandle(NULL), hRes);
const BYTE* pData = reinterpret_cast<const BYTE*>(::LockResource(hGlob));
You don't need to unlock or free the resource, so this code can be used exactly as written without any additional calls. The resource will be freed when your program exits.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With