CLI包装器中全局声明C#dll

CLI包装器中全局声明C#dll

本文介绍了如何在C ++ / CLI包装器中全局声明C#dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了用于调用C#dll方法和事件的C ++ / CLI包装器。我在C ++ / CLI包装器项目中引用了C#dll。我调用了由colorinitialize()和colorclientconnect()组成的connect1方法。从C#dll调用。以下代码用于在C ++ / CLI包装器中调用C#dll。



NativeInterface.h



I have created C++/CLI wrapper for calling C# dll methods and events.I have referenced C# dll in the C++/CLI wrapper project.I have called connect1 method which consists of colorinitialize() and colorclientconnect() both have to be called from C# dll.The following code i have used for calling C# dll with in C++/CLI wrapper.

NativeInterface.h

extern "C"{
   __declspec(dllexport) const char*  Connect1(char* str, int port);
    __declspec(dllexport)  const char*  Test(char* str, int port);
    };





SampleWrapper.cpp(C ++ / CLI包装器)



SampleWrapper.cpp (C++/CLI wrapper)

#include "NativeInterface.h"
namespace Wrapper
{
#ifdef __cplusplus
extern "C"
{
#endif

            __declspec(dllexport)  const char*  Test(char* str, int port)
            {

                KinectV2Server::KinectV2 c1;

                c1.GetBytes();
                return str;
            }

            //String tmp;

            __declspec(dllexport)  const char*  Connect1(char* str, int port)
            {
                  KinectV2Server::KinectV2 c1;

                c1.ColorInitialize();
                c1.ColorClientConnect(gcnew System::String(str));


                return  str;
            }

        #ifdef __cplusplus
}
#endif
}





之后我将在另一个C ++应用程序中调用此C ++ / CLI包装器,



C ++应用程序:



After that i will call this C++/CLI wrapper in another C++ application like this,

C++ application:

#include "SampleCPlusApps.h"
#include <math.h>
#include "Time.h"
#include "NativeInterface.h"

SampleCPlusApps::SampleCPlusApps(void)
{
    float smoothing = 0.7f;  //0.25f        // [0..1], lower values closer to raw data
    float correction = 0.3f; //0.25f        // [0..1], lower values slower to correct towards the raw data
    float prediction = 1.00f;  //0.25f       // [0..n], the number of frames to predict into the future
    float jitterRadius =  1.0f; // 1.03f;     // The radius in meters for jitter reduction
    float maxDeviationRadius = 1.0f;; //0.05f;// The maximum radius in meters that filtered positions are allowed to deviate from raw data

    fde.Init(smoothing, correction, prediction, jitterRadius, maxDeviationRadius);
    //initialization();

    //const char* test1;
    //test1= ("Hai", 1);
}

int SampleCPlusApps::Initialization()
{
const char* test;
    test = Connect1("197.1.1.1",1524); // my wrapper class is called here

}





所以从上面的代码中,我对SampleWrapper.cpp(C ++ / CLI包装器)有疑问。我已经声明了我的c#dll(KinectV2Server :: KinectV2) c1)方法内部。



但是我需要全局声明c#dll,以便它可以在两个函数中使用,即connect1和test。



请帮助我解决问题。



谢谢



so from my above code, i have doubt in SampleWrapper.cpp (C++/CLI wrapper).Here i have declared my c# dll(KinectV2Server::KinectV2 c1) inside the method.

But i need to declare the c# dll globally, so that it can be used in both functions namely connect1 and test.

Please assist me to fix the issue.

Thanks

推荐答案

bool InitServer();//start up
KinectV2Server::KinectV2* GetServer();//access (in the dll OR for external use)
void ExitServer();//shut down





对于GetServer()可以很方便地使用void *以避免一些hazzle。



for the GetServer() could be handy to use a void* to avoid some hazzle.


这篇关于如何在C ++ / CLI包装器中全局声明C#dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 01:10