如何使用函数指针? [英] How to use function pointers?

查看:131
本文介绍了如何使用函数指针?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好:-)



i有以下问题(我认为这是一个函数指针问题)



i必须在程序中设置DLLSPLIT



DLLSPLIT定义如下:



typedef int(WINAPI DLLSPLIT)(LPSTR);



i必须这样做:



DLLSPLIT * dllsplit = ....(这里写什么????)



i尝试定义一个函数:



int foo(LPSTR bla)

{

//做点什么

}



然后是dllsplit =&foo;



但这不起作用....



有人可以帮助我吗?

hi all:-)

i have the following Problem (i think it is a function pointer Problem)

i have to set in a Programm "DLLSPLIT"

DLLSPLIT is defined as follows:

typedef int (WINAPI DLLSPLIT) (LPSTR);

i have to do:

DLLSPLIT* dllsplit= .... (what to write here????)

i tried define a function:

int foo(LPSTR bla)
{
//do something
}

and then dllsplit= &foo;

but that doesnt work....

can someone help me?

推荐答案

鉴于WINAPI定义的出现,可能是调用约定不匹配的问题(参见这里 [ ^ ]例如)但没有更详细的关于它如何不起作用我们无法帮助。
Given the appearance of the WINAPI define, it's likely a matter of calling convention mismatch (see here[^] for instance) but without more detail about exactly how it "doesn't work" we can't help.


请发布给出的确切错误消息由编译器。



请注意,C / C ++函数的默认调用约定是__cdecl,您可能希望将foo定义为



Please post the exact error message given by the compiler.

Note that the default calling convention for C/C++ functions is __cdecl, you probably want to define foo as

int __stdcall foo(LPSTR bla)





这是指定为WINAPI的指针的要求。



还要注意,如果你在一个类中,那么foo应该是静态的并且声明为__stdcall,因为在类中,defualt调用约定是__thiscall。



或者,作为其他用户如上所述,



that is the requirement for the pointers declared as WINAPI.

Note also that if you're in a class then foo should be static and declared as __stdcall, because in classes the defualt calling convention is __thiscall.

Or, as the other users said above,

int WINAPI foo (LPSTR bla)



所有WINAPI只是__stdcall的定义


afer all WINAPI is just a define for __stdcall


这篇关于如何使用函数指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆