设置组件的一个属性,比如pen,本来是LOGPEN,应该改用那一种数据类型啊?

解决方案 »

  1.   

    就是怎么在COM组件中传递Struct结构?
      

  2.   

    LOGPEN
    CreateFontIndirect里的那个lpLogPen?你传结构的指针吧。
      

  3.   

    可能大家误会我得意思了
    是这样的
    我有一个已经存在的类,现在要为它加上COM接口
    这样就要写接口函数
    其中有一个函数是SetPen(LOGPEN &logpen),要把它写成COM接口,作为参数的LOGPEN应该用哪一种自动化数据类型代替?我有一种想法,就是SetPen(IDispatch*pObj),但是不知道把一个LOGPEN形式的结构体怎么封装成COM组件,这样行的通吗?如下:
    Class CPenObj:public CCmdTarget
    {
    ...............
    public:
        LOGPEN m_logpen;
        // Generated OLE dispatch map functions
        //{{AFX_DISPATCH(ATOM_DATA)
         afx_msg void SetlopnWidth(long newValue);
         afx_msg long GetlopnWidth();
          //}}AFX_DISPATCH
         DECLARE_DISPATCH_MAP()
         DECLARE_INTERFACE_MAP()
    }在CPP中:
    void CPenObj::SetlopnWidth(long newValue)
    {
        m_logpen.lopnWidth = newValue;
    }
    long CPenObj::GetlopnWidth()
    {
        return m_logpen.lopnWidth;
    }
    请大家指正!谢谢
      

  4.   

    用数组代替你的结构吧!com中不能传递结构的!这能用variant包一下了!哈哈!
      

  5.   

    用SafeArray传。下面是代码:
    void CMyIeDlg::putArrays()
    {
    HRESULT hr;
    SAFEARRAY* psaStudent = NULL;
    SAFEARRAYBOUND rgbounds = { 4, 0 };
    studentsInfo *pStudentStruct = NULL; psaStudent = SafeArrayCreate(VT_VARIANT, 1, &rgbounds);
    hr = SafeArrayAccessData(psaStudent, reinterpret_cast<PVOID*>(&pStudentStruct)); pStudentStruct[0].grade = 3;
    pStudentStruct[0].name = SysAllocString(L"Shaun");
    pStudentStruct[0].type = class_Clown;
    pStudentStruct[1].grade = 8;
    pStudentStruct[1].name = SysAllocString(L"Fred");
    pStudentStruct[1].type = school_Bully;
    pStudentStruct[2].grade = 12;
    pStudentStruct[2].name = SysAllocString(L"Steve");
    pStudentStruct[2].type = teachers_Favorite;
    pStudentStruct[3].grade = 3;
    pStudentStruct[3].name = SysAllocString(L"Linda");
    pStudentStruct[3].type = teachers_Favorite; hr = SafeArrayUnaccessData(psaStudent);
    m_array.vt = VT_ARRAY;
    m_array.parray = psaStudent;}void CMyIeDlg::getArrays()
    {
    HRESULT hr;
    SAFEARRAY* psaStudent = NULL;
    studentsInfo *pStudentStruct = NULL;
    studentsInfo students[4]; psaStudent = m_array.parray;
    hr = SafeArrayAccessData(psaStudent, reinterpret_cast<PVOID*>(&pStudentStruct));
    for(int i = 0; i<4;i++)
    {
    students[i].grade  = pStudentStruct[i].grade ;
    students[i].name   = pStudentStruct[i].name  ;
    students[i].type   = pStudentStruct[i].type  ;
    }
    hr = SafeArrayUnaccessData(psaStudent);
    }
      

  6.   

    但是我有一个问题
    我的接口最终要被用户用VBSCript语言调用,如果他要调用SetPen(arrays),他也不知道这个参数要怎么写啊,因为arrays是我内部的数组,除非也用COM封装,否则无法暴露给用户:(~~
      

  7.   

    你可以将LOGPEN分成三个参数让用户传递进来了
      

  8.   

    我也这样想过,但是为了兼顾到可能出现其他类似的情形,比如Font,所以想还是用一个比较通用的方法比较好
      

  9.   

    那么接口的OUT参数是接口指针时,这个指针的内存空间是由调用者分配还是由被调用者分配?
      

  10.   

    苯一点,还是用字符串分割传好一点:"1,2,3,4"
    VBScript中用Split等函数返回数组就可以了.