本文介绍了从Visual C ++ DLL导出非托管类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用Visual C ++ 2008创建DLL时,我有几个选择。我可以创建一个类库,我明白实际上会给我一个使用C ++的CLI(托管)扩展的.Net库。



因为我不想要这个,我假设我需要一个静态的.LIB文件链接到另一个Visual C ++ Windows可执行项目中,而是选择Win32 Project,在应用程序设置面板上指定一个C ++ (没有MFC)DLL。



这将创建一个.cpp文件的项目,该文件应该是我定义的地方DLL应用程序的导出函数。



这似乎也不是我想要的。基本上,我正在寻找的是本机C ++的等价物,在C#.NET中将是一个类库程序集。我想将一些类打包到DLL中,然后通过包含DLL项目头文件并链接到.LIB来解析引用,然后使用.EXE项目使用DLL的类



通常这样做的方法是什么?

解决方案

你做的正确。您需要的是使用 __declspec(dllexport)

When creating a DLL with Visual C++ 2008 I have a couple of choices. I can create a "Class Library", which I understand will actually give me a .Net Library that uses the CLI (managed) extenstion of C++.

Since I don't want that, and I assumed that I need a static .LIB file to link into another Visual C++ windows executable project, I choose instead "Win32 Project" and, on the Application Settings panel, specify a C++ (no MFC) DLL.

This will create a project with a .cpp file which is supposed to be where I define "the exported functions for the DLL application".

This doesn't seem to be what I want either. Basically, what I'm looking for is the native C++ equivalent of what would, in C# .NET be a class library assembly. I want to package some classes into a DLL, then have a .EXE project use the DLL's classes by including the DLL project header files and link with a .LIB to resolve references.

What's the usual way of doing this?

You're doing it right. What you'll need is to mark your classes with __declspec(dllexport) to make them available from outside the project. When you build the project, you'll generate both a .DLL and a .LIB.

这篇关于从Visual C ++ DLL导出非托管类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 12:53