I'm creating a C dll like below.
#ifdef TEST_EXPORTS
#define TEST_API __declspec(dllexport)
#else
#define TEST_API __declspec(dllimport)
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* fun accept an argument status_callback which is a function pointer*/
TEST_API void fun(void(*status_callback)(int));
#ifdef __cplusplus
}
#endif
and fun is implemented as:
void fun(void(*status_callback)(int)) {
status_callback(0);
}
When using this dll on object pascal with delphi xe like below I got a crash with an access violation at the address of the callback function
type
TStatusCallBack = procedure( Value: Integer ); stdcall;
T_fun = procedure(cb : TStatusCallback );
procedure BCallBack( Value: Integer ); stdcall;
begin
BStatus := value;
end;
begin
_fun(BCallBack);
end;
Instantiation code:
DLLHandle := LoadLibrary( ‘mylib.dll’ );
if (DLLHandle > HDLL_ERROR) then
begin
_fun := T_fun(GetProcAddress( DLLHandle, 'fun');
end;
What is the issue? Since I'm a noobie to C any comments??