80分关于vb调用cb制作的dll的问题,恳请dll高手回答。
我写了一个cb的dll
使用的是cb的dll向导做的在调用函数中
//---------------------------------------
#include <vcl.h>
#include <ADODB.hpp>
#include <windows.h>
//-------------
#include "C42.h "
#pragma hdrstop
#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
return 1;
}
//---------------------------------------
extern "C " int _export _stdcall ExportInfo(AnsiString server,AnsiString username,
AnsiString pwd,AnsiString database,AnsiString barcode,
AnsiString& xh,AnsiString& pm,AnsiString& gg,AnsiString& zl)
{
TADOConnection *conn=new TADOConnection(NULL);
AnsiString connstr,tempstr;
AnsiString xstr,typestr,sizestr,weightstr;
AnsiString sqlstr;
C42 YS;
YS.mvarC10In=barcode.SubString(1,5).Trim();
YS.C10n();
tempstr=YS.mvarC10Out.sprintf( "%07d ",StrToInt(YS.mvarC10Out));
YS.mvarC10In=barcode.SubString(6,4).Trim();
YS.C10n();
tempstr+=YS.mvarC10Out.sprintf( "%07d ",StrToInt(YS.mvarC10Out));
YS.mvarC10In=barcode.SubString(11,5).Trim();
YS.C10n();
tempstr+=YS.mvarC10Out.sprintf( "%07d ",StrToInt(YS.mvarC10Out));
YS.mvarC10In=barcode.SubString(16,5).Trim();
YS.C10n();
tempstr+=YS.mvarC10Out;
xstr=tempstr.SubString(7,11); //箱号
sqlstr= "select 品名 as pm,规格 as gg,总净重 as weight from 箱记录 where 箱号= "+xstr;
connstr= "Provider=SQLOLEDB.1;Password= "+pwd+ ";Persist Security Info=True;\
User ID= "+username+ ";Initial Catalog= "+database+ ";Data Source= " + server;
conn-> ConnectionString=connstr;
conn-> CommandTimeout=10;
conn-> CursorLocation=clUseServer;
conn-> LoginPrompt=false;
try
{
if(!conn-> Connected)
conn-> Open();
}
catch(const Exception &e)
{
ShowMessage( "连接异常 ");
return 0;
}
TADOQuery *qu=new TADOQuery(NULL);
qu-> Connection=conn;
qu-> SQL-> Clear();
qu-> SQL-> Add(sqlstr);
qu-> Open();
typestr=qu-> FieldByName( "pm ")-> AsString;
sizestr=qu-> FieldByName( "gg ")-> AsString;
weightstr=qu-> FieldByName( "weight ")-> AsString;
xh=xstr.Trim();
pm=typestr.Trim();
gg=sizestr.Trim();
zl=weightstr.Trim();
delete qu;
delete conn;
return 1;
}
然后生成dll cb调用是正常的。
在vb中调用
首先申明:
Private Declare Function ExportInfo Lib "KGQBXInfoEx.dll " (ByVal server As String, ByVal username As String, ByVal pwd As String, ByVal database As String, ByVal barcode As String, ByRef xh As String, ByRef pm As String, ByRef gg As String, ByRef zl As String) As Integer
然后调用
Dim xh, pm, gg, zl As String
Dim i As Integer
i = ExportInfo( "127.0.0.1 ", "sa ", "123 ", "ss ", "1E+L 6YCW 17BCX9 ", xh, pm.gg, zl)
可是提示 compile error: type mismatch
这个是这么回事啊?
是不是cb的AnsiString参数和vb的string类型不同造成的?
我该这么修改啊?
再有我上面的dll在别的没有装cb的机器上能不能正常运行的?就是说脱离borlandmm.dll等支持库运行。
[解决办法]
VB偶不熟.
BCB的DLL导出函数的参数不要用 AnsiString, 换成char *