lundi 24 mars 2014

Declaring C dll functions in visual basic


Vote count:

0




I am learning to make dll for Visual Basic, so I made this:


DLL in C:



// FirstDLL.cpp : Defines the exported functions for the DLL application.
//

#include "stdafx.h"
#include "stdio.h"

extern "C"
{
__declspec(dllexport) int sestej(int a, int b)
{
int c;
c = a + b;
return c;
}
}


Visual Basic:



Public Class Form1

Declare Function sestej Lib "C:\Users\Blaž\Documents\Visual Studio 2013\Projects\FirstDLL\Debug\FirstDLL.dll" (ByVal x As Integer, ByVal y As Integer)

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

Dim vnos1, vnos2, izhod As Integer

vnos1 = Convert.ToDecimal(VnosX.Text)
vnos2 = Convert.ToDecimal(VnosY.Text)

sestej(vnos1, vnos2)

lblvsota.Text = izhod

End Sub


End Class


When I run it i get this error: An unhandled exception of type 'System.Runtime.InteropServices.MarshalDirectiveException' occurred in WindowsApplication2.exe


Additional information: PInvoke restriction: cannot return variants.


I obviously did something wrong but I can't find it anywhere.


Pls help :)



asked 35 secs ago






Aucun commentaire:

Enregistrer un commentaire