Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

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


SampleWrapper.cpp (C++/CLI wrapper)
C++
#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
}


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

C++ application:
C#
#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

}


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
Posted
Updated 28-May-15 5:29am
v2

1 solution

You need to declare it globally because every function has its own scope. A solution would be that you declare some global functions. Like:
C++
bool InitServer();//start up
KinectV2Server::KinectV2* GetServer();//access (in the dll OR for external use)
void ExitServer();//shut down


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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900