Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Import dll procedure exception

Status
Not open for further replies.

f1engineer

Programmer
Aug 23, 2005
2
BG
Dear Sirs
I have a problem to importing procedure from Visual C++ 6.0 dynamic link library:

1. In my Delphi project i do define the imported function as:

StartLogging:procedure(AData: byte);cdecl{$IFDEF WIN32} stdcall {$ENDIF};

2. StartLogging:=GetProcAddress(Handle, 'StartLogging');
Handle - is the handle to the dll that I previously load.

3. When a valid procedure pointer came, I sucessfuly call the function and pass all the requared parameters. But just in the end of procedure where I call StartLogging an exception appear: 'Access violation at address 0012F6FF. Write of address 8C13390D'.

I resolved the problem by inserting an assembler code in the procedure but this is not enaugh safely.

Can anyone help me?
Regards Kamen
 
Don't forget that if any of the parameters are strings they are normally long pointers to an ASCIIZ (ie a PChar)

Hope this helps.
 
In this case there is only one input parameter and it is unsigned char of C++ part that the imported function is implemented and when I call this function I pass variable of type byte that is equivalent of unsigned char

C++ code:
extern "C"__declspec(dllexport)void StartLogging(unsigned char AValue)
{
//body
}

Delphi client:
procedure TForm1.MyDelphiProcedure(TSender: TObject);
var
param:byte;
......
begin
StartLogging:=GetProcAddress(Handle, 'StartLogging');

param:=5;
StartLogging(param);//successful
.......
.......
end;//successful

in project main fail there is:

program Project2;

uses
Forms,
PROJECT1 in 'PROJECT1.pas' {Form1};

{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.//EXCEPTION - 'Access violation at address 0012F6FF. Write of address 8C13390D'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top