从现有的Linux C ++库创建一个DLL并公开它的类 [英] Create a dll from an existing linux C++ library and expose its classes

查看:61
本文介绍了从现有的Linux C ++库创建一个DLL并公开它的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在C#程序中使用Linux的C ++库(我有源​​代码)。



要做到这一点,我创建了一个Visual Studio 2017版本15.6.3中的C ++ DLL项目。我已经复制了Visual Studio项目中的所有源代码,并且我编译它没有任何错误。但是知道,我不知道我要怎么做才能在dll中公开它的所有类




我找到了文件dllmain。带有此内容的cpp:

I need to use a C++ library for Linux (I have its source code) in a C# program.

To do it I have created a C++ DLL project in Visual Studio 2017 version 15.6.3. I have copied all the source code in the Visual Studio project, and I have compiled it without any error. But know, I don't know what I have to do to expose all of its classes in the dll.

I have found the file dllmain.cpp with this content:

    // dllmain.cpp : Defines the entry point for the DLL application.
    #include "header.h"
    
    BOOL APIENTRY DllMain( HMODULE hModule,
                           DWORD  ul_reason_for_call,
                           LPVOID lpReserved
                         )
    {
        switch (ul_reason_for_call)
        {
        case DLL_PROCESS_ATTACH:
        case DLL_THREAD_ATTACH:
        case DLL_THREAD_DETACH:
        case DLL_PROCESS_DETACH:
            break;
        }
        return TRUE;
    }

我认为这是我必须添加一些东西以暴露所有类的地方(或者我可能是错误)。



我发现文章

演练:创建并使用您自己的动态链接库,但它没有说关于课程或如何曝光的任何内容。



我是否必须在dllmain.cpp或其他任何地方添加内容(例如extern"C"LIBGE_API)让我使用原始libGE中声明的所有类?



注意:我不是在问如何使用dll在C#中。我知道怎么做。



顺便说一句,我正在尝试使用它的项目是
libGE


I think this is the place where I have to add something to expose all the classes (or maybe I'm wrong).

I have found the article
Walkthrough: Create and use your own Dynamic Link Library, but it doesn't say anything about classes or how to exposed.

Do I have to add something in dllmain.cpp or anywhere else (like extern "C" LIBGE_API) to let me use all the classes declared in original libGE?

NOTE: I'm not asking how to use a dll in C#. I know how to do that.

By the way, the project I'm trying to use it is libGE.

推荐答案


我需要在C#程序中使用Linux的C ++库(我有它的源代码)。



要做到这一点我已经创建了一个C ++ DLL项目......

I need to use a C++ library for Linux (I have its source code) in a C# program.

To do it I have created a C++ DLL project ...

由于你想要公开的代码是"类",我认为最好的选择是要设计你最简单的理想化C#

界面(好像它是C#),实现它作为一个C ++ / CLI项目,使C#界面尽可能无缝,并有$
C ++ / CLI代码使用您拥有的本机C ++库代码。

As the code you appear to want to expose is "classes", I think the neatest option would be to design your simplest idealised C#
interface (as though it is C#), implement that as a C++/CLI project to make the C# interface as seamless as possible, and have the
C++/CLI code use the native C++ library code you have.

Dave


这篇关于从现有的Linux C ++库创建一个DLL并公开它的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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