问题:DLL接口定义为testprocedure(const var1,var2,var3: string);VB中声明为Private Declare Sub DesignReport Lib "Estimate_Report.dll" (ByVal DBPath As string, ByVal DBName As string, ByVal ReportFile As string)实参类型也为string,但是在DLL中用showmessage显示参数的值是乱码。请问高手该怎么办?很急!
只能用PCHar!!!http://lysoft.7u7.net
类似 VC的 CString吧
DLL接口用Pchar,VB中使用string也是一样的。(VB我不熟临时抱佛脚)VB中用哪种类型?
谢谢!我试试.
问题依旧.请大家继续关注!
要不行。你把代码贴出来。
偶帮你调试。
我这边的DLL用到数据库,代码贴出来你也没办法帮我调试。不过我写了一个很简单的测试程序,劳驾帮忙看看。代码如下:
1、delphi DLL接口函数代码:
procedure TestP(const VarName: Pchar);Export;
begin
form1 := Tform1.Create(nil);
Application.MessageBox(VarName,'Test',MB_YESNO+MB_ICONQUESTION);
form1.Free;
form1 := nil;
end;
2、VB的调用代码
Private Declare Sub TestP Lib "Project1.dll" (ByVal VarName As String)
Private Sub Command3_Click()
Dim VN As String
VN = "XYZ"
TestP VN
End Sub
vb
Public Declare Function testdll Lib "dlltest.dll" (ByVal str1 As String, ByVal str2 As String, ByVal str3 As String) As IntegerPrivate Sub Command1_Click()
testdll "aaa", "awrr", "ccc"
End Subdelphi
function testdll( str1,str2,str3: pchar): integer;
begin
with tform1.Create(Application) do
try
Edit1.Text := str1;
Edit2.Text := str2;
Edit3.Text := str3;
//result := 1;
ShowModal;
finally
end;
end;
请帮忙看看我那段代码。
function testdll( VarName: pchar): integer;
begin
form1 := Tform1.Create(nil);
try
Application.MessageBox(VarName,'Test',1);
finally
FreeAndNil(form1);
end;
可用
不加stdcall;会成乱码
感谢你热情支持!前面我在delphi中调试DLL时,加stdcall出错我才去掉的。我再试试。
通过,谢谢!但是出现一个新问题(再打扰),在VB中编译执行提示地址冲突,生成EXE文件执行正常。
错了,提示“应用程序产生异常 软件未知异常(xxxxxxxxx)位置xxxxxxxxx.
Public Declare Sub testdll Lib "dlltest.dll" (ByVal str1 As String)
Private Sub Command1_Click()
testdll "aaa" 或"通过"
End Sub
没有你说的现象
能肯定是没打sp5补丁的问题吗?能否麻烦解释一下sp5的作用,对vb我不熟。
delphi中用
form1.Free;
form1 := nil;
我的环境d6 ,vb6.0。这时其中的一个接口,定义报表.(用fastreport报表控件,数据库是ACCESS)
procedure PrintReport(DBPath,DBName,ReportFile: pchar);stdcall;export;
---------------------------------
procedure DesignReport(DBPath,DBName,ReportFile: pchar);Export;
var
FileName: string;
Frm_Estimate_Report: TFrm_Estimate_Report;
StrConnection: String;
begin
Frm_Estimate_Report := TFrm_Estimate_Report.Create(nil);
try
StrConnection := '';
with Frm_Estimate_Report do
begin
ADOCon_DB.Connected := false;
StrConnection := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+
DBPath+DBName+
';Mode=Read;Persist Security Info='+
'False;Jet OLEDB:Database Password=conenet99';
ADOCon_DB.ConnectionString := StrConnection;
ADOCon_DB.Connected:=true; ADOQry_DYCS1.Active := true;
FileName := extractfilepath(application.ExeName)+ReportFile;
if FileExists(FileName) then
begin
frReport1.LoadFromFile(FileName);
Screen.Cursor := CrDefault;
frDesignerClass := TfrDesignerForm;
frReport1.DesignReport;
end
else
begin
Screen.Cursor := CrDefault;
application.MessageBox(pchar(FileName + '报表文件不存在,' + #13 + #10
+ '请核对文件名及其路径后重试!'), '提示', MB_OK + MB_ICONINFORMATION);
end;
end;
finally
Frm_Report.Free;
Frm_Report := nil;
end;
太麻烦你了,抱歉!
---------------------------------------------------------------------
scottzyv,b6打sp6补丁,上述问题解决。谢谢大家的支持,马上结帖。