从DLL内部调用EXE函数 [英] Calling to an EXE function from inside a DLL

查看:102
本文介绍了从DLL内部调用EXE函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我需要从DLL位置调用EXE内的几个函数.而且,我还需要从DLL访问EXE内的某些变量.下面是错误列表,可能根本没有帮助,但无论如何都附加了它.
我通过使用* .def文件,dllimport和其他依赖项执行了相反的操作(exe-> dll).而且,现在我陷入了另一种困境.
注意:Micros ** t Visual Studio 2008 pro,Standard-C.

Hi,
I need to call to SEVERAL functions that are inside the EXE from a DLL location. And, I also will need to access some of the variables found inside the EXE from the DLL. Below is the error list, probably not helpful at all, but attached it anyway.
I did the opposite (exe->dll) by using *.def files and dllimport and additional dependencies. And, now I am stuck needing to the other way around.
note: Micros**t Visual Studio 2008 pro, Standard-C.

3>sv_bot.obj : error LNK2019: 未解決の外部シンボル _SV_GentityNum が関数 _SV_BotAllocateClient で参照されました。
3>sv_bot.obj : error LNK2001: 外部シンボル "_svs" は未解決です。
3>sv_bot.obj : error LNK2001: 外部シンボル "_sv_maxclients" は未解決です。
3>sv_bot.obj : error LNK2001: 外部シンボル "_botlib_export" は未解決です。
3>sv_bot.obj : error LNK2019: 未解決の外部シンボル _Cvar_Get が関数 _BotDrawDebugPolygons で参照されました。
3>sv_bot.obj : error LNK2019: 未解決の外部シンボル _SV_Trace が関数 _BotImport_Trace で参照されました。
3>sv_bot.obj : error LNK2019: 未解決の外部シンボル _SV_ClipToEntity が関数 _BotImport_EntityTrace で参照されました。
3>sv_bot.obj : error LNK2019: 未解決の外部シンボル _SV_PointContents が関数 _BotImport_PointContents で参照されました。
3>sv_bot.obj : error LNK2019: 未解決の外部シンボル _SV_inPVS が関数 _BotImport_inPVS で参照されました。
3>sv_bot.obj : error LNK2019: 未解決の外部シンボル _CM_EntityString が関数 _BotImport_BSPEntityData で参照されました。
3>sv_bot.obj : error LNK2019: 未解決の外部シンボル _CM_ModelBounds が関数 _BotImport_BSPModelMinsMaxsOrigin で参照されました。
3>sv_bot.obj : error LNK2019: 未解決の外部シンボル _CM_InlineModel が関数 _BotImport_BSPModelMinsMaxsOrigin で参照されました。
3>sv_bot.obj : error LNK2019: 未解決の外部シンボル _Z_TagMalloc が関数 _BotImport_GetMemory で参照されました。
3>sv_bot.obj : error LNK2019: 未解決の外部シンボル _Z_Free が関数 _BotImport_FreeMemory で参照されました。
3>sv_bot.obj : error LNK2019: 未解決の外部シンボル _Hunk_Alloc が関数 _BotImport_HunkAlloc で参照されました。
3>sv_bot.obj : error LNK2019: 未解決の外部シンボル _Hunk_CheckMark が関数 _BotImport_HunkAlloc で参照されました。
3>sv_bot.obj : error LNK2019: 未解決の外部シンボル _SV_ExecuteClientCommand が関数 _BotClientCommand で参照されました。
3>sv_bot.obj : error LNK2019: 未解決の外部シンボル _VM_Call が関数 _SV_BotFrame で参照されました。
3>sv_bot.obj : error LNK2001: 外部シンボル "_gvm" は未解決です。
2>   ライブラリ ..\..\build\quake3_release\ioquake3.lib とオブジェクト ..\..\build\quake3_release\ioquake3.exp を作成中
3>sv_bot.obj : error LNK2019: 未解決の外部シンボル _GetBotLibAPI が関数 _SV_BotInitBotLib で参照されました。
3>sv_bot.obj : error LNK2019: 未解決の外部シンボル _FS_Seek が関数 _SV_BotInitBotLib で参照されました。
3>sv_bot.obj : error LNK2019: 未解決の外部シンボル _FS_FCloseFile が関数 _SV_BotInitBotLib で参照されました。
3>sv_bot.obj : error LNK2019: 未解決の外部シンボル _FS_Write が関数 _SV_BotInitBotLib で参照されました。
3>sv_bot.obj : error LNK2019: 未解決の外部シンボル _FS_Read2 が関数 _SV_BotInitBotLib で参照されました。
3>sv_bot.obj : error LNK2019: 未解決の外部シンボル _FS_FOpenFileByMode が関数 _SV_BotInitBotLib で参照されました。
3>sv_bot.obj : error LNK2019: 未解決の外部シンボル _Z_AvailableMemory が関数 _SV_BotInitBotLib で参照されました。
3>sv_bot.obj : error LNK2019: 未解決の外部シンボル _Z_Malloc が関数 _SV_BotInitBotLib で参照されました。
3>sv_bot.obj : error LNK2019: 未解決の外部シンボル _Cvar_VariableIntegerValue が関数 _SV_BotInitBotLib で参照されました。
3>..\..\build\game_release\qagamex86.dll : fatal error LNK1120: 外部参照 28 が未解決です。
2>LINK : warning LNK4098: defaultlib ''LIBCMT'' は他のライブラリの使用と競合しています。/NODEFAULTLIB:library を使用してください。
3>ビルドログは "file://c:\Documents and Settings\yasir\デスクトップ\ioquake3dev\ioquake3dev - sandbox\build\game_release\BuildLog.htm" に保存されました。
3>game - エラー 29、警告 0
2>LINK : warning LNK4199: /DELAYLOAD:OleAcc.dll は無視されます。OleAcc.dll にインポートがありません。
2>cm_patch.obj : error LNK2019: 未解決の外部シンボル _BotDrawDebugPolygons が関数 _CM_DrawDebugSurface で参照されました。
2>sv_client.obj : error LNK2019: 未解決の外部シンボル _SV_BotFreeClient が関数 _SV_DropClient で参照されました。
2>sv_game.obj : error LNK2001: 外部シンボル "_SV_BotFreeClient" は未解決です。
2>sv_game.obj : error LNK2019: 未解決の外部シンボル _SV_BotGetConsoleMessage が関数 _SV_GameSystemCalls で参照されました。
2>sv_game.obj : error LNK2019: 未解決の外部シンボル _SV_BotGetSnapshotEntity が関数 _SV_GameSystemCalls で参照されました。
2>sv_game.obj : error LNK2019: 未解決の外部シンボル _SV_BotLibShutdown が関数 _SV_GameSystemCalls で参照されました。
2>sv_game.obj : error LNK2019: 未解決の外部シンボル _SV_BotLibSetup が関数 _SV_GameSystemCalls で参照されました。
2>sv_game.obj : error LNK2019: 未解決の外部シンボル _BotImport_DebugPolygonDelete が関数 _SV_GameSystemCalls で参照されました。
2>sv_game.obj : error LNK2019: 未解決の外部シンボル _BotImport_DebugPolygonCreate が関数 _SV_GameSystemCalls で参照されました。
2>sv_game.obj : error LNK2019: 未解決の外部シンボル _SV_BotAllocateClient が関数 _SV_GameSystemCalls で参照されました。
2>sv_game.obj : error LNK2001: 外部シンボル "_bot_enable" は未解決です。
2>sv_init.obj : error LNK2019: 未解決の外部シンボル _SV_BotFrame が関数 _SV_SpawnServer で参照されました。
2>sv_main.obj : error LNK2001: 外部シンボル "_SV_BotFrame" は未解決です。
2>sv_init.obj : error LNK2019: 未解決の外部シンボル _SV_BotInitBotLib が関数 _SV_Init で参照されました。
2>sv_init.obj : error LNK2019: 未解決の外部シンボル _SV_BotInitCvars が関数 _SV_Init で参照されました。
2>..\..\build\quake3_release\ioquake3.exe : fatal error LNK1120: 外部参照 13 が未解決です。
2>ビルドログは "file://c:\Documents and Settings\yasir\デスクトップ\ioquake3dev\ioquake3dev - sandbox\build\quake3_release\BuildLog.htm" に保存されました。
2>quake3 - エラー 16、警告 2
========== ビルド: 0 正常終了、2 失敗、2 更新不要、1 スキップ ==========

推荐答案

您可以以与DLL相同的方式从exe导出函数.

如果从exe导出函数,则编译器还将生成一个DLL或另一个exe可以链接的.lib文件.

我通常使用__declspec(dllexport)而不是.def文件,但是两者都可以正常工作.


使用exe中的变量要复杂一些.
您需要做的就是为每个变量设置2个函数,其中1个用于获取值,1个用于设置值.
You can export functions from an exe in the same way you would from a DLL.

If functions are exported from the exe the compiler will also generate a .lib file that a DLL or another exe can link against.

I generally use __declspec(dllexport) rather than .def files, but both work just as well.


To use the variables from the exe is a little more complicated.
All you need to do is make 2 functions for each variable, 1 to get the value and 1 to set it.


您无法以与dll.如果您需要在exe中访问函数,我认为您需要通过COM公开它们.
You cannot link an exe file in the same way you would a dll. If you need to access functions within an exe I think you will need to have them exposed via COM.


coffeenet说:
coffeenet says:
变量如何?有没有办法从dll到达EXE端的变量?
How about variables? Is there a way to reach a variable on the EXE side from the dll?



据我所知,无法在DLL和EXE之间访问变量,您可以尝试



Variables cannot be accessed between a DLL and an EXE as far as I know, you could try

//some_exe_file.cpp
int nMyVar = 0;

//some_dll_file.cpp
extern int nMyVar;



那应该工作.否则,您将需要定义一个函数来获取/设置变量
在C ++中,您只能使用1个通过引用返回的函数



That should work. Otherwise you will need to define a function to get/set the variables
In C++ you could use just 1 function that returns by reference

//some_exe_file.cpp
int nMyVar = 0;
int &GetMyVar() {
	return nMyVar;
}

//some_dll_file.cpp
int &nMyVar = GetMyVar();



或者在C语言中,您将需要单独的get和set函数



Or in C you would need separate get and set functions

//some_exe_file.cpp
int nMyVar = 0;
int GetMyVar() {
	return nMyVar;
}
void SetMyVar(int nNewVal) {
	nMyVar = nNewVal;
}

//some_dll_file.cpp
int nMyVar = GetMyVar();
SetMyVar(2);



coffeenet说:



coffeenet says:

顺便说一句,我是否需要两次声明这些导出的函数(一次执行dellexport,一次不执行)?
Btw, do I need to declare those exported functions twice(once with dellexport, once without)?



不能.与DLL一样,您可以在导出函数的模块中使用导出的函数.
没有什么特别的事情要做.编译器将进行所需的任何更改,您将像使用其他任何功能一样使用它们.



No. As with DLLs you can use the exported functions inside the module that is exporting them.
There is nothing special to do. The compiler will make any changes needed, and you use them as you would use any other function.


这篇关于从DLL内部调用EXE函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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