Hi all,
I have a C++ dll file which contains an exported function named fn(double* p, int* pLength), where, p is a pointer (is an out array used in C#), pLength which is calculated in this function is the length (size) of p . Code here:
void _stdcall fn(double* p, int* pLength)
{
int i=0;
double p_=0;
do
{
p[i]=p_;
p_=an expression!!!!!;
i++;
}
while (p_<20);
*pLength=i;
return;
}
I compile to dll file successfuly. This file is named "testFile.dll" and move it to System32 folder.
Now, I start C# console project and declare that exported function fn() from "testFile.dll", and this code is:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace ConsoleApplication1
{
class Program
{
[DllImport("testFile.dll")]
public static extern void fn(double[] p, ref int pLength);
static void Main(string[] args)
{
double[] p;
int pLength;
fn(p, ref pLength);
Console.WriteLine(pLength);
for (int i = 0; i < pLength; i++)
Console.WriteLine(p[i]);
Console.ReadKey();
}
}
}
I run and get two errors:
Error 1 Use of unassigned local variable 'p'
Error 2 Use of unassigned local variable 'pLength'
How to fix them?, and I want to get pLength and p[i] fully from fn() function in "testFile.dll". Thanks in advance.