VB6 vs VB.NET to C++ DLL Calling Conventions

preficks

New member
Joined
Nov 10, 2003
Messages
2
Is there any difference in the way that an array is passed from VB to C++ in VB6.0 as opposed to .NET?

My problem is that I have a working app in VB6 which passes an array by reference to a C++ DLL. However, when running the same app converted into VB.NET, something is wrong with passing the array in the same manner... the return of "Status" is a paramater error.

Ex:

VB code:

Public Declare Function GetString Lib "Test.dll" (ByVal dwNum As Long, ByRef lpvString As Byte, ByVal dwFlags As Long) As Integer

Status = GetString(0, DevStr(0), RETURN_DEVSTRING)


C code:

TEST_API STATUS WINAPI GetString(DWORD dwNum, LPVOID lpvString, DWORD dwFlags);

If I am missing something in the conversion for VB6 to VB.NET, any help would be appreciated!
 
You cant do this, well not like you do in VB 6.0 anyway, ;) The way that .Net works is on the principle that VB, VC# and some VC++ is compiled to an intermediate language. Thats essential what the .Net framework is, an intermediate language compiler than takes programs at this level, and converts them to machine code. It greatly improves speed and reliability of code (objects destroy themselves etc), but does have draw backs.

If your DLL is in machine code already, a .Net application cannot talk to it.

(COM)
What you need is to create an interop, that is, a DLL that talks to your machine code C++ DLL, and then provides a .Net interface to your VB.Net program...

If your DLL is a COM object, then read this...
http://msdn.microsoft.com/library/d...l/cpcongeneratingprimaryinteropassemblies.asp

(C++ DLL)
If your DLL is just a C++ class wrapped up, you need to create a wrapper class for your .Net code.
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconconsumingunmanageddllfunctions.asp

hope that helps.
Dan.
 
Back
Top