Hi guys

Hi guys,

I am still working on that DLL compiled in VS2015 and I have this declarations in the DLL:

void __cdecl newProc(newProc_callback_t);

/// Callback type
typedef void(__cdecl *newProc_callback_t)();

Now, how do I get access to this?

I have declared a method which receives newProc: TProc as argument:

The method does this:

procedure AssignNewProc(const newProc:TProc);
var
tmpProc: procedure(newP: Pointer); cdecl;
begin
I have already the handler to the DLL
@tmpProc:=GetProcAddress(fHandle,'newProc');
if Assigned(tmpProc) then
tmpProc(@newProc);
end;

When I execute, the call to AssignNewProc(myProc) works nicely but when the DLL calls newProc I get an AV error.

I am pretty sure I mess something up with the pointers.

Can you help please?

Thanks.

Comments

  1. Ondrej Kelle Can MyCallBack be inside a class? Can I declare a procedure in private section with cdecl? or can MyCallback be local to another procedure?

    ReplyDelete
  2. Not a method of a class (which adds a hidden Self parameter to the signature, making it incompatible). Also not a local procedure, as that's kind of a closure, compiler capturing state and juggling with the stack frames. Just a regular procedure.

    ReplyDelete

Post a Comment