简体   繁体   English

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

[英]Calling a C++ DLL file in VB.NET

I need to use a C++ DLL file in VB.NET . 我需要在VB.NET中使用C ++ DLL文件。 Below is the dumpbin for the DLL file. 下面是DLL文件的转储

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. 下面是在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

How do I call this method in VB.NET? 如何在VB.NET中调用此方法?

I tried doing a DLL import: 我尝试执行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

But it's giving me an error: 但这给了我一个错误:

Attempted to read or write protected memory. 尝试读取或写入受保护的内存。 This is often an indication that other memory is corrupt. 这通常表明其他内存已损坏。

If it shows up in the Visual Basic 6.0 Object Browser, it is a COM DLL. 如果它显示在Visual Basic 6.0对象浏览器中,则为COM DLL。 Use COM Interop. 使用COM Interop。 In VB.NET , go to Project References , go to the COM tab, and add the DLL file. VB.NET中 ,转到“ 项目引用” ,转到“ COM”选项卡,然后添加DLL文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM