Game Development Community

TGE ActiveX Event problems

by Neil Marshall · in Torque Game Engine · 03/31/2006 (10:32 am) · 2 replies

I'm working on the activeX version of TGE tdn.garagegames.com/wiki/TGE/Code/How_to_make_torque_a_plugin and I'm having some problems with ActiveX and was wondering if there are any developers here who would know how to get around this problem.

The version on the above web site handles the WM_INITDIALOG event and then forwards it into the WindowProc function in WinWindow.cc. Now this works, but there are some problems. Mainly the WM_DESTROY event never seems to get handled properly. What I suspect is happening is the Torque WM_DESTROY function is handelling it and then not passing the event on to IE to finish the close window process.

I gave up trying to fix that method and decided to try to move the events out of winwindow.cc and into ax3DPlugin.h where all of the ActiveX events are "supposed" to be handled.

BEGIN_MSG_MAP(Cax3DPlugin)
   MESSAGE_HANDLER(WM_INITDIALOG, OnCreate)
   MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
   MESSAGE_HANDLER(WM_CLOSE, OnClose)
   MESSAGE_HANDLER(WM_TORQUEDRAW, OnDraw)
   MESSAGE_HANDLER(WM_ACTIVATEAPP, OnActivateApp)
   MESSAGE_HANDLER(WM_POWERBROADCAST, OnPowerBroadcast)
   MESSAGE_HANDLER(WM_SYSCOMMAND, OnSysCommand)
   MESSAGE_HANDLER(WM_ACTIVATE, OnActivate)
etc, etc...

The problem I'm having here is the functions try to use the static variables in winWindow.cc and I can't get it to compile and link.

static BYTE keyboardState[256];
static bool mouseButtonState[3];
static bool capsLockDown = false;
static S32 modifierKeys = 0;
static bool windowActive = true;
static Point2I lastCursorPos(0,0);
static Point2I windowSize;
static HANDLE gMutexHandle = NULL;
static bool sgDoubleByteEnabled = false;

I've tried the extern command:

extern bool mouseButtonState[3];
extern S32 modifierKeys;
extern bool windowActive;

but that gives me these errors:

ax3DPlugin.obj : error LNK2019: unresolved external symbol "void __cdecl mouseButtonEvent(int,int)" (?mouseButtonEvent@@YAXHH@Z) referenced in function "public: long __thiscall Cax3DPlugin::OnActivate(unsigned int,unsigned int,long,int &)" (?OnActivate@Cax3DPlugin@@QAEJIIJAAH@Z)
ax3DPlugin.obj : error LNK2001: unresolved external symbol "bool * mouseButtonState" (?mouseButtonState@@3PA_NA)
ax3DPlugin.obj : error LNK2001: unresolved external symbol "bool windowNotActive" (?windowNotActive@@3_NA)
ax3DPlugin.obj : error LNK2019: unresolved external symbol "void __cdecl setMouseClipping(void)" (?setMouseClipping@@YAXXZ) referenced in function "public: long __thiscall Cax3DPlugin::OnActivate(unsigned int,unsigned int,long,int &)" (?OnActivate@Cax3DPlugin@@QAEJIIJAAH@Z)
ax3DPlugin.obj : error LNK2001: unresolved external symbol "bool windowActive" (?windowActive@@3_NA)

and I can't seem to get around it. Does anyone know how I can handle these events properly? Ideally I would like to keep WindowProc handeling the events so that the plugins never get out of sync with the main TGE branch, but I can't figure out how to pass the event on as though it wasn't handeled.

#1
03/31/2006 (11:44 am)
Neil, you can't declare static variables as external. You can solve this problem a few ways. The simplest would be to simply remove the static keyword from the variable declaration, and just make them normal variables.

If you need them to be static still, then the best way to access them would be through accessor functions. IE, you would have the following in your winWindow.cc file:
static BYTE keyboardState[256];
static bool mouseButtonState[3];
static bool capsLockDown = false;
...
BYTE *getKeyboardState()
{
	return keyboardState;
}

bool *getMouseButtonState()
{
	return mouseButtonState;
}

bool &getCapsLockDown()
{
	return capsLockDown;
}

Then in ax3DPlugin.h you'd add these lines:
extern char *getKeyboardState();
extern bool *getMouseButtonState();
extern bool &getCapsLockDown();

Then just make sure you access those variable using these accessor functions. Ie, 'getCapsLockDown() = false;', etc.
#2
03/31/2006 (11:49 am)
I'll give that a shot. Thanks.