Forward declare a typedef'd structure

I cannot figure out how to forward declare a Windows structure. Definition

typedef struct _CONTEXT { .... } CONTEXT, *PCONTEXT 

I really don't want to pull this heading in, as it is everywhere included.

I tried

struct CONTEXT

and

struct _CONTEXT

no luck (overriding base types with actult struct in winnt.h.

+4
source share
2 answers
 extern "C" { typedef struct _CONTEXT CONTEXT, *PCONTEXT; } 

You need to declare that _CONTEXT is a struct . And declare it as extern "C" to match the external link of windows.h (which is the C header).

However, you do not need to specify a definition for typedef , but if you do, all definitions must comply ( One definition rule ).

EDIT: I also forgot the extern "C".

+9
source

Not a solution, but a workaround:

 // h-file struct MyContext; // forward decl void f(MyContext * pContext); // use pointer //cpp-file #include <windows.h> struct MyContext { CONTEXT cont; }; void f(MyContext * pContext) { CONTEXT * p_win_cont = & pContext->cont; // use p_win_cont // .... } 
+1
source

Source: https://habr.com/ru/post/1303961/


All Articles