入门级问题。 VC ATL 封装 Delphi com 组件 pchar 类型转换。

VC 中需要用ATL 调用 delph 写的com。

IFinanceReport  : 为接口

GetFinaceReport : 接口方法

在 文件头 :#import "dll path" no_namespace

类型转换问题折腾了好久。在delphi 中的 pchar, vc 封装后为 LPSTR*

STDMETHODIMP CmyATL::GetFinaceReport(BSTR year, BSTR month, BSTR* XMLReport)
{
 // TODO: 在此添加实现代码

   LPSTR * year2  ;
   LPSTR * month2 ;
      year2=new LPSTR;
      month2=new LPSTR;
      *year2 =  _com_util::ConvertBSTRToString(year);
      *month2= _com_util::ConvertBSTRToString(month); 
      
   CoInitialize(NULL);
   CLSID clsid;
   HRESULT hr=CLSIDFromProgID(OLESTR("ProFinRep.FinanceReport"),&clsid);
   IFinanceReport *ptr;
   hr=CoCreateInstance(clsid,NULL,CLSCTX_INPROC_SERVER,
                 __uuidof(IFinanceReport),(LPVOID*)&ptr);
  
   *XMLReport=  _com_util::ConvertStringToBSTR (ptr->GetFinaceReport(year2 ,month2));
   
 
  CoUninitialize();

 
 return S_OK;
 
}

posted on 2011-03-16 10:50  dengdeng  阅读(470)  评论(0编辑  收藏  举报

导航