在同一解决方案中的应用程序项目中使用DLL项目中的函数和类 [英] Using Functions and Classes from DLL project in Application project in the Same Solution

查看:49
本文介绍了在同一解决方案中的应用程序项目中使用DLL项目中的函数和类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我有一个包含两个项目的解决方案.一个项目是游戏引擎,它是一个DLL.另一个项目是应该使用游戏引擎的应用程序.

我正在尝试测试已编码到应用程序引擎中的某些功能,并且已向项目中添加了必要的包含目录,但是当我构建解决方案时,VS抱怨未解决的外部问题,这是外部问题都在游戏引擎中.

/如何使VS为DLL项目输出.lib文件?如果有.lib文件,我将能够解决此问题.

Hello,

I have a solution that has two projects in it. One project is the game engine, which is a DLL. The other project is an application which is supposed to use the game engine.

I''m trying to test some of the functions I''ve coded into the engine in the application, and I''ve added the necessary include directories to the project, but when I build the solution VS complains about unresolved externals, which are all in the game engine.

/ How do I make VS output a .lib file for the DLL project? I''ll be able to solve this problem if there''s a .lib file.

Thanks in advance!

推荐答案

您是否尝试过将dll项目设置为对应用程序的依赖关系?如果以这种方式进行配置,则dll项目应先编译并创建与该项目相关的任何产品,然后再编译.exe.这应该可以满足您的需求.
Have you tried setting the dll project as a dependency to the application? If you configure it that way, the dll project should compile first and create any products related to that project before compiling the .exe. That should get you what you need.


如果没有.lib文件,这将是一项艰巨的工作.您可以通过调用 LoadLibrary 从应用程序中加载DLL.然后,您需要询问要与 GetProcAddress 调用一起使用的每个函数的函数指针.通过函数指针,您可以调用DLL的函数.

如果DLL包含C ++类对象,则可能只需要询问创建此类对象的函数.然后,将.h文件与类定义一起使用,以调用此类的函数(所有这些都必须是虚拟函数).这样,您需要通过GetProcAddress请求的功能数量相对较少.

开始之前,您可能需要检查游戏引擎DLL是否确实没有可用的.lib文件.
Without a .lib file it''s going to be hard work. You can load the DLL from your application with a call to LoadLibrary. Then you have to ask for a function pointer of each of the functions you want to use with calls to GetProcAddress. Via the function pointers you can then call the functions of your DLL.

If the DLL contains C++ class objects, you probably need only to ask for the functions that create such objects. Then use the .h file with the class definitions to call the functions of such classes (which all need to be virtual functions). That way, the number of functions you need to ask for via GetProcAddress is relatively small.

Before getting started on this you might want to check whether there is really no .lib file available for your game engine DLL.


您可以尝试按照此处概述的步骤进行操作:
如何在没有.OBJ或源代码的情况下创建32位导入库 [
You can try to follow the procedure outlined here:
How To Create 32-bit Import Libraries Without .OBJs or Source[^]


Best regards
Espen Harlinn


这篇关于在同一解决方案中的应用程序项目中使用DLL项目中的函数和类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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