0

EDIT: My post yesterday has been modified.

EDIT2: I've tried using Marshal.GetNativeVariantForObject but I still get same error. See modified code below...

From VB.NET code, I am calling a method of a COM object and get DISP_E_TYPEMISMATCH

Dim thisDispName As String
Dim ap1StreamName As Object
Dim ap1Temperature As Object
Dim ap1Pressure As Object
Dim iTemporary(1) As Integer
Dim ptrToAp1Temperature As IntPtr = IntPtr.Zero
Const SizeOfNativeVariant As Int32 = 16

iTemporary(0) = 3
iTemporary(1) = iTemporary(0)
ap1Pressure = iTemporary

ptrToAp1Temperature = System.Runtime.InteropServices.Marshal.AllocHGlobal(SizeOfNativeVariant)
System.Runtime.InteropServices.Marshal.GetNativeVariantForObject(ap1Pressure, ptrToAp1Temperature)

apGen.GetHeaterStreams(thisDispName, ap1StreamName, ap1Temperature, ap1Pressure)

I know the method GetHeaterStreams is defined below (I know, pretty old types...)

GetHeaterStreams(BSTR* dispName, VARIANT* streamName, VARIANT* temp, VARIANT* pressure);

I think (not really sure) that passing an empty Object to parameter of type VARIANT* is okay. However, I think the issue is passing ap1Pressure, which is an Integer array, to parameter of type VARIANT*

ryrich
  • 2,164
  • 16
  • 24
  • The [`VARIANT`](http://msdn.microsoft.com/en-us/library/aa908601.aspx) type is a union in C/C++, there's a matching [`Variant` data type](http://msdn.microsoft.com/en-us/library/office/gg251448.aspx) in the .NET world that might be what you need instead of a standard `Object` (which is a generic pointer reference). I don't know what GetHeaterStreams does or how it is built, but the calling convention of the methods can affect how to marshal things too (i.e. `__cdecl` vs `__stdcall` in the binary). – txtechhelp Dec 19 '13 at 22:01
  • 1
    Looks like VB6 code. You definitely got the first argument wrong, it should be a plain String. Avoid late binding, just add a reference to the type library. Normally embedded in the DLL itself. – Hans Passant Dec 19 '13 at 23:20
  • Thanks guys. First parameter is wrong (thanks Hans). Still gives the same error, but found out it's because one of the `Object`'s I'm passing is an `Integer` array, and I guess that can't be converted implicitly to a `VARIANT*` like `String`->`BSTR*` can. I'll edit my post tomorrow with more code and work in marshalling correctly to `VARIANT*` – ryrich Dec 20 '13 at 03:45
  • post has been modified. Looking into how to convert from `Integer`array to `Variant*` – ryrich Dec 20 '13 at 14:46

0 Answers0