Hi
I am struggling with pinvoke
I have dll a function that is declared as :
sf_command (IntPtr sndfile,int command, IntPtr data, int datasize);
i need to pass a pointer to a double in the data parameter, i now did :
IntPtr mem = Marshal.AllocHG lobal(sizeof(do uble));
sf_command (sndfile,comman d, mem, sizeof(double)) ;
then i did
byte[] ba=new byte[sizeof (Double)];
ba[0]=Marshal.ReadBy te(mem,0);
ba[1]=Marshal.ReadBy te(mem,1);
ba[2]=Marshal.ReadBy te(mem,2);
ba[3]=Marshal.ReadBy te(mem,3);
ba[4] = Marshal.ReadByt e(mem, 4);
ba[5] = Marshal.ReadByt e(mem, 5);
ba[6] = Marshal.ReadByt e(mem, 6);
ba[7] = Marshal.ReadByt e(mem, 7);
max_val = BitConverter.To Double(ba,0);
Marshal.FreeHGl obal(mem);
this works ,but i think there should be a shorter way ??
second question :
How do i pass an array doubles to my function ?
Johan
I am struggling with pinvoke
I have dll a function that is declared as :
sf_command (IntPtr sndfile,int command, IntPtr data, int datasize);
i need to pass a pointer to a double in the data parameter, i now did :
IntPtr mem = Marshal.AllocHG lobal(sizeof(do uble));
sf_command (sndfile,comman d, mem, sizeof(double)) ;
then i did
byte[] ba=new byte[sizeof (Double)];
ba[0]=Marshal.ReadBy te(mem,0);
ba[1]=Marshal.ReadBy te(mem,1);
ba[2]=Marshal.ReadBy te(mem,2);
ba[3]=Marshal.ReadBy te(mem,3);
ba[4] = Marshal.ReadByt e(mem, 4);
ba[5] = Marshal.ReadByt e(mem, 5);
ba[6] = Marshal.ReadByt e(mem, 6);
ba[7] = Marshal.ReadByt e(mem, 7);
max_val = BitConverter.To Double(ba,0);
Marshal.FreeHGl obal(mem);
this works ,but i think there should be a shorter way ??
second question :
How do i pass an array doubles to my function ?
Johan
Comment