C++/C# DLL - Call functions - procedure - C++/C# Wrapper

  • Thread starter Thread starter Markus Freitag
  • Start date Start date
M

Markus Freitag

Guest
Hello,
How can I create a global object from C++?
String^ str2 = gcnew String(result);
Do I have to release the string at gwnew again?
Is there a way to debug C++ into the C# class DLL? If so, how? Which settings are necessary?

#include "stdafx.h"
#include "..\CSharpCalcWrapper\CSharpCalcWrapper.h"

int main()
{
int x = Calc_Add(1, 2);
int y = Calc_Sub(20, 10);

for (int i = 0; i < 100; i++)
Calc_Send_Result(i + 1, "TestFromC++");

std::cout << "x is " << x << ", y is " << y << std::endl;

return 0;
}

/// Wrapper
#include "stdafx.h"
#include "CSharpCalcWrapper.h"
#include "atlstr.h"

#include <string>
#include <iostream>
using namespace System;
using namespace std;

using namespace CSharpCalculate;

//extern Calc GlobalCalc;
CALCWRAP_API int Calc_Add(int a, int b)
{
Calc obj;
return obj.Add(a, b);
}

CALCWRAP_API int Calc_Sub(int a, int b)
{
Calc obj;
return obj.Sub(a, b);
}

CALCWRAP_API void Calc_Send_Result(int index, CString result)
{
Calc obj;

String^ str2 = gcnew String(result);

obj.SendResult(index, str2);
//str2.release
}

This way is for me not possible
Here I have own object for all functions.
int main()
{
CSharpCalculate::Calc^ c = gcnew CSharpCalculate::Calc();

int x = c->Add(1, 2);
int y = c->Sub(20, 10);

Regards Markus

Continue reading...
 
Back
Top