VC6.0调用银海新疆程序接口示范代码
Powered by 十二医院
使用本文附录的方法五,即通过ClassWizard利用类型库生成包装类.
用VC6的View->ClassWizard…从AddClass…按钮里选择From a type library…,出现对话框,选择windows\system32\目录下的yh_interfaceproxy.dll链接库,然后会在VC里自动生成Iyhinterface类.以03交易刷卡交易为例,添加如下代码.
CoInitialize(NULL); //初始化COM环境
Iyhinterface yh; //声明Iyhterface类的对象yh
COleVariant appmsg; //因为C是强类型语言,
COleVariant appcode; // 所以appmsg和appcode这两个变量必须这样声明
if(yh.CreateDispatch("yinhai.xjcj.interface")!=0)
{
yh.yh_interface_init(appcode,appmsg); //银海的初始化函数
}
CString BusinessID="03";//刷卡交易
CString dataxml;
COleVariant Businesssequence,Businessvalidate,outputxml;
dataxml="";
yh.yh_interface_call((LPCTSTR)BusinessID,(LPCTSTR)dataxml,Businesssequence,Busines svalidate,outputxml,appcode,appmsg);
if(appcode.lVal<0)
{
CString cs,strappmsg=appmsg.bstrVal;
cs.Format("读卡失败!错误原因:%s",strappmsg);
MessageBox(cs,"读卡程序",MB_ICONERROR);
}
else
{
CString stroutput=outputxml.bstrVal;
processoutputxml((char *)(LPCTSTR)stroutput); //自定义处理xml的函数
UpdateData(false);
}
CoUninitialize(); //析构COM环境