An external variable is a variable declared in the target process, or in files when used with the Hex Editor. After being declared, they are used the same way as normal variables. External variables are declared using the form “extern <data type> <variable name> = { <string>, <expression> };”. For example:

extern int iValue = { "gamex86.dll", 0x1344C };

This would declare an external variable named iValue at the address 0x1344C bytes after the base address of gamex86.dll. <data type> can be any built-in data type or a custom structure, union, enumeration, or typedef. See Data Types, Typedefs, Structs, Unions, and Enums for information on what is valid in a <data type>. <string> must be a constant literal string. <expression> must resolve to an integer value.

You can use an empty string to indicate that the <expression> is the actual address of the variable in the target process or file. For example:

extern int iValue = { "", 0x0041344C };

This would declare iValue as an int in the target process (or file) at address 0x0041344C.

<data type> follows the same rules as with any other variable declaration, and as such you can define structures and unions at the same time you define the external variable. For example,

extern struct NiftyPuff {
    int iA;
    int iB[32];
    float * pfC;
} e_npPuffster = {
"gamex86.dll", 0x1344C };

would declare an external variable e_npPuffster as type Niftypuff at address [gamex86.dll+0x1344C].

For information on how to use the [module+offset] format, refer to the About Pointers section.

Using the & (address-of) operator on external variables returns the address of the variable as an unsigned long. Be sure to remember that the value returned is an unsigned long and not actually a pointer type. For example:

unsigned long ulThis = &e_npPuffster;


Examples of Usage

After declaring the above external variables, we can use them in the same ways as we can any other variables. Here are some examples:

  • iValue++;
  • int iCopy = iValue;
  • e_npPuffster.iA = iValue;
  • e_npPuffster.iB[iValue] = 3;
  • (*e_npPuffster.pfC) = 3.1415963f;
  • if ( e_npPuffster.iA > iValue ) { e_npPuffster.iA = iValue; }



External functions are not yet supported. External functions will, in the future, allow the user to call functions that exist inside the target process. Like external variables, external functions will be usable in the same manner as normal functions. Internally, however, the parameters passed in the script will be sent to the target process and the return value (if any) will be taken from the target process.

Copyright © 2006 Shawn (L. Spiro) Wilcoxen