VC6 ATL DLL interop with VB.NET

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



I have an existing VC6 ATL COM DLL. It has a number of methods within it
that take a byte array as the methods parameters. Here's what the IDL looks
like in the VC6 DLL:

[id(32), helpstring("method GetSystemConfig")] HRESULT GetSystemConfig([in,
out] SAFEARRAY(unsigned char) *pData, [out, retval] long *retval);

As you can see it is a byte array (SAFEARRAY)

In the VB.NET object browser the the prototype looks like this:

Public Function GetSystemConfig(ByRef pData as System.Array) as Integer

PROBLEM: Everyone of the API calls made in the following code section throws
an error:
"Specified array was not of the expected type. Err.Number = 5 "

I currently have VB.NET up in the VC 6 debugger just to see if the interface
ever gets called, and it does not. Which means my problem is in the interop
dll that Dot net creates automatically.

Public Function GetSystemConfig(ByRef pBytes As System.Array) As Integer
On Error GoTo processerror

Dim pByte() As Byte
GetSystemConfig = (ESITapi.GetSystemConfig(pByte) = S_OK)

Dim pByt(512) As Byte
GetSystemConfig = (ESITapi.GetSystemConfig(pByt) = S_OK)

Dim chars As Byte() = System.Text.Encoding.ASCII.GetBytes("hello
world")
GetSystemConfig = (ESITapi.GetSystemConfig(chars) = S_OK)

Dim arr As Array

GetSystemConfig = (ESITapi.GetSystemConfig(arr) = S_OK)

Dim strArr() As String = {"1", "2", "3"}
GetSystemConfig = (ESITapi.GetSystemConfig(strArr) = S_OK)

Dim pB(512) As Char
GetSystemConfig = (ESITapi.GetSystemConfig(pB) = S_OK)

End Function

Is there any way I can debug VB.NETS interop DLL ?
Any idea's what's wrong with the parameters I'm passing ?
FYI, I'm using VS 2005
This ATL control was written for use with VB6 and has been in production for
years, I'm trying to reuse it in the Dot Net world.
Anyone got any ideas ?

Dave


.



Relevant Pages

  • Re: String array in c++ dll to vb.net
    ... Dim ids As IntPtr ... I know the dll function works btw as I can call it from C++ ... This will get you the address of the array. ...
    (microsoft.public.dotnet.framework.interop)
  • Re: Specified Cast not Valid: Object to Bitmap
    ... to an object, then the reverse, object to byte array to image. ... Dim IMG As System.Drawing.Image ... 'Create a Memory Stream and put the Picture in it. ... The bitmaps/images come from a DLL. ...
    (microsoft.public.dotnet.framework)
  • Re: Return array from C# COM to VBScript
    ... We came across a similar problem when trying to access an array returned by ... a VB6 DLL in an ASP page. ... Dim bResult As Boolean ...
    (microsoft.public.dotnet.framework.component_services)
  • Re: How do I pass an array to a vb DLL
    ... ArrayCom.exe Passing Array To COM DLL by Reference ... > PUBLIC otest ... > Dim aArrayAs Variant ...
    (microsoft.public.fox.programmer.exchange)
  • Re: Is a Thread appropriate?
    ... >> Now, if you are not doing dynamic loading of the DLL, you shouldn't need GetProcAddress. ... >> Note that it is foolish to create a char array, particularly a char array of a fixed size. ... >> If you need to declare a separate variable, ... without necessity. ...
    (microsoft.public.vc.mfc)