user1770583
user1770583

Reputation: 21

Calling a C++ DLL file in VB.NET

I need to use a C++ DLL file in VB.NET. Below is the dumpbin for the DLL file.

D:\Program Files\Microsoft Visual Studio 10.0\VC>dumpbin /exports d:\dll\myssort.dll
Microsoft (R) COFF/PE Dumper Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.
Dump of file d:\dll\ myssort.dll
File Type: DLL
  Section contains the following exports for MySort.dll
    00000000 characteristics
    3D3F006E time date stamp Thu Jul 25 01:00:54 2002
        0.00 version
           1 ordinal base
           1 number of functions
           1 number of names
    ordinal hint RVA      name
          1    0 00001000 MySortA7
  Summary
        1000 .data
        1000 .rdata
        1000 .reloc
        1000 .rsrc
        3000 .text

Below is the function definition which is showing in the Visual Basic 6.0 Object Browser.

Function SortA7(udtArray As udtA7Rec, nTotalItems As Long) As Long
    Member of MySort. MySort
    Sort the elements of A7-type array

How do I call this method in VB.NET?

I tried doing a DLL import:

<DllImport("MySort.dll", _
SetLastError:=True, CharSet:=CharSet.Auto)>
Public Function SortA7(ByVal udtArray As MySort.udtA7Rec(), ByVal nTotalItems As Long) As Long
End Function

But it's giving me an error:

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Upvotes: 0

Views: 3499

Answers (1)

MarkJ
MarkJ

Reputation: 30398

If it shows up in the Visual Basic 6.0 Object Browser, it is a COM DLL. Use COM Interop. In VB.NET, go to Project References, go to the COM tab, and add the DLL file.

Upvotes: 1

Related Questions