在VB.NET中调用C ++ DLL文件

时间:2012-10-24 08:17:08

标签: c++ vb.net dll dllimport

我需要在VB.NET中使用C ++ DLL文件。下面是DLL文件的dumpbin

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

下面是Visual Basic 6.0对象浏览器中显示的函数定义。

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

如何在VB.NET中调用此方法?

我尝试进行DLL导入:

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

但它给了我一个错误:

  

尝试读取或写入受保护的内存。这通常表明其他内存已损坏。

1 个答案:

答案 0 :(得分:1)

如果它出现在Visual Basic 6.0对象浏览器中,则它是COM DLL。使用COM Interop。在VB.NET中,转到项目引用,转到 COM 选项卡,然后添加DLL文件。