Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array Pointers, Calling C++ DLL

Status
Not open for further replies.

Chucker75

Programmer
Mar 18, 2004
2
DE
Array Pointers in C#, calling C++ DLL

I got a DLL that reads some RAW Double Data from a File to an Array.
The DLL works fine.

This is the Header of the double_read function:

int dll_dbl_read (const char * fnam,
/* File name to read from */
int * res,
/* returns int[4]*/
float * len,
/* returns float[4]*/
double ** data);
/* returns double[unknown size]*/

This is how I call the function from C++:

char * myfname;
int res[4];
float len[4];
double * data;
int m_type;

int DataStack::dbl_read(const char * fname)
{
m_type = dll_dbl_read(fname,res,len,&data);
myfname = new char[strlen(fname)+1];
strcpy(myfname, fname);

return m_type;
}

This works fine and I would like to know how to call this function from C#?????

This is what I try in C# and what doesn´t work:

using System;
using System.Runtime.InteropServices;

namespace mine
{
/// <summary>
/// Summary description for FileIO.
/// </summary>


public unsafe class FileIO
{
public int m_type;
public char[] myfname;
public int * res;
public float * len;
public double ** data;

[DllImport("MYLIB.DLL", EntryPoint="dll_dbl_read", SetLastError=true, CharSet=CharSet.Unicode, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
public static unsafe extern int dll_dbl_read(char[] fnam, int* res, float* len, double** data);

public int dbl_read(string fname)
{
int result;
int[] resolution = {0,0,0,0};
float[] length = {0,0,0,0};
double[] mydata = {0};
myfname = fname.ToCharArray();
fixed (int* res = resolution)
{
fixed (float* len = length)
{
fixed (double* data = mydata)
{
result = dll_dbl_read(myfname,res,len,&data);
/*Just for Testing*/
int x = res[0];
float xl = len[0];
double test = data[100];
test = data[23];
/*Everything is empty here :eek:(*/
}
}
}

return result;
}

public FileIO()
{
}
}

Can Anybody tell me how to Create my Variables to pass to the function
dll_dbl_read? So that I find my data in there and not only 0 or NULL?

Thanks in Advance

Martin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top