Hi everybody
I have a problem with my C# program and I'd like to get your advice
In the past, I wrote a traditional DLL (TryingDLL) with following code
....
EXPORT void Test(double* &ptrDbl,long n)
{
ptrDbl=new double[n];
for(long i=0;i<n;i++)
{
ptrDbl[i]=i+100;
}
}
...
Then I compiled to "TryingDLL.dll". Now I want to use the function Test in that library in my C# program
...
namespace CSApp
{
class Program
{
[DllImport("E:\\Temp\\Programming\\C++\\TryingDll\\App\\Output\\TryingDll.dll")]
private static extern unsafe void Test(out double * p,long n);
static unsafe void Main(string[] args)
{
double* p;
Test(out p,3);
Console.ReadLine();
}
}
...
But this code didn't work (there's no error when I built it, but the program can not run with an error message).
Can anyone help me to solve the problem?
(I also tried using the library with a test C++ code and it worked very well)
Thanks.