0

In VB.NET, to import a method from DLL file can be written in:

  1. DllImport statement - new method introduced for .net
  2. Declare statement - old method since VB6

For the first one, the code looks like:

Imports System.Runtime.InteropServices
<DllImport("library_name.dll", EntryPoint:="entry_point", CallingConvention:=CallingConvention.Cdecl)> Public Function method_name(...) AS ...
End Function

And the above code works fine, I just wonder how to convert the code into the older way using Declare keyword as following:

Declare Function method_name Lib "library_name.dll" Alias "entry_point" (...) As ...

To make the question more specific, where can I add the CallingConvention attribute into the Declare statement?

GSerg
  • 76,472
  • 17
  • 159
  • 346
omg
  • 35
  • 4
  • 1
    Any particular reason you want to use the older method, when the newer one works? – James Thorpe Apr 23 '18 at 08:18
  • 1
    It [looks like](https://stackoverflow.com/questions/16293334/vb6-declaration-for-c-function-gives-bad-dll-calling-convention) the older syntax/VB6 is limited to `__stdcall`. – James Thorpe Apr 23 '18 at 08:21

1 Answers1

1

The legavy Declare syntax is limited to stdcall. Use p/invoke.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490