Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / January 2007

Tip: Looking for answers? Try searching our database.

saving data with my .exe

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Paul E - 17 Jan 2007 09:07 GMT
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!
ClayB - 17 Jan 2007 10:22 GMT
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.
Paul E - 17 Jan 2007 15:06 GMT
> Here is a link to a FAQ showing you how the read a bmp file as an
> embedded resource.
[quoted text clipped - 8 lines]
> 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 "";
     }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.