I’m creating a DLL using Visual C++ Express, and when declaring
extern ValveInterfaces* VIFace inside Required.h, the compiler is telling me that ValveInterfaces isn’t defined. (I want to expose VIFace to any file including Required.h)
Here is the structure of my files:
DLLMain.cpp
#include "Required.h" //required header files, such as Windows.h and the SDK
ValveInterfaces* VIFace;
//the rest of the file
Required.h
#pragma once
//include Windows.h, and the SDK
#include "ValveInterfaces.h"
extern ValveInterfaces* VIFace; //this line errors
ValveInterfaces.h
#pragma once
#ifndef _VALVEINTERFACES_H_
#define _VALVEINTERFACES_H_
#include "Required.h"
class ValveInterfaces
{
public:
ValveInterfaces(void);
~ValveInterfaces(void);
static CreateInterfaceFn CaptureFactory(char *pszFactoryModule);
static void* CaptureInterface(CreateInterfaceFn fn, char * pszInterfaceName);
//globals
IBaseClientDLL* gClient;
IVEngineClient* gEngine;
};
#endif
Screenshot of errors:
https://i.stack.imgur.com/1ZUph.png
That first error:
is a dead giveaway that the
ValveInterfacestype has not been defined at the point where you first try to use it.This almost invariably occurs because the type of
ValveInterfacesis unknown. It’s a little hard to tell since you’ve cut out huge swathes ofValveInterfaces.hbut, even if it’s defined there, it could be a weird combination of#pragma onceand the apparent misplacement of the_REQUIRED_Hinclude guards (they would normally be inrequired.h) which is causing you grief.