LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to call labview DLL from C#, passing char, char[], float[], long, short

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

0 Kudos
Message 1 of 1
(2,895 Views)