saving data with my .exe

P

Paul E

I have some data that I want to save inside my .exe instead of
delivering it as separate files. When I was using MFC, I would create a
custom resource in my .RC file, then use FindResource and LoadResource.
What is the equivolent in .NET, or is there another way to achieve my
goal?

I created a custom resource in my app.rc file, just like I would have
in MFC, but I have no idea how to do anything with it. What is the call
to get that resource in a variable I can see?

In other words, I'd like the equivolent of this routine:

CString PutResourceInString(HINSTANCE hInstance, const TCHAR*
szSection, UINT uiResource)
{
HRSRC hFound =
::FindResource(hInstance,MAKEINTRESOURCE(uiResource),TEXT(szSection));
HGLOBAL hRes = ::LoadResource(hInstance, hFound);
int iSize = ::SizeofResource(hInstance, hFound);
LPVOID lpBuff = ::LockResource(hRes);
CString csRet;
char* psz = csRet.GetBuffer(iSize+1);
memcpy(psz, lpBuff, iSize);
psz[iSize] = '\0';
csRet.ReleaseBuffer();
::UnlockResource(hRes);
::FreeResource(hRes);
csRet.Replace("\r\n", "\n");
return csRet;
}

Thanks!
 
P

Paul E

ClayB said:
Here is a link to a FAQ showing you how the read a bmp file as an
embedded resource.

http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c56c.aspx#q649q

To include an embedded resource file, add the file to your project and
make sure in its property grid, the file's Build Action is set to
Embedded Resource.

====================
Clay Burch
Syncfusion, Inc.

Thanks! That looks like what I'm trying to do, but I'm not sure how to
translate the instructions to my situation. First, I'm using MSVC 8.0
and C++.

In Solution Explorer, I right-clicked on "Resource Files",
Add->Existing Item, and loaded the file in (it has the extension
".txt"). I don't understand how to set the "Build Action". I right
clicked on the file, then went to Properties, and I see:

General
Excluded From Build: No
Tool: Custom Build Tool
Custom Build Step
Command Line:
Description: Performing Custom Build Step
Output:
Additional Dependencies:

Where is the "Build Action"?

---

Second, I modified the function mentioned in the link to the following,
but I'm pretty sure it's not quite right. I'm not sure about the
strResourceName, and I'm not sure how to get the resource out of strm
and into a string.

private: String^ ReadResourceToString(String^ strResourceName)
{
// Root is the item in the RootNamespace=
// subfolders should be the folder names if any, inside which the
file is added. If the file was added to the top level, you don't have
to specify anything here.
strResourceName = "Root.Resource Files." + strResourceName;
try
{
System::IO::Stream^ strm =
GetType()->Assembly->GetManifestResourceStream(strResourceName);
String^ strRet = gcnew String(strm->ToString());
return strRet;
}
catch(Exception^ e)
{
MessageBox::Show(e->Message);
}
return "";
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top