Memory access error when calling a C ++ function from managed C # code
I have a managed C # program that calls a function in an unexplored C ++ dll. I am getting an error. I debug tirelessly but can't seem to find a solution. Please advise me to pass the correct data format from C # to the C ++ callable function.
Here's what I have:
Mistake:
" at Frame_Processor.ProcessFrames(Frame_Processor* , SByte* , SByte* , Int32 , SByte* ) "
***-- this is the unmanged C++ function that is called.***
" at Frame_Processor_Wrapped.ProcessFrames(String framesPath, String datasetPath, Int32 frameCount, String keyName)"
***-- this is the manged function that called it.***
it seems that the format of the arguments is the problem. SByte * / string. Please advise.
NEW EDIT:
C # (managed code)
static void Main(string[] args)
{
//test
string id = "abcd";
string in = "C:\\input\\";
string out = "C:\\output";
int count = 10;
Frame_Processor_Wrapped fp = new Frame_Processor_Wrapped();
fp.ProcessFrames(in, out, count, id);
}
C ++ / CLI Code (with marshaling) - AKA Frame_Processor_Wrapped
void Frame_Processor_Wrapped::ProcessFrames(System::String^ in, System::String^ out, int count, System::String^ id)
{
StringConversion ^convert = gcnew StringConversion();
//convert System.String to char*
char* in_char= convert->myStringToChar(in);
char* out_char= convert->myStringToChar(out);
char* id_char= convert->myStringToChar(id);
frameProcessor->ProcessFrames(in_char, out_char, count, id_char);
}
*
/* Conversion Class*/
StringConversion::StringConversion() {}
char* StringConversion::myStringToChar(System::String^ str) {
System::IntPtr ptr = Marshal::StringToHGlobalAnsi(str); return
static_cast<char*>(ptr.ToPointer()); }
*
C ++ DLL (unchanged)
void Frame_Processor::ProcessFrames(char* in, char* out, int count, char* id)
{
//use the parameters here for something (w,x,y,z varaibles)
w = out;
x = in;
y = count;
z = id;
//do something
RunProcessFrames();
}
I am getting a runtime error for memory access.
+3
source to share
No one has answered this question yet
Check out similar questions: