c++ builder 如何调用COM?
以下是vbs代码:
Set hsClient = CreateObject("HSIrm.HSIrmClient")
'对密码进行加密
EnPassword = hsClient.EncryptPassword("my", "w21WrtX")
'进行用户认证
RetCode = hsClient.Init("my", EnPassword, 1)
if RetCode <> 0 then
Descr = hsClient.GetDescriptionByCode(RetCode)
MsgBox "初始化失败, Code: " & RetCode & "---" & Descr
else
MsgBox "初始化成功"
end if
---------------------------------
想模仿vb用c++ builder来实现
vb中的:Set hsClient = CreateObject("HSIrm.HSIrmClient")
可以用c++ builder:Variant hsClient = Variant::CreateObject("HSIrm.HSIrmClient")代替
其他的hsClient.EncryptPassword、hsClient.Init没法做,Variant没有这样的方法。
请各位老师支持,谢谢!
[解决办法]
大概可能是这样,个别术语不清楚到底是方法还是属性,自己揣摸。
Variant hsClient = CreateOleObject("HSIrm.HSIrmClient");
Variant EnPassword = hsClient.OleFunction("EncryptPassword", "my", "w21WrtX");
Variant RetCode = hsClient.OleFunction("my", EnPassword, 1);
if (RetCode.intVal)
{
Variant Descr = hsClient.OleFunction("GetDescriptionByCode", RetCode);
ShowMessage(String().sprintf(TEXT("初始化失败, Code: %d --- %s"),
RetCode.intVal, Descr.pcVal));
}
else
ShowMessage("初始化成功");