1

I have created a dll in vs2019 c++. It has some exported function, and it has to call back a function in a specific event. It is imported in a Delphi project (it is written by another person).

Evertyhing works well in x86, but it gives an Access violation error on the callback in x64 (OnEvent()).

I tried to set the calling convention, but it isn't worked.

What should i do?

typedef void (__cdecl *EventCallback)();

extern EventCallback OnEvent = NULL;


extern "C" {
    __declspec(dllexport) void  __cdecl SetEventCallback(EventCallback func);
    __declspec(dllexport) void  __cdecl FireEvent();
}

extern void __cdecl SetEventCallback(EventCallback func) {
    OnEvent = func;
}

extern void __cdecl FireEvent() {
    if (OnEvent)
        OnEvent();
}
Gerhen
  • 21
  • 4
  • 1
    Unfortunately without knowing the calling code this will be extremely difficulty to debug. In most cases this is either a function signature issue or a calling convention issue (which should be less an issue on x86-64 as there are only two). – Mgetz Jul 14 '21 at 12:42
  • It looks like this [maybe a delphi issue](https://stackoverflow.com/q/10162749) – Mgetz Jul 14 '21 at 17:00
  • Yes i understand it is hard without delphi, but i can't get that yet. we checked the stdcall, cdecl, fastcall conventions and all the same result. checked the delphi issue you linked, and now use only functions, but the result is the same – Gerhen Jul 16 '21 at 13:05

0 Answers0