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

呼叫dll的問題?

尚未結案
benson5033
一般會員


發表:44
回覆:47
積分:18
註冊:2004-08-16

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-03-30 18:36:11 IP:210.62.xxx.xxx 未訂閱
type
  RecDef = record
        ID             :string;
        Status         :string;
        PlayTime       :string;
        Speaker        :String;
        Controller     :string;
        Creator        :string;
        CreateTime     :string;
        FinishTime     :string;
        LastUpdateTime :string;
        Updater        :string;
        Comments       :string;
        NewsTotalCnt   :string;
        PrepareTime    :string;
    end;    function Read(var SID :integer; var DB_Name:PChar;var RSId: SmallInt;var RS_SEQ:SmallInt;var FPos:Smallint;var Stamp:SmallInt; pRecord:Pointer):SmallInt;stdcall;external 'Client.dll';     implementation    {$R *.dfm}    var
  InRec : RecDef;
  TBRv:integer;
  ss:string;
procedure TForm1.FormCreate(Sender: TObject);
begin
TBRv := Read(ServerID, dbname, DBRsId, DBRsSeqNo, DBRecNo,  
                DBUFlag, @InRec);
ss:=InRec.ID;
end;    
ServerID, dbname, DBRsId, DBRsSeqNo, DBRecNo,DBUFlag這些值我省略了沒寫出來,這些值是要代入Read函數的。 如上的一段程式碼,當執行到Read這個function時如果有錯誤的話會傳回非0值,正常的話會得到0值,而且會把資料放至InRec裏,但是我執行後一確正常,可是就一直無法去存取InRec裏的資料,為什麼呢? 執行到ss:=InRec.ID;時就發生了存取違規,到底要怎麼做才行,我已經試了一天了,快起笑,那位大大救救我~~~~
huwk
資深會員


發表:26
回覆:340
積分:323
註冊:2002-04-03

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-03-30 19:32:45 IP:211.76.xxx.xxx 未訂閱
試著把你exe及dll都加入ShareMem在第一個單元試試看.. 若不行可否把比較完整的程式丟上來看看.. { 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. }
------
熊的學習 http://huwk.blogspot.com
benson5033
一般會員


發表:44
回覆:47
積分:18
註冊:2004-08-16

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-03-30 20:04:23 IP:218.167.xxx.xxx 未訂閱
引言: 試著把你exe及dll都加入ShareMem在第一個單元試試看.. 若不行可否把比較完整的程式丟上來看看.. { 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. }
小弟不太懂,可否說明白點。 程式要上傳的話,很麻煩,因為還要有SERVER的程式才有辦法RUN,那實在太大了。
wameng
版主


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

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-03-30 20:41:17 IP:61.31.xxx.xxx 未訂閱
1. 定義 PRecDef = ^ RecDef; 指針來操作較好。 2. 不要使用 String 。String 不是Dll 標準。 改用 PChar (需申請記憶體)或 ID:Array[0..255] of Char;....
benson5033
一般會員


發表:44
回覆:47
積分:18
註冊:2004-08-16

發送簡訊給我
#5 引用回覆 回覆 發表時間:2005-03-30 21:10:21 IP:61.230.xxx.xxx 未訂閱
引言: 1. 定義 PRecDef = ^ RecDef; 指針來操作較好。 2. 不要使用 String 。String 不是Dll 標準。 改用 PChar (需申請記憶體)或 ID:Array[0..255] of Char;....
使用了pchar,就沒有錯誤了,但裏面的值卻是空的,哎~~~~
wameng
版主


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

發送簡訊給我
#6 引用回覆 回覆 發表時間:2005-03-30 21:58:13 IP:61.31.xxx.xxx 未訂閱
改用 PChar (需申請記憶體 Getmem ) 或 ID:Array[0..255] of Char;.... 若不是很瞭解PChar 的用法。直接使用ID:Array[0..255] of Char;.... 255是指字串長度。可以先設定可能文字長度的最大值。 補充: 使用 String 並需 SetLength。 也就是說必須定義使用記憶體(內存)大小,這樣在傳遞指針內容。 才不會造成 讀取上的錯誤。
benson5033
一般會員


發表:44
回覆:47
積分:18
註冊:2004-08-16

發送簡訊給我
#7 引用回覆 回覆 發表時間:2005-03-30 22:01:41 IP:61.230.xxx.xxx 未訂閱
我是從vb程式要轉寫delphi的,原本vb的程式是:  
 
 Public Declare Function Read Lib "Client.Dll" (SDI As Long, DB_Name As String, RSID As Integer, Seq As Integer, Number As Integer, ByRef Stamp As Integer, Record As Any) As Integer    Type RecDef
    ID As String * 13
    Status As String * 4
    PlayTime As String * 3
    Speaker As String * 16
    Controller As String * 16
    Creator As String * 16
    CreateTime As String * 16
    FinishTime As String * 16
    LastUpdateTime As String * 16
    Updater As String * 16
    Comments As String * 32
    NewsTotalCnt As String * 3
    PrepareTime As String * 6
End Type    Public InRec As RecDef    Private Sub Form_Load()
dim ss as string
TBRv = TB_Read(ServerID, DB.Name, DBRsId, DBRsSeqNo, DBRecNo, DBUFlag, InRec)
ss=InRec.ID
End Sub
執行後ss是有東西的。那位大大救救我呀~~~~~~~~
wyndog
資深會員


發表:7
回覆:362
積分:348
註冊:2004-10-12

發送簡訊給我
#8 引用回覆 回覆 發表時間:2005-03-31 00:40:28 IP:61.64.xxx.xxx 未訂閱
引言:
Type RecDef
    ID As String * 13
    Status As String * 4
    PlayTime As String * 3
    Speaker As String * 16
    Controller As String * 16
    Creator As String * 16
    CreateTime As String * 16
    FinishTime As String * 16
    LastUpdateTime As String * 16
    Updater As String * 16
    Comments As String * 32
    NewsTotalCnt As String * 3
    PrepareTime As String * 6
End Type
那你應該這樣寫才是:
type
  RecDef = record
        ID:            array [0..12] of char; // string * 13
        Status:        array [0..3]  of char; // string * 4
        ... 餘累推
        PrepareTime:   array [0..5]  of char; // string * 6
    end;
系統時間:2024-05-02 21:40:52
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!