06-26-2011 08:55 PM
Hi,
I'm having trouble calling labview dll from C# to perform certain function.
The function supposed to return the values in the float Analysis[] array. However, when I execute it it only returns zero values.
It seems that some parameters are not properly passed to the dll.
Below is the function in the header file:
void __stdcall Optical_Center(char FileDirectory[], long ImagePtr,
short int Height, short int Width, char ReadFromFile, float Analysis[],
long lenAnalysis);
and my corresponding dll import in c#:
[DllImport(@"SMIA.dll", CharSet = CharSet.Ansi)]
public static extern void Optical_Center([MarshalAs(UnmanagedType.LPStr)]string FileDirectory, long ImagePtr,
short Height, short Width,char ReadFromFile, IntPtr Analysis,
long lenAnalysis);
string str = @"C:\SMIA.raw";
int len = 3;
long m_lenAnalysis = 3;
long m_ImagePtr = 0;
short m_Height = 2464;
short m_Width = 3280;
IntPtr m_PtrArray = Marshal.AllocHGlobal(len * Marshal.SizeOf(typeof(float)));
char m_ReadFromFile = '1';
Optical_Center(str,m_ImagePtr,m_Height,m_Width,m_ReadFromFile,m_PtrArray,m_lenAnalysis);
float[] m_Analysis = new float[len];
Marshal.Copy(m_PtrArray, floatArray,0,len);
Marshal.FreeHGlobal(m_PtrArray);
string printstr = "";
for (int i=0; i<len; i++)
{
printstr = printstr + floatArray[i].ToString() + "\n";
}
MessageBox.Show(printstr);
Appreciate if anyone can help, thanks.
KL