Click here to Skip to main content
15,886,110 members
Articles / Desktop Programming / MFC

Using Resources in the VCF

Rate me:
Please Sign up or sign in to vote.
4.25/5 (6 votes)
19 Apr 200611 min read 38.7K   444   12  
An article on adding and using resources to your application using the VCF.
////Resources.cpp

#include "vcf/FoundationKit/FoundationKit.h"

using namespace VCF;


/**
This simple program will demonstrate how to load up resources.
We will use bundle based resources for this test, and .rc based 
resources for the Win32 version.
*/

#define IDS_STRING1	"1"

int main( int argc, char** argv ){

	FoundationKit::init( argc, argv );


	//retrieves the System's resource bundle for this application
	ResourceBundle* resBundle = System::getResourceBundle();

	//retreive a string resource
	String val = resBundle->getString( IDS_STRING1 );

	System::println( "IDS_STRING1: " + val );
	
	val = resBundle->getString( "HELLO_STR" );

	System::println( "HELLO_STR: " + val );

	val = resBundle->getString( "TEST" );

	System::println( "TEST: " + val );

	val = resBundle->getString( "goodbye_str" );

	System::println( "goodbye_str: " + val );


	/**
	This retreives a resource in the form of a raw data buffer.
	The caller is responsible for freeing the resources
	instance if one is returned
	*/

	Resource* res = resBundle->getResource( "MyData.dat" );
	if ( NULL == res ) {
		System::println( "Failed to find resource!" );
	}
	else {
		System::println( "Found resource " + res->getName() + 
							" size in bytes: " + StringUtils::toString(res->getDataSize()) +
							" buffer: " + Format( "%p") % res->getData() );

		res->free();
	}

	/**
	This will extract a resource from the exe
	*/
	res = resBundle->getResource( "logo_png" );
	if ( NULL == res ) {
		System::println( "Failed to find resource!" );
	}
	else {
		System::println( "Found resource " + res->getName() + 
							" size in bytes: " + StringUtils::toString(res->getDataSize()) +
							" buffer: " + Format( "%p" ) % res->getData() );

		res->free();
	}


	/**
	Get program information about the program from either the 
	Win32 RT_VERSION res type, or, if the file exists, the Info.xml (or Info.plist)
	meta-data files.
	The caller is responsible for releasing the ProgramInfo instance
	*/
	ProgramInfo* info = resBundle->getProgramInfo();
	if ( NULL == info ) {
		System::println( "Sorry, no program information was found." );
	}
	else {
		System::println( "Program information:" );

		System::println( info->getProgramName() );
		System::println( info->getProgramVersion() );
		System::println( info->getAuthor() );
		System::println( info->getCompany() );
		System::println( info->getDescription() );		


		info->free();
	}

	FoundationKit::terminate();
	return 0;
}


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior)
United States United States
Currently working on the Visual Component Framework, a really cool C++ framework. Currently the VCF has millions upon millions upon billions of Users. If I make anymore money from it I'll have to buy my own country.

Comments and Discussions