我在Add Method中只能添加的方法只能是HRESULT类型的,要返回其他值只能通过OUT类型的参数
能不能做到调用这个ATL COM时返回的内容直接通过方法的返回值得到,比如直接返回 字符,long 或其他类型
我在其他程序中调用
string sRet;
sRet= MyAtl.method1(); //返回的内容直接通过返回值得到

解决方案 »

  1.   

    你在ATL Object Wizard中的Object Wizard的Attributes页面中的Interface设置为Custom类型就可以了。
      

  2.   

    我在Attributes页面中的Interface设置为Custom类型
    然后添加一个返回为long类型的方法AddNum,系统自动生成了下面代码
    STDMETHODIMP_(long) CMyAlt::AddNum()
    {
    // TODO: Add your implementation code here
    return 0;
    }
    但这是编译就报错了
    procedures in an object interface must return an HRESULT : [ Procedure 'AddNum' ( Interface 'IMyAlt' ) ]
    请问是为什么
      

  3.   

    可以。你可以IDL文件中定义这样的接口:Hresult   getString([out, retval] BSTR *strRet);
      

  4.   

    要像楼上这样声明接口:
    Hresult   getString([out, retval] BSTR *strRet);
    不过只能使用于script语言,比如在vbscript里面你可以sRet= MyAtl.method1(); ,但是如果你用VC调用这样做就不行了.
      

  5.   

    可以.
    你也可在IDL中加入属性。