Monday, August 25, 2008

Sample LoadResource

Pic 1:
If we want to acess resources then we have to do the following steps

step 1:Add resource like in the pic 1 .
step2 :Type the data in the notepad & paste that in resource like pic 2.

Pic 2:






To acess the resource db we can use this code
CString dbData; dbData.LoadString(IDR_DBDATA1);
HGLOBAL hDB = NULL;
HRSRC hDBRes = FindResource(AfxGetResourceHandle(),MAKEINTRESOURCE(130),"DBDATA");
if (hDBRes==NULL) return;
DWORD size = SizeofResource(AfxGetResourceHandle(),hDBRes);
LPTSTR pRes = NULL;
hDB = LoadResource(AfxGetResourceHandle(),hDBRes);
if (!hDB) return;
pRes = (LPTSTR) (hDB);
FreeResource(hDB);
FreeResource(hDBRes);
CString csTmp = (CString) pRes;

AfxMessageBox(csTmp);

No comments: