入门级问题。 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;
}