我需要在VB.NET中使用C++ DLL文件。以下是DLL文件的dumpbin。在VB.NET中調用C++ 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
下面是在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
但它給我一個錯誤:
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Vb.Net應用程序和本機C++ dll不能一起玩。你應該在C++/CLI中編寫一些包裝,以便將它們聯繫在一起,但看看你如何格式化你的問題,我懷疑你沒有資格。 –
+1因爲你不值得因爲作爲一個新手互操作而被低估,並且COM – MarkJ
用整數替換長整數。 –