線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1129
推到 Plurk!
推到 Facebook!

请问用Delphi写的DLL在Vb下如何调用

尚未結案
vclphi
一般會員


發表:28
回覆:39
積分:13
註冊:2003-03-06

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-12-01 10:39:26 IP:61.154.xxx.xxx 未訂閱
我用Delphi写了xstr.dll,如下: library Xstr; uses SysUtils, Classes, XstrUnit1 in 'XstrUnit1.pas', exports xas1,xas2,xas3; {$R *.res} begin end. unit XstrUnit1; interface Type Procedure xas1(a1,a2,a3,a4:Real;d5:String);export; Procedure xas2(a1,a2,a3,a4:Real;c5:Byte);export; Procedure xas3;export; ...... 在Delphi下经应用程序调用,运行正常. 后我一同事用VB调用,如下: Module1: Declare Sub xas1 Lib "xstr.dll" (ByVal a1 As Single, ByVal a2 As Single, ByVal a3 As Single, ByVal a4 As Single, ByVal d5 As String) Declare Sub xas2 Lib "xstr.dll" (ByVal a1 As Single, ByVal a2 As Single, ByVal a3 As Single, ByVal a4 As Single, ByVal c5 As Byte) Declare Sub xas3 Lib "xstr.dll" () Private Sub Command1_Click() CommonDialog1.Action = 2 sName = CommonDialog1.FileName xas1 0,0,40,29,sName xas2 0,0,40,0,9 xas2 40,0,40,97,9 xas2 40,97,0,197,6 xas2 0,197,0,0,5 xas3 End Sub 却报告语法错误,请问Module1要怎么改? 發表人 - vclphi 於 2004/12/01 15:16:08
tonytop
中階會員


發表:6
回覆:114
積分:89
註冊:2003-12-04

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-12-01 14:07:01 IP:210.64.xxx.xxx 未訂閱
Delphi「預設」編譯出來的dll非standard的dll,vb當然不能調用, 但仍可透過delphi的project options設定environment options裡設定 編譯成standard 的dll,try it.    
vclphi
一般會員


發表:28
回覆:39
積分:13
註冊:2003-03-06

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-12-01 15:11:29 IP:61.154.xxx.xxx 未訂閱
请问如何設定environment options裡設定 編譯成standard 的dll
wameng
版主


發表:31
回覆:1336
積分:1188
註冊:2004-09-16

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-12-01 15:45:39 IP:61.31.xxx.xxx 未訂閱
事實上是您未依照Windows 標準設計您的DLL 接口。 字串單位,建議使用PCHAR 不要使用 String。這裡的String為Delphi自己的格式。
vclphi
一般會員


發表:28
回覆:39
積分:13
註冊:2003-03-06

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-12-01 16:28:28 IP:61.154.xxx.xxx 未訂閱
(1)real,byte也是Delphi自己的格式? 我在另一DLL中还用了ShortString,Integer,Char,Word请问要该成哪些类型? (2)Procedure xas1(a1,a2,a3,a4:Real;d5:String);中的D5是用来指定文件名, If (Pos('.doc',d5)=0) Then d5:=d5 '.doc'; Assign(dfile,d5); ...... Close(dfile); 用pchar代替string后出错
wameng
版主


發表:31
回覆:1336
積分:1188
註冊:2004-09-16

發送簡訊給我
#6 引用回覆 回覆 發表時間:2004-12-01 16:55:01 IP:61.31.xxx.xxx 未訂閱
(1)real,byte也是Delphi自己的格式? 一般是用 Single。不過應該也是可以的。 >用pchar代替string后出错 使用PChar 必須先配置記憶體。利用 GetMem 取得及 FreeMEM釋放。
tonytop
中階會員


發表:6
回覆:114
積分:89
註冊:2003-12-04

發送簡訊給我
#7 引用回覆 回覆 發表時間:2004-12-02 10:50:45 IP:210.64.xxx.xxx 未訂閱
SORRY!記錯了,我找一下help的資料,希望有幫助 while stdcall and safecall are used for Windows API calls. A dual interface is an interface that supports both compile-time binding and runtime binding through Automation. Dual interfaces must descend from IDispatch. All methods of a dual interface (except from those inherited from IUnknown and IDispatch) must use the safecall convention, and all method parameter and result types must be automatable. (The automatable types are Byte, Currency, Real, Double, Real48, Integer, Single, Smallint, AnsiString, ShortString, TDateTime, Variant, OleVariant, and WordBool.) 我正確的mail:h832214@hotmail.com
vclphi
一般會員


發表:28
回覆:39
積分:13
註冊:2003-03-06

發送簡訊給我
#8 引用回覆 回覆 發表時間:2004-12-02 11:14:09 IP:61.154.xxx.xxx 未訂閱
(1)tonytop你是说"Byte, Currency, Real, Double, Real48, Integer, Single, Smallint, AnsiString, ShortString, TDateTime,  Variant, OleVariant, and WordBool"可自动转化? 那么"string,Char,Word"怎么办?将"string"改为"AnsiString"? (2)wameng你说"建議使用PCHAR 不要使用 String"是指返回的Function值吗?    如是Function的参数能用String吗?如:Function GetPYM(vStr:String; vS:Integer):Pchar;stdcall;export;    Dll中的Procedure参数能用String吗?如Procedure GetPYM(vStr:String; vS:Integer);stdcall;export;     發表人 - vclphi 於 2004/12/02 17:13:51
系統時間:2024-05-17 10:20:01
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!