An Overview of Resources

In its simplest sense, a resource is a variable stored in a file for later use. A resource has three levels of identification:

Resources are the entities that MicroStation uses to define the way things are physically presented on the screen, represent static information and provide functional extensions. MicroStation itself, the core product, is a large, natively compiled and linked program. It contains virtually no static text definitions, no dialog box or item definitions, no information on how the interface is to look visually, and only some additional code beyond the basic functionality provided in versions of MicroStation prior to release 4.0.

All MicroStation versions since 4.0 (3.5 on the Macintosh) store GUI related information in resource files. During execution, MicroStation refers to the resource files for information on user preferences, how and where to display dialog items, and many other aspects of its behavior. Resource files provide an efficient way to extend MicroStation's functionality. The following files are compiled into binary resources and referenced by MicroStation via the MicroStation resource manager:

Resource-based subsystems in MicroStation include:

Benefits from using resources

Several benefits can be gained from using resources:

Application Resources

Like MicroStation, MDL applications use resources to define text strings command tables.– In addition to these standard resources, applications can define their own application-specific resources for whatever purposes the application needs.

General Resource Definition Format

The syntax for resource source .r files is modeled after the syntax for data initialization in C. Specifying resource types and initializing them with data is the same as specifying typedef and declaring and initializing variables in C. The differences from standard C are listed below, and examples of some concepts are in the following "Examples" section.

This information is stored in the resource file, and MicroStation's resource manager uses it when locating resources. The syntax for a resourceclass statement is as follows:

resourceclass <type-name> <resource class>

<type-name> must have been previously declared in a typedef statement.

<resource class> is a constant integer expression. The expression is evaluated at compile time and treated as an unsigned long.

typedef struct
{
char str[6];
} SimpleString;
resourceclass SimpleString SMPL_STR_TYPE_ID;
Also, suppose the declaration of the resource was as follows:
SimpleString MY_RES_ID = {"abcdefg"};

Thus, the string would get truncated to fit in six characters (including the trailing NULL byte) as abcde\0.

Resource Examples

The following sub-sections demonstrate the aforementioned differences between resource and C syntax.

Resource classes and resource IDs

Here is an example of how resource classes and resource IDs are used:

#define TWO_INT_TYPE 0x5
#define MY_RESOURCE 0x200
#define YOUR_RESOURCE 0x300
typedef struct
{
int a;
int b;
} TwoIntStruct;
resourceclass TwoIntStruct TWO_INT_TYPE;
TwoIntStruct MY_RESOURCE = {3, 4},
YOUR_RESOURCE = {6, 5};

An MDL application can access the structure at runtime by calling one of the resource management built-in functions specifying resourceclass TWO_INT_TYPE and resourceID MY_RESOURCE or YOUR_RESOURCE.

Variable sized arrays

The testStruct structure, shown below, has an undefined length because of its c structure member. This example shows how each instance of testStruct will look, but the number of members in the c array will vary with each resource of type testStruct declared in the file.

Source file

typedef struct testStruct // typedef structure containing
{ // an array of undefined size
char a[3];
char b[3];
char c[];
} testStruct;
resourceclass testStruct 'abcs'; // Assign 0x61626373 ID to
// the "testStruct" structure
testStruct 1 = {"aaa", "bbb", "ccc"};// Declare an instance of a
//resource with RSCID of 1

Dump of compiled resource

resourceclass = 0x61626373 ('abcs') - 1 resources
resourceId = (1, 0x00000001) Size / Pos = (14 / 340)
000000 61 61 61 62 62 62 04 00 00 00 63 63 63 00 | aaabbb.ccc.
\ / |
length NULL terminator

The[] signifies a variable - length array.When a resource of type TestStruct is declared later in the file, a hidden long value is inserted after member b and before member c indicating the number of iterations of member c in TestStruct.

Immediate members / Fillers

The following example illustrates the use of fillers :

typedef struct fourIntStruct
{
int 0[3]; // 3 zero-filled ints
int b;
} FourInts;
resourceclass FourInts FOUR_INTS_TYPE_ID;

A subsequent resource declaration would need only to provide an initializer for the b member since the first structure member(array of three ints) is already initialized :

FourInts MY_RESOURCE_ID = {1}; // 0,0,0,1

Copyright © 2017 Bentley Systems, Incorporated. All rights reserved.