Public Group

# Error RC2143 [solved] -- More rc questions

This topic is 4247 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

1>.\super.rc(2) : error RC2143 : font names must be ordinals
My rc file:
BACKDROP BITMAP DISCARDABLE "E:/VisualCpp/Projects/SuperBrobk/debug/data/backdrop.bmp"
MAINFONT FONT DISCARDABLE "E:/VisualCpp/Projects/SuperBrobk/debug/data/font.ttf"

I'm learning how to work with resource files. I have a simple free Resource Editor, since MSVC++2k5EE doesn't have a rc editor. I tried googling my problem, but they tell me The pointsize field in the FONT statement must be an integer, not a string. I have no clue how I am supposed to fix this.
Edit: I managed to fix it with by adding #define MAINFONT 1
New question: How do I use these resources now??? I can't seem to find any help via google. Just using MAINFONT or BACKDROP doesn't work...

##### Share on other sites
There are a number of Win32 functions you can use to load resources and obtain a handle to the resource that can actually be used. LoadImage is one commonly used example:

// This could, for example, be in response to a WM_PAINT or WM_ERASEBKGND messageHBITMAP backdrop;backdrop = LoadImage( hInstance,                      MAKEINTRESOURCE(BACKDROP),                      IMAGE_BITMAP,                      0, 0,                      LR_DEFAULTCOLOR );// Use the bitmap to paint a backgroundHBRUSH brush = CreatePatternBrush(backdrop);LPRECT rect;GetClientRect(hWnd, rect);FillRect(hDC, rect, brush);

##### Share on other sites
Hmm... I'm not too familiar with the Win32 API, I've been using SDL. Here is a piece of my code, with abviously errors in it:
int loadFiles(){	mbackdrop = loadImage( MAKEINTRESOURCE( BACKDROP ) );	fontl = TTF_OpenFont( MAINFONT, 16 );	fonts = TTF_OpenFont( MAINFONT, 10 );	fontxs = TTF_OpenFont( MAINFONT, 6 );	return 1;}

These are my compilation errors:
1>e:\visualcpp\projects\superbrobk\superbrobk\filestuff.h(8) : error C2065: 'BACKDROP' : undeclared identifier1>e:\visualcpp\projects\superbrobk\superbrobk\filestuff.h(10) : error C2065: 'MAINFONT' : undeclared identifier

I have no clue what I'm doing, since I have no clue what this resource file actually is. I can't find any tutorials that also work with VC++2k5EE

Edit
Here is the loadImage() function, to avoid confusion:
SDL_Surface *loadImage( std::string filename ){	SDL_Surface* loaded_image = NULL; // The image that's loaded	SDL_Surface* optimized_image = NULL; // The optimized image that will be used	loaded_image = IMG_Load( filename.c_str() ); // Load the image using SDL_image	if( loaded_image != NULL ) // If the image loaded	{		optimized_image = SDL_DisplayFormat( loaded_image ); // Create an optimized image		SDL_FreeSurface( loaded_image ); // Free the old image		if( optimized_image != NULL ) // If the image was optimized just fine		{			Uint32 colorkey = SDL_MapRGB( optimized_image->format, 0, 0xFF, 0xFF ); // Map the color key #00FFFF			SDL_SetColorKey( optimized_image, SDL_RLEACCEL | SDL_SRCCOLORKEY, colorkey ); // Set all pixels of color R 0, G 0xFF, B 0xFF to be transparent		}		/* else		{			std::string error = "Failed optimizing:\n" + filename;			MessageBox( NULL, error.c_str(), "Error", MB_ICONEXCLAMATION );		} */	}	else	{		std::string error = "Failed loading:\n" + filename;		MessageBox( NULL, error.c_str(), "Error", MB_ICONEXCLAMATION );	}	return optimized_image;}

##### Share on other sites
You need a resource header file (VS's resource editor by default creates one named "resource.h") that defines your resource identifiers. (e.g., your #define MAINFONT 1) Include this file in both your .rc file, and in any files that need to load your program's resources.

[EDIT: just saw your second code snippet]

What you're trying to do there definitely won't work. That loadImage function expects a string filename, whereas the MAKEINTRESOURCE macro simply gives a string identifier that can be used by Win32 resource loading functions. I haven't used SDL, so I'm not sure what all it provides, but you'd need some way to create an SDL image from the data directly, instead of through a filename.

##### Share on other sites
Thank you, I got a lot further now. These are some source files:

BACKDROP BITMAP DISCARDABLE "E:/VisualCpp/Projects/SuperBrobk/SuperBrobk/data/backdrop.bmp"MAINFONT FONT DISCARDABLE "E:/VisualCpp/Projects/SuperBrobk/SuperBrobk/data/font.ttf"

// **** resource.h ****//     Resources eh//#define BACKDROP 0#define MAINFONT 1

Somehow I get my original error again though, it's really bugging me:
1>Compiling resources...1>.\super.rc(2) : error RC2143 : font names must be ordinals

How am I supposed to fix this?

Edit
How do you mean, it wno't work? It's compiling alright so it seems. I'll see if the program actually works if this little error is solved, otherwise I need a fix for my SDL loadImage() function.

##### Share on other sites
It may compile, but it certainly won't work that way. loadImage is expecting a filename - you're giving it an internal resource identifier.

As for the other problem, I'm not entirely sure. According to this, your FONT statement is correct. It doesn't even say anything about a "pointsize" field, so I'm kinda puzzled. I just tried it myself in an RC file and it seemed to work fine.

##### Share on other sites
It's not necessarily expecting a filename, I just called that string filename. I bet IMG_Load() (the first function that does something) also takes my resource file. I am also puzzled with my compilation error..... I'ma sleep a night over it, thanks for all your help!

##### Share on other sites
I don't think that's likely, since in order to load your bitmap resource it would also need an instance handle, and the function accepts none. Anyway, I looked it up the documentation - unfortunately, the parameter name is not deceptive. [wink]

If there's a way you can construct an SDL image directly from bitmap data, it's possible in Win32 to just get a pointer to the raw data of a resource in your executable.

##### Share on other sites
Hmmm... Google seems to be extremely unhelpful for me when I need help for programming... How do I make a pointer to the raw data of the resource?

Also, the same error persists... I can't seem to fix that font names must be ordinals error...

##### Share on other sites
A little bit of juggling is required to get at the raw resource data. Here's an example that gets a byte array of the data for the resource bitmap specified by the ID macro MY_BITMAP_ID:

    unsigned char* data;    int size;    // Find the resource. Assumes "hInst" is the current instance handle    HRSRC hResource = FindResource(hInst, MAKEINTRESOURCE(MY_BITMAP_ID), RT_BITMAP);    // Get the size, in bytes, of the resource data    size = SizeofResource(hInst, hResource);    // Get a handle to the data    HGLOBAL hGlob = LoadResource(hInst, hResource);    // Get a pointer to the data indicated by the handle    data = (unsigned char*)LockResource(hGlob);

Note that for Windows bitmap files, the 14-byte bitmap file header is stripped when the file is embedded in your executable. You probably don't need the file header, but if you do for some reason, it's pretty easy to construct. You can find information about the Windows bitmap file format here.

As for the font thing: I just did a little quick testing, and I found that the "Font names must be ordinals" error results when you use an undefined identifier macro for your font's ID. Like this:
#include "resource.h"// This will produce a "Font names must be ordinals" error// if "NOTDEFINED_ID" is not defined in resource.hNOTDEFINED_ID        FONT       "res\\my_font_file.ttf"

Make sure that you're including your resource header file in your .rc file, and that the MYFONT symbol is defined in the resource header file.

1. 1
2. 2
Rutin
22
3. 3
4. 4
frob
18
5. 5

• 33
• 13
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
632563
• Total Posts
3007099

×