![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | COM Interop and Array Pointers I am using a COM DLL function that takes a pointer to the first element in an array of short values. Foo(short* array) COM interop provides that function to me in the .NET world with a "ref short" parameter. Foo(ref short array) It seems that no matter what I try, the function only sees the first element in the array. Is there a way to get it to see then entire array? Maybe by using some sort of marshalling I haven't tried yet? Thanks, Mike |
My System Specs![]() |
| | #2 (permalink) |
| | RE: COM Interop and Array Pointers Hello... If you write short* array is not actually... is a pointer to a memory zone where is some information (it may be the start of an array).. so don't think that this is an array... ![]() To call that method correctly, you'll have to marshal the C# array to unmanaged and send the size of the array. So you'll have something like this... //C++ void Foo(short* pArray, unsigned int size){...}; //C# [DllImport("MyDll.dll")] public static extern Foo(ref IntPtr arrayPointer, uint size); To create arrayPointer you'll have to allocate some memory... short[] myArray; //init and set array elements IntPtr arrayPointer = Marshal.AlloHGlobal(myArray.Length * Marshal.SizeOf(typeof(short)); Marshal.Copy(myArray, 0, arrayPointer, myArray.Length); //invoke method... Foo(arrayPointer, myArray.Length); Hope this helps... |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Fast copy method of sub array (=array range) possible? | VB Script | |||
| COM Interop and Pointer to Array | .NET General | |||
| Microsoft.VirtualServer.Interop.dll and the Microsoft.VMRCClientControl.Interop.dll | Virtual Server | |||
| Using an interop assembly with interop dependencies | PowerShell | |||
| how to assign values to array and how to create array via variable | PowerShell | |||