I am calling a c++ dll from c#. I want to create a safearray (within a structure)in the c++ dll and pass it back to the c#.
The program crashes when returning to the c# with rhe following message:
An unhandled exception of type 'System.ExecutionEngineException' occurred in ConsoleApplication2.exe
the c# code is:
using System;
using System.Runtime.InteropServices;
namespace ConsoleApplication2
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct retVar
{
public object pData;
public int errorNo;
}
class Program
{
[DllImport("probsoln.dll")] private static
extern void run(ref int k , ref retVar rV);
static void Main(string[] args)
{
retVar rV = new retVar();
rV.errorNo = 1;
rV.pData = 0;
int k = 5;
run(ref k , ref rV); // error when returning here
Console.WriteLine("prog finished!! k = " + k);
}
}
}
the c++ dll code is:
#define WINVER 0x0502
#ifndef _AFXDLL
#define _AFXDLL
#endif
#include <iostream>
#include <afxdisp.h>
Bookmarks