Click here to Skip to main content
15,885,029 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Hi, I want to set up a CALLBACK function in a delphi code so that from a C++ dll I can call it; As of now I wrote following code:

Delphi
program Project1;

{$APPTYPE CONSOLE}

uses
  Windows;
var
    fnSomeDllMethod:procedure() cdecl;
    m_hDll: HMODULE;
type
TCALLBACKPROC = function(arg:Pointer):HRESULT stdcall;
type
TSetCallbackFunc = procedure(_proc:TCALLBACKPROC) cdecl;

var
fnSetCallback:TSetCallbackFunc;

function CallbackProc(wEvent:DWORD;arg:Pointer;pParam:Pointer):HRESULT stdcall;
begin
         MessageBoxA(0,'delphi', 'delphi',MB_OK);
end;

begin
  { TODO -oUser -cConsole Main : Insert code here }

  begin
      begin
        m_hDll := LoadLibrary('DLLMsgBox.dll');
        fnSetCallback := GetProcAddress(m_hDll,'DisplayInMessageBox');
        fnSetCallback(CallbackProc);
        FreeLibrary(m_hDll);
      end;
  end;

end.


It is giving error as :[Error] Project1.dpr(30): Incompatible types: 'Pointer' and 'Cardinal'

Can any one help me?

Thanks
Posted
Comments
iDebD 3-Apr-13 13:58pm    
I am using delphi 7 simple console application
Sergey Alexandrovich Kryukov 3-Apr-13 14:13pm    
The problem is quite simple, but you did not show this like of code; there is no any "Cardinal" case in your sample. Just make sure you have matching types.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900