Solved

Is it possible to embed a text file into Visual C++ static library

Posted on 2009-05-04
1
1,528 Views
Last Modified: 2013-12-14
I'm usual Visual Studio 2005.

When compiling a Visual C++ executableI can embed a text file when compiling by setting the project properties as:
     Configuration properties -> General -> CLR Support->CLR Support enabled
     Link -> Input -> Embed managed Resource -> name of text file added

If I am generating a Visual C++ static library, can I also embed a text file in it when compiling?  If yes, how do I do it?  The properties for a static library project allows me to enable CLR support but I can't find any property such as "Embed Managed Resource" that allows me to include the text file name that I want to embed.
0
Comment
Question by:khrispy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 2

Accepted Solution

by:
Gregdo earned 200 total points
ID: 24329251
Yes, it is possible to embed a text file in an unmanaged DLL or EXE.  You do it as a resource.  Go to the resource view. Right click on your resource file and choose Add Resource..., Import..., select the file that you want to embed and hit Open, enter a name for the custom resource type (e.g. TEXT).  Hit OK.

You now have a text resource in your project.  If you check the code in the .RC file, you will see that the actual file is not stored in the RC file, just a link to the actual file.  At compile time, the actual file will be copied into the EXE or DLL that you build.

The code below shows how to read the text file from the program resources.  This code doesn't do any pointer checking, so you might want to add some in your own code.
const HINSTANCE hInst = AfxFindResourceHandle(MAKEINTRESOURCE(IDR_TEXT1), TEXT("TEXT"));
 
const HRSRC hResDll = FindResource(hInst, MAKEINTRESOURCE(IDR_TEXT1), TEXT("TEXT"));
 
// load
const HGLOBAL hSQL = LoadResource(hInst, hResDll);
 
// lock
LPCTSTR pszSQL = (LPCTSTR)LockResource(hSQL);
const DWORD dwResourceSize = SizeofResource(hInst, hResDll);
 
// You now have a pointer to the embeded TEXT file and it's length so you can copy it somewhere
 
//unlock
UnlockResource(hSQL);

Open in new window

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question