I am having a difficult time trying to pass an array of integers, by reference
to an ActiveX method with out the CLR crashing. Here is the method definition
that I was able to get from the ActiveX component with the type library viewer.
[id(0x0000004f)]
short ReadFFT(
long* pArray,
short wCount);
.NET creates a couple of import dll's and here are the disassembly for this
same method from the AxInterop assembly.
.method public hidebysig newslot virtual
instance int16 ReadFFT(int32& pArray,
int16 wCount) cil managed
{
// Code size 36 (0x24)
.maxstack 3
.locals init (int16 V_0)
IL_0000: ldarg.0
IL_0001: ldfld class [Interop.MMVARILib]MMVARILib._DMMVARI
AxMMVARILib.AxMMVARI::ocx
IL_0006: brtrue.s IL_0014
IL_0008: ldstr "ReadFFT"
IL_000d: ldc.i4.0
IL_000e: newobj instance void
[System.Windows.Forms]System.Windows.Forms.AxHost/InvalidActiveXStateException::.ctor(string,
valuetype [System.Windows.Forms]System.Windows.Forms.AxHost/ActiveXInvokeKind)
IL_0013: throw
IL_0014: ldarg.0
IL_0015: ldfld class [Interop.MMVARILib]MMVARILib._DMMVARI
AxMMVARILib.AxMMVARI::ocx
IL_001a: ldarg.1
IL_001b: ldarg.2
IL_001c: callvirt instance int16
[Interop.MMVARILib]MMVARILib._DMMVARI::ReadFFT(int32&,
int16)
IL_0021: stloc.0
IL_0022: ldloc.0
IL_0023: ret
} // end of method AxMMVARI::ReadFFT
This is from the Interop Assembly:
.method public hidebysig newslot virtual
instance int16 ReadFFT(int32& pArray,
int16 wCount) runtime managed preservesig internalcall
{
.custom instance void
[mscorlib]System.Runtime.InteropServices.DispIdAttribute::.ctor(int32) = ( 01
00 4F 00 00 00 00 00 ) // ..O.....
.override MMVARILib._DMMVARI::ReadFFT
} // end of method MMVARIClass::ReadFFT
In the good old days of VB6 one would call this method with the following code:
Dim ret as integer
Dim count as integer = 1024
dim fft(1023) as integer
ret = MM.ReadFFT(fft(0),count)
This worked without problems.
If I use this same calling convention in .NET the CLR croaks and the program
aborts with the standard MS noise about the program has abruptly halted and we
are checking for a solution.
Since VB.NET seems to have problem with pointers and references, I tried this
same scenario in C#
unsafe private void GetFFTData()
{
Int16 ret;
short count = 1024;
Int32[] fft = new Int32[1023];
ret = this.MM.ReadFFT(ref fft[0], count);
count = 0;
}
Same exact result in C#. So how do I go about calling this method in either C#
or VB in .NET?
Jeff Steinkamp, [email protected]
2011-09-26
--
You received this message because you are subscribed to the Google
Groups "DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML
Web Services,.NET Remoting" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/dotnetdevelopment?hl=en?hl=en
or visit the group website at http://megasolutions.net