Adding methods to an MFC/ATL ActiveX Control project

How do you add your own methods to an MFC/ATL ActiveX Control project Either I get compiling errors or the ASP page claims that the "object doesn't support the property or method". I've used this script (see below) for other ActiveX controls I've worked with and it has worked, and still works for them. I want to use the code automatically generated when adding a new MFC ActiveX Control project because I want to be able to write an ActiveX component for a Windows CE device. And there is a project type for VC++ called MFC Smart Device ActiveX Control. When I deploy the MFC Smart Device ActiveX Control to the Windows CE device, register it and go to the page with the script below, I get an error on the second line ( str=obj.Question() ). If I comment out all VBScript but the "CreateObject"-line I get no errors, and the ASP page works.

<%
Set obj=Server.CreateObject("AXTEST.AxTestCtrl.1")
str=obj.Question() ' Here is where the error occurs
%>

<html>
<title>
Test ActiveX Server Component
</title>
<body>
<span style="{font-family:Arial}">
<%=str%>
</span>
</body>
</html>

P.S. For WinCE Set obj=CreateObject("AXTEST.AxTestCtrl.1") D.S.



Answer this question

Adding methods to an MFC/ATL ActiveX Control project

  • Nick.Muguira

    I've never used the for smart device template and it might not be the same, but this might point you in the right direction -

    That error usually means that it couldn't find the method on the dispatch interface. You need to add your methods to the control class's dispatch table: you need to make sure

    if you're using an MFC COleControl

    • you have a DISP_FUNCTION_ID definition for Question in the BEGIN_DISPATCH_MAP section in the control implementation
    • the method is on the dispatch interface in the .idl
      (I'm less sure that this'll make a difference - would ASP need the TLB - but it's the correct thing to do and it can't hurt)

    if you're using an ATL control

    • you've added a new interface for your class to the .idl which inherits from IDispatch; add the Question method (you might need a numeric dispatch ID property "[id(123)]" - I can't remember if it's mandatory for scriptable interfaces) and make sure your coclass implements this interface
    • your control implementation inherits from the IDispatchImpl template (as well as the usual CComCoClass etc.) and you have a COM_INTERFACE_ENTRY2(IDispatch, IYourInterface) in the BEGIN_COM_MAP


  • SK_Rajdev

    I'm using your advice for the MFC version. But I get this error:

    ##########################################################################
    HTTP 500.100 - Internal server error - ASP-error

    Error type:
    (0x8000FFFF)
    irrevocable error
    /tabletestcpp.asp, line 3

    Page:
    GET /tabletestcpp.asp
    ##########################################################################

    In AxTestTemplateCtrl1.h I changed:
    afx_msg
    int AboutBox(); // Actually AboutBox returned void previously
    to
    afx_msg
    int AboutBox();
    int
    Question();
    ##########################################################################

    In Resource.h I changed:
    #define IDD_ABOUTBOX_AXTEMPLATETEST1 1
    to
    #define IDD_ABOUTBOX_AXTEMPLATETEST1 1
    #define IDD_QUESTION_AXTEMPLATETEST1 1
    ##########################################################################

    In AXTemplate.idl I changed:

    [id(DISPID_ABOUTBOX)] int AboutBox();

    to

    [id(DISPID_ABOUTBOX)] int AboutBox();

    [id(DISPID_ QUESTION)] int Question();

    A major part of the file:

    #define DISPID_QUESTION (-804)

    [ uuid(DF4F7FC6-E01D-4FFE-8EC5-5916BEE8E034), version(1.0),

    helpfile("AxTemplateTest1.hlp"),

    helpstring("AxTemplateTest1 ActiveX Control module"),

    control ]

    library AxTemplateTest1Lib

    {

    importlib(STDOLE_TLB);

    // Primary dispatch interface for CAxTemplateTest1Ctrl

    [ uuid(F009FE68-00BB-40AF-822B-09498C1D7961),

    helpstring("Dispatch interface for AxTemplateTest1 Control")]

    dispinterface _DAxTemplateTest1

    {

    properties:

    methods:

    [id(DISPID_ABOUTBOX)] int AboutBox();

    [id(DISPID_QUESTION)] int Question();

    };

    // Event dispatch interface for CAxTemplateTest1Ctrl

    [ uuid(FF7AEE09-2089-4978-B6DB-C94EB843A932),

    helpstring("Event interface for AxTemplateTest1 Control") ]

    dispinterface _DAxTemplateTest1Events

    {

    properties:

    // Event interface has no properties

    methods:

    };

    // Class information for CAxTemplateTest1Ctrl

    [ uuid(789AC977-B160-41BE-902A-1D032D722E89),

    helpstring("AxTemplateTest1 Control"), control ]

    coclass AxTemplateTest1

    {

    [default] dispinterface _DAxTemplateTest1;

    [default, source] dispinterface _DAxTemplateTest1Events;

    };

    };
    ##########################################################################

    In AxTestTemplateCtrl1.h I changed:


    // Dispatch map

    #define DISPID_QUESTION (-804)

    BEGIN_DISPATCH_MAP(CAxTemplateTest1Ctrl, COleControl)

    DISP_FUNCTION_ID(CAxTemplateTest1Ctrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_I4, VTS_NONE)

    //DISP_FUNCTION_ID( theClass, pszName, dispid, pfnMember, vtRetVal, vtsParams )

    END_DISPATCH_MAP()


    to

    // Dispatch map

    #define DISPID_QUESTION (-804)

    BEGIN_DISPATCH_MAP(CAxTemplateTest1Ctrl, COleControl)

    DISP_FUNCTION_ID(CAxTemplateTest1Ctrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_I4, VTS_NONE)

    DISP_FUNCTION_ID(CAxTemplateTest1Ctrl, "Question", DISPID_QUESTION, Question, VT_I4, VTS_NONE)

    //DISP_FUNCTION_ID( theClass, pszName, dispid, pfnMember, vtRetVal, vtsParams )

    END_DISPATCH_MAP()
    ##########################################################################

    In AxTestTemplateCtrl1.h I changed:


    // CAxTemplateTest1Ctrl::AboutBox - Display an "About" box to the user

    int CAxTemplateTest1Ctrl::AboutBox()

    {

    CDialog dlgAbout(IDD_ABOUTBOX_AXTEMPLATETEST1);

    dlgAbout.DoModal();

    }

    to

    // CAxTemplateTest1Ctrl::AboutBox - Display an "About" box to the user

    int CAxTemplateTest1Ctrl::AboutBox()

    {

    return 321;

    CDialog dlgAbout(IDD_ABOUTBOX_AXTEMPLATETEST1);

    dlgAbout.DoModal();

    }

    int CAxTemplateTest1Ctrl::Question()

    {

    return 321;
    }
    ##########################################################################


  • Adding methods to an MFC/ATL ActiveX Control project