안녕하십니까
DLL Unit을 작성하는 중에 요상한 Error로 고민중입니다..
Dll에는 DataModule에 간단한 Procedure,function이 있습니다.
-----------------------------------------------------------
이상한 점은 Delphi4가 떠있는 상태에서 실행 시키면 정상적으로
Dll procedure를 잘실행하는 데
---------------------------------
독립적으로 실행파일을 실행시키면
여지없이 LoadLibary Fail Error : 1157 가 나타납니다..
-------------------------------------------------------
잘아시는 분 꼭좀부탁드립니다....
// DLL Unit.........
//----------------------------------------------
unit UGetAddr;
interface
uses
................
procedure DllInitGetAddr(DBHand:hDBIDb);StdCall;
function ExGetAddr(Arg1:PChar):PChar; StdCall;
exports
DllInitGetAddr,ExGetAddr;
var
CADataModule: TCustAddrDataModule;
implementation
`~~~~~~~~~~
~~~~~~~~~
// DLL Call Unit................
===============================
procedure TForm1.DLLStart;
begin
database1.Connected := true;
hDllInst := LoadLibrary('getAddr.dll');
if hDllInst <= 0 then <==== Error 지점
Raise Exception.Create('[LoadLibrary Fail] GetLastError reports: '+
IntToStr(GetLastError));
try
@DllInitGetAddr := GetProcAddress(hDllInst,'DllInitGetAddr');
if Assigned(DllInitGetAddr) then begin
DllInitGetAddr({Application,Screen,}database1.handle);
@ExGetAddr := GetProcAddress(hDllInst,'ExGetAddr');;
if not Assigned(ExGetAddr) then begin
Raise Exception.Create('cc[GetProcAddress Fail] GetLastError reports: '+
IntToStr(GetLastError));
end;
end else begin
Raise Exception.Create('[GetProcAddress Fail] GetLastError reports: '+
IntToStr(GetLastError));
end;
except
Showmessage('Error');
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Arg1 : PChar;
Arg2 : PChar;
begin
FormStart;
With Query1 do begin
Open;
Showmessage('RecordCount = '+IntToStr(RecordCount));
First;
While not eof do begin
Arg1 :=PChar(FieldByName('ev_cust_no').AsString);
try
Arg2 := ExGetAddr(Arg1);
except
showmessage('Error');
end;
RichEdit1.Lines.Add(Arg2);
Next;
end;
end;
FormEnd;
end;
따라서 if hDllInst <= 0 then 는 if hDllInst = 0 then 이 되어야 할것입니다.
만일 hDllInst = 0 일 때 GetLastError 함수를 사용해서 에러 원인을
확인하십시오.
조제현 wrote:
> 안녕하십니까
> DLL Unit을 작성하는 중에 요상한 Error로 고민중입니다..
>
> Dll에는 DataModule에 간단한 Procedure,function이 있습니다.
> -----------------------------------------------------------
> 이상한 점은 Delphi4가 떠있는 상태에서 실행 시키면 정상적으로
> Dll procedure를 잘실행하는 데
> ---------------------------------
> 독립적으로 실행파일을 실행시키면
> 여지없이 LoadLibary Fail Error : 1157 가 나타납니다..
> -------------------------------------------------------
> 잘아시는 분 꼭좀부탁드립니다....
>
>
>
> // DLL Unit.........
> //----------------------------------------------
> unit UGetAddr;
>
> interface
> uses
> ................
>
> procedure DllInitGetAddr(DBHand:hDBIDb);StdCall;
> function ExGetAddr(Arg1:PChar):PChar; StdCall;
>
> exports
> DllInitGetAddr,ExGetAddr;
>
> var
> CADataModule: TCustAddrDataModule;
> implementation
> `~~~~~~~~~~
> ~~~~~~~~~
>
>
>
> // DLL Call Unit................
> ===============================
> procedure TForm1.DLLStart;
> begin
> database1.Connected := true;
> hDllInst := LoadLibrary('getAddr.dll');
>
>
> if hDllInst <= 0 then <==== Error 지점
>
>
> Raise Exception.Create('[LoadLibrary Fail] GetLastError reports: '+
> IntToStr(GetLastError));
> try
> @DllInitGetAddr := GetProcAddress(hDllInst,'DllInitGetAddr');
> if Assigned(DllInitGetAddr) then begin
> DllInitGetAddr({Application,Screen,}database1.handle);
> @ExGetAddr := GetProcAddress(hDllInst,'ExGetAddr');;
> if not Assigned(ExGetAddr) then begin
> Raise Exception.Create('cc[GetProcAddress Fail] GetLastError reports: '+
> IntToStr(GetLastError));
> end;
> end else begin
> Raise Exception.Create('[GetProcAddress Fail] GetLastError reports: '+
> IntToStr(GetLastError));
> end;
> except
> Showmessage('Error');
> end;
> end;
>
>
> procedure TForm1.Button1Click(Sender: TObject);
> var
> Arg1 : PChar;
> Arg2 : PChar;
> begin
> FormStart;
> With Query1 do begin
> Open;
> Showmessage('RecordCount = '+IntToStr(RecordCount));
> First;
> While not eof do begin
> Arg1 :=PChar(FieldByName('ev_cust_no').AsString);
> try
> Arg2 := ExGetAddr(Arg1);
> except
> showmessage('Error');
> end;
> RichEdit1.Lines.Add(Arg2);
> Next;
> end;
> end;
> FormEnd;
> end;
>
>
>