如何用vc调用vb编的dll

tab888 2003-06-09 02:01:55
接口函数如下:
short _DiskInform::GetDiskInfo(LPCTSTR vNewValue)
...全文
74 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
enhydraboy 2003-06-09
  • 打赏
  • 举报
回复
vb编写的是activex dll,vc中调用
1 #import该dll文件
2 然后就可以调用,和vb很接近,不过要注意部分数据类型的转换。

example:
下面是一个调用ADO的

#import "d:\\Program Files\\Common Files\System\ADO\msado15.dll" no_namespace rename("EOF","EndOfFile")

BOOL DB_Add(String Title,String content,String Author,String SelfIntro,String file0,
String file1,String file2,String file3,String file4)
{
HRESULT hr = S_OK;
// Define ADO object pointers.
// Initialize pointers on define.
_RecordsetPtr pRst = NULL;
_ConnectionPtr pConnection = NULL;
//Replace Data Source value with your server name.
String DBFile;
String sResult="";
DBFile="Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=";
DBFile+=GetDBPath();

_bstr_t strCnn(DBFile.c_str());
_bstr_t strMessage;

if(FAILED(::CoInitialize(NULL))) return 0;
try{
//Open a connection
TESTHR(pConnection.CreateInstance(__uuidof(Connection)));
pConnection->Open(strCnn,"","",adConnectUnspecified);
TESTHR(pRst.CreateInstance(__uuidof(Recordset)));
pRst->Open("Salons",_variant_t((IDispatch *) pConnection, true),
adOpenDynamic,adLockOptimistic,adCmdTable);
//Add Recordset
TESTHR(pRst->AddNew());
pRst->Fields->Item["Title"]->Value=_bstr_t(Title.c_str());
pRst->Fields->Item["Content"]->Value=_bstr_t(content.c_str());
pRst->Fields->Item["Author"]->Value=_bstr_t(Author.c_str());
pRst->Fields->Item["Self-introduction"]->Value=_bstr_t(SelfIntro.c_str());
pRst->Fields->Item["pic1"]->Value=_bstr_t(file0.c_str());
pRst->Fields->Item["pic2"]->Value=_bstr_t(file1.c_str());
pRst->Fields->Item["pic3"]->Value=_bstr_t(file2.c_str());
pRst->Fields->Item["pic4"]->Value=_bstr_t(file3.c_str());
pRst->Fields->Item["pic5"]->Value=_bstr_t(file4.c_str());
TESTHR(pRst->Update());


}catch(_com_error &e)
{
::CoUninitialize();
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
return FALSE;
}
::CoUninitialize();
return TRUE;
}

7,764

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧