DISPID ---- Identifies the method or property to be invoked. This value is usually supplied by Component Gallery.

解决方案 »

  1.   

    The following dispatch identifiers (DISPIDs) have special meaning.DISPID Description 
    DISPID_VALUE The default member for the object. This property or method is invoked when an ActiveX client specifies the object name without a property or method. 
    DISPID_NEWENUM The _NewEnum property. This special, restricted property is required for collection objects. It returns an enumerator object that supports IEnumVARIANT, and should have the restricted attribute specified in Object Description Language. 
    DISPID_EVALUATE The Evaluate method. This method is implicitly invoked when the ActiveX client encloses the arguments in square brackets. For example, the following two lines are equivalent:
    x.[A1:C1].value = 10
    x.Evaluate("A1:C1").value = 10The Evaluate method has the DISPID DISPID_EVALUATE.
     
    DISPID_PROPERTYPUT The parameter that receives the value of an assignment in a PROPERTYPUT. 
    DISPID_CONSTRUCTOR The C++ constructor function for the object. 
    DISPID_DESTRUCTOR The C++ destructor function for the object. 
    DISPID_UNKNOWN The value returned by IDispatch::GetIDsOfNames to indicate that a member or parameter name was not found. 
      

  2.   

    如果你在加入com对象,MFC没用classwizard为你封装的话,就用OLE/COM Object Viewer工具找到你要就入的com对象,里面提供的信息足够你了解dispid
      

  3.   

    你要是插入com时连set、get函数都有了,说明classwizard已经为你代劳了,就不必那么费心了
      

  4.   

    多谢,我找到了,我自己写了个activex控件,可是属性的设置总是不能保存,程序一运行,涉及时候设的属性就不见了,后来看书发现所有的属性的在set函数里面都用到了这个函数,不知道是不是必需的?
      

  5.   

    写一个ActiveX对象要让别的编译器能用,一般要实现IDispatch接口,以方便没有指针的编译器,如VB,VC在工程中插入ActiveX的时候,ClassWizard会从类型库里面查询接口的信息,再为这些接口封装出一个C++风格的类,再在这个类的每一个成员函数里调用InvokeHelper函数,InvokeHelper函数会调用IDispatch接口实现功能。你看得书是不是怎样使用控件的书,那就当然都会用到这个函数。这个函数可以说是必须的,除非你不打算给VB这样的编译器用。
      

  6.   

    我现在遇到的情况是这样的比如说在vb中设计时,通过属性页设置了控件的属性,在属性得值在属性栏里面是显示出来了,可是一运行,这个属性刚才的设置就无效了,结束运行后在属性栏里面刚才设置的属性值也没有了。
    我是这样写代码的:
    void CTcfnewCtrl::SetDBPath(LPCTSTR lpszNewValue) 
    {
    static BYTE parms[]=VTS_BSTR;
    InvokeHelper(0x1,DISPATCH_PROPERTYPUT,VT_EMPTY,NULL,parms,lpszNewValue);
    m_datapath=lpszNewValue;//m_datapath是控件的一个成员变量
    if(ConnectDatabase())//连接数据库,再控件中显示数据库中的内容
    {
    ……
    }
    }
    BSTR CTcfnewCtrl::GetDBPath() 
    {
         CString strResult;
    // TODO: Add your property handler here
         strResult=m_datapath;
         InvokeHelper(0x1,DISPATCH_PROPERTYGET,VT_BSTR,(void*)&strResult,NULL);
         return strResult.AllocSysString();
    }
    不知道对不对?
      

  7.   

    呵呵,这段代码看得我云山雾里呀^_^,小生也是初涉COM,功力不够啊!
    这个控件是你自己写的吧!你的控件属性的调用很混乱!你的Set和Get函数最好加入返回值,这样才能知道调用是否成功!
    //InvokeHelper(0x1,DISPATCH_PROPERTYPUT,VT_EMPTY,NULL,parms,lpszNewValue);
    //m_datapath=lpszNewValue;//m_datapath是控件的一个成员变量
    m_datapath既然是控件的一个成员变量,你怎么又能在你插入ActiveX的地方直接用到它?你应该在ActiveX内部编写STDMETHODIMP SetDBPath(BSTR lpsePath, short *pVal)
    时,将lpszNewValue付给m_datapath,如果不成功,可用返回的short *pVal值表示错误的不同原因。
    short CTcfnewCtrl::SetDBPath(LPCTSTR lpszNewValue)
    {
    short result;
    static BYTE parms[] =
    VTS_BSTR;
    InvokeHelper(0x1, DISPATCH_PROPERTYPUT, VT_I2, (void*)&result, parms,
    lpszNewValue);
    return result;
    }
    就可以了。
    但CTcfnewCtrl::SetDBPath()函数应由classwizard来写,你只要专心写你的ActiveX就可以了。写好了ActiveX,在VC中利用ClassWizard把ActiveX封装进来,和别的MFC类一样用,没什么大区别。
      

  8.   

    还有在调用ActiveX的程序里的Get函数应为:
    CString CTcfnewCtrl::GetDBPath()
    {
    CString result;
    InvokeHelper(0x1, DISPATCH_PROPERTYGet, VTS_BSTR, (void*)&result, NULL);
    return result;
    }
    当然,这个函数也是ClassWizard自动写的!
      

  9.   

    还有在调用ActiveX的程序里的Get函数应为:
    CString CTcfnewCtrl::GetDBPath()
    {
    CString result;
    InvokeHelper(0x1, DISPATCH_PROPERTYGet, VTS_BSTR, (void*)&result, NULL);
    return result;
    }
    当然,这个函数也是ClassWizard自动写的!
    下班了^_^