如何正确声明也在本地使用的导出函数? [英] How I properly declare an exported function that is also used locally?

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

问题描述


我在EXE中有一个FuncA().从EXE内部和DLL内部调用FuncA().因此,我为FuncA()编写了一个回调函数,以便DLL可以对其进行调用.因此,我需要导出FuncA()以便从DLL内部获取函数地址.

Hi,
I have a FuncA() inside the EXE. FuncA() is called from inside the EXE and from inside a DLL. Therefore, I wrote a callback function for FuncA() so that the DLL can call to it. Hence, I need to export FuncA() so that I can get the function address from inside the DLL.

declspec(dllexport) void FuncA(){ return; }//declspec(dllexport) is to be able to get the function address.


但是,
由于FuncA()也是从DLL和EXE内部调用的,因此
我的问题是EXE中的funcA()声明.该声明将由EXE中的函数使用.


However,
Because FuncA() is called from DLL AND from inside the EXE as well,
my problem is the declaration of funcA() inside the EXE. That declaration will be used by the functions inside the EXE.

void FuncA();//If I write it this way I get the following error:
error C2375: ''FuncA'' : redefinition; different linkage


而且,


And,

declspec(dllimport) void FuncA();//If I write it this way, I get the following warning and the program hangs.
warning LNK4049: locally defined symbol _FuncA imported


如何编写正确的声明?
注意:Windows,Visual Studio 2008,Standard-C


How do I write the proper declaration?
Note: Windows, Visual Studio 2008, Standard-C

推荐答案

据我所知,您需要在任何hader文件中使用预处理器指令,用于声明您的功能.

As far as I understand your comments, you need to use pre-processor directives in any hader file using to declare your function.

// in AnyHaderFile.h for FuncA() declaration
#ifdef _WITHINDLL_
declspec(dllimport) void FuncA();
#else
declspec(dllexport) void FuncA();
#endif

// in your DLL file, include it with after definition of _WITHINDLL_
#define _WITHINDLL_
#include "AnyHaderFile.h"

// in your EXE file, you just need to include without _WITHINDLL_

#include "AnyHaderFile.h"



在这种特殊情况下,该功能是在EXE中实现的(与往常不同,不是在DLL中实现).

希望我理解正确.



In this particual case, the function is implemented in EXE (not in DLL unlike as usual).

I hope, I understand right.


我不确定我是否正确理解了您的问题,但是我认为您在exe文件和dll中声明了FuncA吗?而在您的exe中,您希望能够从exe本身和dll调用FuncA?
最简单的解决方案似乎是只重命名其中之一,以使它们不再冲突.
I''m not sure I understand your problem correctly, but I think you have FuncA declared inside your exe file and in your dll? And in your exe you want to be able to call both the FuncA from the exe itself and the dll?
The easiest solution seems to be to just rename one of them so they no longer conflict.


这篇关于如何正确声明也在本地使用的导出函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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