怎么使用函数指针?

tear_pearl 2005-03-29 03:59:14
WINXP,VC6
在一个DLL中存在函数int function(int, int );
要动态调用的话
是不是如下:
typedef int(*f)(int,int);
f newF;
hModule = LoadLibrary(libraryName);
newF = (f)GetGetProcAddress(hModule,"function");

可是在f newF这一句编译不过去,提示
illegal use of this type as an expression 和
missing ';' before identifier 'newF'等

这是什么问题?
...全文
175 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
tear_pearl 2005-03-30
  • 打赏
  • 举报
回复
感谢各位!!
gnixemos 2005-03-30
  • 打赏
  • 举报
回复
建议你贴多一点代码,上面的代码是没有问题的(除了GetGet)

Cline 2005-03-29
  • 打赏
  • 举报
回复
//newF = (f)GetGetProcAddress(hModule,"function");
newF = (f)GetProcAddress(hModule,"function");//多了一个Get
tear_pearl 2005-03-29
  • 打赏
  • 举报
回复
象这个:
typedef int(FUNCTION) (HWND);
参数明显错误嘛……大哥

由于我现在的这个工程类型还是一个DLL
是不是这个有问题?
DLL里还可以再调DLL吗?
sjcode 2005-03-29
  • 打赏
  • 举报
回复
dll:
extern "C" __declspec(dllexport) int function(int a,int b)

usage:
HINSTANCE hDllInstance;
typedef int(FUNCTION) (HWND);
FUNCTION *pFunction = NULL;

VERIFY(hDllInstance= LoadLibrary("yourdll.dll"));

VERIFY(pFunction = (FUNCTION*)GetProcAddress(hDllInstance,"function"));

pFunction(10,20);

FreeLibrary(hDllInstance);

记得给分哦~~
tear_pearl 2005-03-29
  • 打赏
  • 举报
回复
f也没有定义过
tear_pearl 2005-03-29
  • 打赏
  • 举报
回复
不是这个问题……

现在如果我new一个新的项目,写入上面的代码
可以编译通过
但在当前项目中,就不行……
晕了
gnixemos 2005-03-29
  • 打赏
  • 举报
回复
typedef int(*f)(int,int);
原来写的没有问题阿

除非
f已经定义过了
DentistryDoctor 2005-03-29
  • 打赏
  • 举报
回复
typedef int(*f)(int,int);

int 和 ( 之间应该有一个括号
=>
typedef int (*f)(int,int);

15,473

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧