ATL开发COM组件时能用unsigned char类型参数吗?
用ATL开发了一个COM组件,在.CPP单文档里可以调用,但是在MFC里面就出现
method 'ascii_read_hldreg' not emitted because of invalid return type or parameter type
错误,不知道怎么弄了,希望高手能指点一二。
还有怎么用ATL开发无界面的AvctiveX控件呢?

解决方案 »

  1.   

    HRESULT是他最终的返回值,但是在函数里面还有可以有[out,retval]属性的参数的,这些才是我们真正需要的返回值
    但是不知道用什么数值类型取代unsinged char类型,貌似这个在COM中用不来。非常奇怪
      

  2.   

    用VARIANT类型,里面指定位BYTE*类型就行啦
      

  3.   

    STDMETHODIMP CCode::ascii_set_hldreg(UCHAR board_adr, UCHAR *com_buf, int start_address, int value, int* pResult)
    {
    // TODO: Add your implementation code here unsigned char tmp[256],tmp_lenth;
    tmp[0]=board_adr;
    tmp[1]=SET_HLD_REG;
    tmp[2]= start_address/256;
    tmp[3]=start_address & 0xff;
    tmp[4]= value/256;
    tmp[5]= value &0xff;    
    tmp_lenth=6;
    _ConFrm.construct_ascii_frm ( com_buf,tmp,tmp_lenth);
    *pResult = 17;
    return S_OK;
    }
    定义了UCHAR为unsigned char不行
    改为BYTE类型也不行。
    真是郁闷啊~继续改改看看。
    奇怪的是在单文件的.CPP程序中可以,但在MFC中就不可以用了出现
    // method 'ascii_read_hldreg' not emitted because of invalid return type or parameter type
    其他函数类似也是这个问题