且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用C ++源代码创建DLL,以及它们在其他来源中的使用方式?

更新时间:2023-09-19 19:39:10

DLL是由C ++源代码创建的,如何在其他源中使用?一个动态链接库,其工作原理与其他库类似,但与您的可执行应用程序无关。在运行时,您可以调用特定的函数来加载DLL并执行其导出的方法。



您可以尝试自己创建一个DLL - 使用visual studio创建一个项目,并指定一个DLL。这将为您的项目创建一些基础构造,例如您的项目的设置来编译DLL,还有一些用于显示方法,对象或变量的基础代码。



现在有很多步骤可以帮助您:查看这里



所以,总结一下:




  • 一个DLL是一个库,您可以在runtim e加载。这是一个非常灵活的插件模型。示例:您可以在运行时以编程方式选择并加载不同的DLL。每个DLL都可以是插件来提供不同的功能。


  • 一个DLL具有入口点。就像您的命令行可执行文件的Main函数是入口点一样,DLL有一个入口点函数,当DLL上的不同事件发生时,如加载,卸载等等,这个函数被调用。


  • 要使用DLL,您必须使用导出的对象或DLL的方法。


  • 当从另一个应用程序调用这些导出的功能时,非常重要的是您匹配兼容类型!另外,请确保调用约定兼容



How are DLLs created out of C++ source code, and how are they used in other sources?

The DLL is a 'Dynamic Link Library' which works a lot like other libraries but is not linked with your executable application. At run time you can call specific functions for loading your DLL and executing its exported methods.

You can try creating a DLL yourself- create a project using visual studio and specify a DLL. This will create some of the base constructs for your project such as settings for your project to compile the DLL and also some base code for exposing methods, objects, or variables.

There are many walk through's to help you at this point: check here.

So, to summarize:

  • A DLL is a library which you can be loaded at runtime. This is a very flexible 'plug-in' model. Example: You can programmatically select and load different DLL at runtime. Each DLL can be a 'plug-in' to provide different functionality.

  • A DLL Has an entry point. Just like your Main function of your command line executable is the entry point, the DLL has an entry point function which is called when different events occur on the DLL such as loading, unloading, and more.

  • To use a DLL you must use the exported objects or methods of the DLL.

  • When Calling these exported functions from another application it is very important that you match compatible types! Also, make sure the calling conventions are compatible