When you omit the return type in a VB function, it is assumed to be object
. Since object
maps to the native VARIANT
type, that explains the error. You must specify the return type.
Rather than continue with Declare
I suggest you switch to P/invoke. Declare
was how it was done in VB6, but P/invoke is the .net way to do interop with unmanaged code. You would declare the function like this:
<DllImport("...\FirstDLL.dll", CallingConvention:=CallingConvention.Cdecl)> _
Public Shared Function sestej(ByVal a As Integer, _
ByVal b As Integer) As Integer
End Function
This also allows you to correct the other error in your code. Namely the calling convention mismatch. Your unmanaged code uses Cdecl
, but your VB code using Declare
uses StdCall
. The code above fixes that.