我做了一个activex 控件,想自定义一个结构通过接口参数传给控件,问如何来做??(问题解决马上给分)

解决方案 »

  1.   


    import "oaidl.idl";
    import "ocidl.idl";
    typedef 
    [uuid(D8B3861A-74C6-11d2-A0D6-00C04FB17CDB)]
    struct StudentStruct
    {
      VARIANT_BOOL   graduate;
      short grade;
      BSTR name;
    }StudentStruct; [
    object,
    uuid(D9C28B00-2D5E-4D2A-885F-DBB7F7DA98E3),
    dual,
    helpstring("ITran Interface"),
    pointer_default(unique)
    ]
    interface ITran : IDispatch
    {
    [propput, id(1), helpstring("property Zero")] HRESULT Zero([in] long newVal);
    [propget, id(2), helpstring("property ID")] HRESULT ID([out, retval] long *pVal);
    [propput, id(2), helpstring("property ID")] HRESULT ID([in] long newVal);
    [id(3), helpstring("method GetStudent")] HRESULT GetStudent([in, out]StudentStruct* pst);
    [id(4), helpstring("method GetStringArray")] HRESULT GetStringArray([in, out] SAFEARRAY(BSTR) *psa);
    };[
    uuid(AB783E87-C2D7-4DB8-B6A3-45EDEE0F8EBF),
    version(1.0),
    helpstring("Trans 1.0 Type Library")
    ]
    library TRANSLib
    {
    importlib("stdole32.tlb");
    importlib("stdole2.tlb"); [
    uuid(34F5E700-2758-4C94-A2A3-616E6DC372BA),
    helpstring("_ITranEvents Interface")
    ]
    dispinterface _ITranEvents
    {
    properties:
    methods:
    [id(1), helpstring("method ZeroChanged")] HRESULT ZeroChanged(long psid, VARIANT *psa);
    }; [
    uuid(449AC010-5024-4BDD-891B-AB0CBB0EB827),
    helpstring("Tran Class")
    ]
    coclass Tran
    {
    [default] interface ITran;
    [default, source] dispinterface _ITranEvents;
    };
    };
      

  2.   

    我在我的odl文件中加入了
    import "oaidl.idl";
    import "ocidl.idl";
    typedef 
    [uuid(D8B3861A-74C6-11d2-A0D6-00C04FB17CDB)]
    struct StudentStruct
    {
      VARIANT_BOOL   graduate;
      short grade;
      BSTR name;
    }StudentStruct;
    可是编译出错
    statements outside library block are illegal in mktyplib compatability mode : [ ]
    这该如何解决?
      

  3.   

    to wei97081116(韦小宝) 你是在idl 文件中添加的上述代码吗?idl文件我为什我找不着(路径下没有)?我用com/ole object viewer 可以浏览但不能更改。如果不是在idl中添加的,我应该把它加在那?
      

  4.   

    typedef 
    [uuid(D8B3861A-74C6-11d2-A0D6-00C04FB17CDB)]
    struct StudentStruct
    {
      VARIANT_BOOL   graduate;
      short grade;
      BSTR name;
    }StudentStruct;
      

  5.   

    你看看这篇文章
    http://comcamp.myrice.com/techarticles/com/0007.htm
      

  6.   

    我的控件是用Class wizard做的,还是有问题,在
    BEGIN_DISPATCH_MAP(CStructreturnCtrl, COleControl)
    //{{AFX_DISPATCH_MAP(CStructreturnCtrl)
    DISP_FUNCTION(CStructreturnCtrl, "GetInfofromocx",  etInfofromocx, StudentStruct, VTS_BOOL)
    //}}AFX_DISPATCH_MAP
    DISP_FUNCTION_ID(CStructreturnCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
    END_DISPATCH_MAP()
             我无法处理以下语句
    DISP_FUNCTION(CStructreturnCtrl, "GetInfofromocx",  etInfofromocx, StudentStruct, VTS_BOOL)有问题??