在简单的Delphi代码中设置CALLBACK函数时出错 [英] Error in setting a CALLBACK function in a simple Delphi code
本文介绍了在简单的Delphi代码中设置CALLBACK函数时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在delphi代码中设置一个CALLBACK函数,以便从C ++ dll中调用它;截至目前我写了以下代码:
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:
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.
给予错误为:[错误] Project1.dpr(30):不兼容的类型:''指针''和''红衣主教''
任何人都可以帮助我?< br $>
谢谢
It is giving error as :[Error] Project1.dpr(30): Incompatible types: ''Pointer'' and ''Cardinal''
Can any one help me?
Thanks
推荐答案
APPTYPE CONSOLE}
使用
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;
开始
MessageBoxA(0,' delphi',' delphi',MB_OK);
end ;
开始
{ TODO -oUser -cConsole Main:在此处插入代码}
开始
begin
m_hDll:= LoadLibrary(' DLLMsgBox.dll');
fnSetCallback:= GetProcAddress(m_hDll,' DisplayInMessageBox');
fnSetCallback(CallbackProc);
FreeLibrary(m_hDll);
end ;
end ;
end 。
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.
给予错误为:[错误] Project1.dpr(30):不兼容的类型:''指针''和''红衣主教''
任何人都可以帮助我?
谢谢
It is giving error as :[Error] Project1.dpr(30): Incompatible types: ''Pointer'' and ''Cardinal''
Can any one help me?
Thanks
这篇关于在简单的Delphi代码中设置CALLBACK函数时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文