D
DavidT
Hello,
at first, exuse if the following question is simple to solve, but i
normaly coding with C# and now have to use C++/CLI for one project.
My Problem is that i have to use a native c++ sdk to read pictures
from ip cameras. I get the native c++ decoder worked so far and now
try to send callbacks from unmanaged to managed code, to signal wenn a
picture is fully received.
To get a first view on that area i implemented a little test where i
extract a pointer from a delegate and sending the pointer to unmanaged
code. In the unmanaged function i use the callbackfunction (after
filling an array), jump back to to managed code and marshaling the
generated array to the managed world.
That little example is working fine in debugmode but as soon as i
running in releasemode the programm crashs and i dont know why.
So, at first my Code:
When it runs in release mode, the callbackfunction is normally called
but after finishing the function, he is called again. On the
Marshal::Copy(...)-Line then the programm is crashing without any
exception...
I hope someone of you find the mistake, i have no idea anymore...
Thanks in advance
Greets,
David
at first, exuse if the following question is simple to solve, but i
normaly coding with C# and now have to use C++/CLI for one project.
My Problem is that i have to use a native c++ sdk to read pictures
from ip cameras. I get the native c++ decoder worked so far and now
try to send callbacks from unmanaged to managed code, to signal wenn a
picture is fully received.
To get a first view on that area i implemented a little test where i
extract a pointer from a delegate and sending the pointer to unmanaged
code. In the unmanaged function i use the callbackfunction (after
filling an array), jump back to to managed code and marshaling the
generated array to the managed world.
That little example is working fine in debugmode but as soon as i
running in releasemode the programm crashs and i dont know why.
So, at first my Code:
Code:
#include <iostream>
#pragma unmanaged
class umTest
{
private:
unsigned char * data;
public:
void Caller(int size, void callback(int, unsigned char*))
{
data = new unsigned char[size];
for(int i = 0; i < size; i++)
data[i] = i;
callback(size,data);
};
};
#pragma managed
#pragma managed
using namespace System;
using namespace System::Runtime::InteropServices;
public delegate void callback(int, unsigned char*);
ref class mTest
{
private:
array<unsigned char> ^destination;
int size;
public:
mTest()
{
callback ^d = gcnew callback(this,&mTest::callTest);
IntPtr ptr = Marshal::GetFunctionPointerForDelegate(d);
umTest *umT = new umTest();
[B]umT->Caller(5,
static_cast<void (__cdecl *)(int, unsigned char*)>
(ptr.ToPointer()));
this->print();
}
void callTest(int size, unsigned char* test)
{
this->size = size;
destination = gcnew array<unsigned char>(size);
Marshal::Copy(IntPtr(test),destination,0,size);
delete[](test);
test = NULL;
this->print();
};
void print()
{
for(int i = 0; i<size; i++)
Console::WriteLine("destination[{0}]={1}",i,destination[i]);
};
};
but after finishing the function, he is called again. On the
Marshal::Copy(...)-Line then the programm is crashing without any
exception...
I hope someone of you find the mistake, i have no idea anymore...
Thanks in advance
Greets,
David