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

有關dll的求救!!!

尚未結案
northwind
一般會員


發表:3
回覆:4
積分:1
註冊:2003-04-09

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-04-24 14:24:59 IP:61.221.xxx.xxx 未訂閱
小弟用delphi寫了一個dll.....介面如下---- function GetNumber(T1,B1: PChar;Out Buffer1,Buffer2,Buffer3: PChar): Integer; stdcall; 但用vb寫了一支執行檔call此dll要回接buffer1,buffer2,buffer3的值時沒產生錯誤但接回來的卻是出現~~~此變數使用了vb不支援的automation型態~~的值....到底buffer1~3要宣告成何種型態才能讓外部的語言接到回傳值(*ps: buffer1~3我只是要回傳單純的字串資料而己.....)...........求各位大大救救我吧........
derekcylin
一般會員


發表:0
回覆:7
積分:6
註冊:2003-04-16

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-04-24 15:01:51 IP:211.21.xxx.xxx 未訂閱
可否寫出你在VB中的宣告以及在DLL中丟出了什麼資料呢? 看不懂你寫的意思. automation型態? 使用PCHAR和VB呼叫WIN32 API是一樣的用法去接, 看API怎麼宣告, 就怎麼接就對啦..它大概可以宣告如下: Private Declare Function GetNumber Lib "YouDllFile" Alias "GetNumber" (ByVal T1 As String, ByVal B1 As String, ByRef Buffer1 As String, ByRef Buffer2 As String, ByRef Buffer3 As String) As Long
northwind
一般會員


發表:3
回覆:4
積分:1
註冊:2003-04-09

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-04-24 15:46:16 IP:61.221.xxx.xxx 未訂閱
因為這個dll不只是給vb用的...還有給develop2000用,但vb如果宣告string去接會出型態錯誤的訊息,一定要宣告any才會過...如下: Private Declare Function GetNumber Lib "MYDllFile" Alias "GetNumber" (ByVal T1 As String,ByVal B1 As String,ByRef Buffer1 As any,ByRef Buffer2 As any,ByRef Buffer3 As any) As Long.......而且可以run沒錯誤 當我要看變數回接回什值...但卻出現~~此變數使用了vb不支援的automation類型~~...我再用develop2000寫程式測試結果也是沒有錯...但回接的值卻是'4?'的奇怪值....是dll宣告錯了還是外部程式的變數型態錯...像'4?'看起來好像是4 BYTE的記憶體位址,..是我回接指標變數的值回來嗎...請各位高手教一下吧..... 發表人 - northwind 於 2003/04/24 23:26:50
brucetsao
一般會員


發表:1
回覆:33
積分:11
註冊:2002-09-11

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-04-30 10:06:07 IP:61.219.xxx.xxx 未訂閱
delphi再寫dll時 回傳的值一定要宣告為pchar 如果真的不行,請先宣告一個 global靜態變數(不太合法,但是可以用) 再將此靜態變數回傳
brucetsao
一般會員


發表:1
回覆:33
積分:11
註冊:2002-09-11

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-07-08 18:35:26 IP:220.130.xxx.xxx 未訂閱
我您您一個範例 library jwdll; { Important note about DLL memory management: ShareMem must be the first unit in your library's USES clause AND your project's (select Project-View Source) USES clause if your DLL exports any procedures or functions that pass strings as parameters or function results. This applies to all strings passed to and from your DLL--even those that are nested in records and classes. ShareMem is the interface unit to the BORLNDMM.DLL shared memory manager, which must be deployed along with your DLL. To avoid using BORLNDMM.DLL, pass string information using PChar or ShortString parameters. } uses SysUtils, Classes ; exports getusername;//返回windows的當前用戶名稱 begin end. 再來用另一個PAS 內容 function getusername():pchar;stdcall;//返回當前用戶名稱 function getusername():pchar;stdcall;//取得當前用戶名稱 var ret:string; begin ret:=getwindowsuser(); result:=pchar(ret); end; 注意 result:=pchar(ret); 哪就是關鍵點
系統時間:2024-05-17 17:35:11
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!