tags:

views:

310

answers:

1

I'm creating an ActiveX control that will be used in web pages to query the current installed version of a 3rd party software on the client machine. The control only needs to expose a single method - GetVersion - that returns the version as an integer. I'm very inexperienced with ActiveX, and I'm having problems with something as simple as correctly returning values from methods. If i use the following declaration in the IDL:

[id(1)] void GetVersion();

Paired with the following implementation:

BEGIN_DISPATCH_MAP(CDetectorCtrl, COleControl)
    DISP_FUNCTION_ID(CDetectorCtrl, "GetVersion", 1, GetVersion, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()

void CDetectorCtrl::GetVersion()
{
    MessageBox(L"Test");
}

I can invoke the method from HTML and see my MessageBox just fine.

But if I change the definition/code to:

[id(1)] int GetVersion();

and

BEGIN_DISPATCH_MAP(CDetectorCtrl, COleControl)
    DISP_FUNCTION_ID(CDetectorCtrl, "GetVersion", 1, GetVersion, VT_INT, VTS_NONE)
END_DISPATCH_MAP()

int CDetectorCtrl::GetVersion()
{
    MessageBox(L"Test");
    return 1337;
}

I get a crash when I invoke the method from HTML.

A: 

Asked and answered...

The problem appeared to a missing AFX_MANAGE_STATE in the method itself:

LONG CDetectorCtrl::GetVersion(void)
{
    AFX_MANAGE_STATE(AfxGetStaticModuleState());
    return 1337;
}
korona