傳 record type 變數至 DLL 需 allocate memoey嗎? |
尚未結案
|
amy580120
一般會員 發表:2 回覆:2 積分:0 註冊:2003-03-01 發送簡訊給我 |
大家好:
我是新手,有一問題想請教各位高手.
我寫了一function,需傳一傳址的自訂型態變數streply,
此function又call一DLL 的 function(RSCWR),
若不編譯成 DLL,則傳回值是正確的,
但若轉為 DLL,則RSCWR 會 return一值表示堆疊用盡(heap exhausted),
所有 RSCWR傳回的自訂型態變數streply內容就是錯的,想請問大家
傳 record type 變數至 DLL 需先 allocate memoey嗎?
若要,請問要如何做?
以下是我的程式,請大家幫幫我,我快瘋了.
-------------------------------------------------------------
主程式: interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,ShareMem; type
strequest = packed record
cID:array[0..9] of char;
cPname:array[0..9] of char;
cPbirth:array[0..5] of char;
cSex:char;
cAddress:array[0..49] of char;
cTel:array[0..9] of char;
cFdate:array[0..5] of char;
cFlag:char;
cCkgp:char;
cSchdt:array[0..5] of char;
end; type
streply = packed record
replycode:smallint;;
filestatus:array[0..1] of char;
guardianerror:smallint;
fileid:array[0..7] of char;
cPno:array[0..7] of char;
cPname:array[0..9] of char;
cPbirth:array[0..5] of char;
cSex:char;
cAddress:array[0..49] of char;
cTel:array[0..9] of char;
cFdate:array[0..5] of char;
cIdi:array[0..2] of char;
cAdate:array[0..5] of char;
cFlag:char;
cPunit:char;
cEno:array[0..5] of char;
cAcyn:char;
cResult:array[0..1] of char;
end; var
stRequestrec: strequest;
streplyrec :streply;
uloptions:longint;
ulConnectionHandle:longint;
ulSessionHandle:longint;
uSessionType:word;
acTermName:pchar;
acServerName:pchar; const
RSC_REQ_WAITED:smallint = -1;
RSC_ST_INTERPROCESS:word = 2;
RSC_ST_PATHWAY:word = 1; function RSCB126FS(ulOptionsHandle:longint;ulConnectionHandle:Longint;ulSessionHandle:Longint;stRequestBuffer:strequest;out preply:pstreply;x:smallint):smallint;stdcall;external 'C:\RSC\Delphi\RSCDLL\PRJRSCDLL.DLL' ; implementation
procedure TForm1.Button2Click(Sender: TObject);
var
nRtn:smallint;
begin
with strequestrec do
begin
StrPCopy(cId, m_id.text);
FillChar(cPname,sizeof(cPname),' ');
FillChar(cPbirth,sizeof(cPbirth),' ');
FillChar(cSex,sizeof(cSex),' ');
FillChar(cAddress,sizeof(cAddress),' ');
FillChar(cTel,sizeof(cTel),' ');
cFdate := '920319';
FillChar(cFlag,sizeof(cFlag),' ');
cCkgp := '2';
FillChar(cSchdt,sizeof(cSchdt),' ');
end;
acServerName:='B126FS' ;
nRtn := RSCB126FS(uloptions, ulConnectionHandle,ulSessionHandle,strequestrec,stReplyrec,2);
if nRtn = 0 then
begin
m_pname.text :=stReplyrec.cPname;
m_pbirth.Text := stReplyrec.cPbirth;
m_address.text := stReplyrec.cAddress;
m_pno.Text := stReplyrec.cPno;
m_tel.Text := stReplyrec.cTel;
m_sex.text := stReplyrec.cSex;
end;
end;
--------------------------------------------------------
DLL 部份: library PrjRscDll;
uses
UnitRSC in 'UnitRSC.pas';
exports
RSCB126FS;
------------------------------
unit UnitRSC; interface type
preq=^rdreq;
rdreq = packed record
cID:array[0..9] of char;
cPname:array[0..9] of char;
//cPname : string[10];
cPbirth:array[0..5] of char;
cSex:char;
cAddress:array[0..49] of char;
cTel:array[0..9] of char;
cFdate:array[0..5] of char;
cFlag:char;
cCkgp:char;
cSchdt:array[0..5] of char;
end; type
prep=^rdrep;
rdrep = packed record
replycode:smallint;
filestatus:array[0..1] of char;
guardianerror:smallint;
fileid:array[0..7] of char;
cPno:array[0..7] of char;
cPname:array[0..9] of char;
cPbirth:array[0..5] of char;
cSex:char;
cAddress:array[0..49] of char;
cTel:array[0..9] of char;
cFdate:array[0..5] of char;
cIdi:array[0..2] of char;
cAdate:array[0..5] of char;
cFlag:char;
cPunit:char;
cEno:array[0..5] of char;
cAcyn:char;
cResult:array[0..1] of char;
end; function RSCWR(ulOptionsHandle:Longint;ulConnectionHandle:Longint;ulSessionHandle:Longint;pcServerName:PCHAR;nIoHandle:Smallint;var pvRequestBuffer;uRequestSize:word;var pvReplyBuffer;var puReplySize:word):word;stdcall;far;external 'RSCW32.DLL'; function RSCB126FS(ulOptions:longint;ulConnectionHandle:Longint;ulSessionHandle:Longint;stRequestBuffer:rdreq;out stReplyBuffer:rdrep;x:smallint):smallint;stdcall;export; implementation function RSCB126FS(ulOptions:longint;ulConnectionHandle:Longint;ulSessionHandle:Longint;stRequestBuffer:rdreq;out stReplyBuffer:rdrep;x:smallint):smallint; const
RSC_REQ_WAITED:smallint = -1;
RSC_ST_INTERPROCESS:word = 2;
RSC_ST_PATHWAY:word = 1;
acServerName:pchar = 'B126FS';
var
nIoHandle:smallint;
nrequestsize:word;
nreplysize:word;
nResult:word;
begin
nResult := 0;
case x of 2: // check 病歷資料
begin
nIoHandle := RSC_REQ_WAITED;
nrequestsize := sizeof(rdreq);
nreplysize := sizeof(rdrep);
nResult := RSCWR(uloptions, ulConnectionHandle,
ulSessionHandle, acServerName,
nIoHandle, stRequestBuffer,
nrequestsize, stReplyBuffer, nreplysize);
stReplyBuffer.replycode := RSCSI(stReplyBuffer.replycode);
end;
RSCB126FS := nResult;
end;
|
Justmade
版主 發表:94 回覆:1934 積分:2030 註冊:2003-03-12 發送簡訊給我 |
|
amy580120
一般會員 發表:2 回覆:2 積分:0 註冊:2003-03-01 發送簡訊給我 |
|
rexchiu
中階會員 發表:14 回覆:88 積分:70 註冊:2002-03-17 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |