Laurie Stearn
Laurie Stearn

Reputation: 999

Typedef Variables for Global Use?

Suppose we have source file wide this decl:

typedef VOID ( NTAPI *my_RtlInitUnicodeString ) (
PUNICODE_STRING DestinationString,
PCWSTR SourceString
);
my_RtlInitUnicodeString rtlInitUnicodeString;
//static has same effect

Any attempt to use rtlInitUnicodeString in the source file internal functions requires "redefining" like this:

my_RtlInitUnicodeString rtlInitUnicodeString ....

Clicking on "definition" [VS] for rtlInitUnicodeString used in any source file internal functions always takes us to its home: Winternl.h instead of the source file wide decl. Is this a compiler limitation or is there another way rtlInitUnicodeString can be made available for all and sundry?

Upvotes: 0

Views: 1028

Answers (2)

Laurie Stearn
Laurie Stearn

Reputation: 999

The answer was not obvious until the compilation error was noted:

error C2659: '=' : function as left operand

Something got twisted in knots. But an explanation of why

my_RtlInitUnicodeString RtlInitUnicodeString = (my_RtlInitUnicodeString) GetProcAddress(hdlNtCreateFile, initUnicodeFnString); 

works in source-file internal functions but not

RtlInitUnicodeString = (my_RtlInitUnicodeString) GetProcAddress(hdlNtCreateFile, initUnicodeFnString); 

requires an understanding beyond my ken.

Upvotes: 0

David Grayson
David Grayson

Reputation: 87486

You should not have more than one definition of the variable in your program. To use a variable from different compilation units, each compilation unit using it should include a header file with a declaration of the variable. A declaration should start with the keyword "extern". This is just how global variables work in C, it has nothing to do with typedefs.

Upvotes: 1

Related Questions