I am currently trying to make use of a .dll file that was written in C++ in one of my vb.net 2005 applications. Initially I thought I could simply add the file as a Reference to my project, however, I found this didn't work because the .dll was not written with managed code. After a little research I found I could accomplish this task by using DllImport. I wrote the following code to test this:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim InputRecords As New ArrayList

Dim CmpltCheckFlag As Char

Dim OutputRecords As New ArrayList

Dim MessageRecords As New ArrayList

Dim ReleaseList As New ArrayList

CmpltCheckFlag = "Y"





Class1.TriConEngine(InputRecords, CmpltCheckFlag, OutputRecords, MessageRecords, ReleaseList)

End Sub

End Class

Public Class Class1


<DllImport("CallableTriConCEClient")> _

Public Shared Function TriConEngine(ByRef InputRecords As ArrayList, ByVal CmpltCheckFlag As Char, ByRef OutputRecords As ArrayList, ByRef MessageRecords As ArrayList, ByRef ReleaseList As ArrayList) As Integer

End Function

End Class

The .dll file expects five parameters:

1. &InputRecords of type vector<string>

2. CmpItCheckFlag of type char

3. &OutputRecords of type vector<string>

4. &MessageRecords of type vector<string>

5. &ReleaseList of type vector<string>

I was not sure what data type to use on the VB.NET side so I chose Arraylist. I am getting the following error when I click the button on the form to test this out:

An unhandled exception of type 'System.Runtime.InteropServices.MarshalDirectiveException' occurred in TestDLLImport2003.exe

Additional information: Can not marshal parameter #5: The type definition of this type has no layout information.

Any help or advice on this matter would be greatly appreciated.

Re: .NET Base Class Library DllImport Issue


You can not use P/Invoke to marshal parameters of type vector<T>. You'll have to resort to writing a thunk layer to translate between vector<T> and a normal array. C++/CLI will work for that.

Michael Taylor - 2/16/07

Re: .NET Base Class Library DllImport Issue


Can you give me example of how I would go about doing this