How to use managed c++ classes/features in C#
This was working very well, but since .cpp file got overwritten with what was in .h file, everything just went crazy. I make a dll in managed C++ in VS2005.
.h file:
Code:
namespace DetectorInterface {
public ref class DetInt
{
public:
__declspec (dllexport) bool nonsense ();
};
}
.cpp file:
Code:
namespace DetectorInterface {
public ref class DetInt
{
bool nonsense ()
{
return false;
}
};
}
I have added a C# program to the DLL, and applied using DetectorInterface.
When can I do DetInt detector = new DetInt ();. Everything hurt well so far. But I could not find a feature that is defined.
Re: How to use managed c++ classes/features in C#
Code:
bool DetectorInterface :: DetInt :: nonsense ()
{
return false;
}
Re: How to use managed c++ classes/features in C#
OK, tried again. Here is .h file from a c++ class library project.
Code:
// DLLTest.h
#pragma once
using namespace System;
namespace DLLTest {
public ref class MostlyHarmless
{
public:
int DLLTest::MostlyHarmless::LifeUniverseAndEverything()
{
return 42;
}
};
}
Thank you!
But then comes a small challenge.
Code:
int* getImage ()
{
int* arr = new int [7744];
// Do stuff here ...
return arr;
How do I handle it in C# program?
Re: How to use managed c++ classes/features in C#
int* getImage ()
{
int* arr = new int [7744];
image = GetImage (ctr);
return (int*) image -> data;
}
image is a struct which contains the image data, as an array.
Here's some code that uses min .Dll.
Code:
unsafe
{
int* imagePtr;
int[,] image = new int [88, 88];
imagePtr = detector.getImage ();
image = arrayTo2DArray (imagePtr);
}