Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Using Resources in the VCF

, 19 Apr 2006
An article on adding and using resources to your application using the VCF.
appresourcesex.zip
AppResources
AppResources.bkl
AppResources.dsp
AppResources.positions
AppResources_cb.cbp
AppResources_icl7.dsp
GNUmakefile
makefile.bcc
makefile.gcc
makefile.vc
Resources
brushed-metal.bmp
de_DE
brushed-metal.bmp
en_US
brushed-metal.bmp
it_IT
brushed-metal.bmp
resourcesex.zip
Resources
GNUmakefile
logo.png
makefile.bcc
makefile.gcc
makefile.vc
Resources
MyData.dat
Resources.strings
Resources.bkl
Resources.dsp
Resources.xcodeproj
Resources_cb.cbp
Resources_icl7.dsp
////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

Share

About the Author

Jim Crafton
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.

| Advertise | Privacy | Mobile
Web04 | 2.8.140814.1 | Last Updated 19 Apr 2006
Article Copyright 2006 by Jim Crafton
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid