vb怎样调用c++
最近要写一个软件工程的课程设计,想用vb写界面,c++封装成dll然后在vb中调用,可以吗?如果可以请问怎么调用,我是vb6.0,vs2010,顺便再弱弱问句,我们只有5个礼拜时间,时间够吗?
[解决办法]
本帖最后由 bcrun 于 2013-03-31 09:52:51 编辑 调用方式为_Cdecl 的 DLL 有两种方法:
1 再写一个 __stdcall 的代理 DLL 间接调用。
2 做一个类,如下:
Imports System
Imports Microsoft.VisualBasic
Imports System.Runtime.InteropServices
Public Class LibWrap
' Visual Basic does not support varargs, so all arguments must be
' explicitly defined. CallingConvention.Cdecl must be used since the stack
' is cleaned up by the caller.
' int printf( const char *format [, argument]... )
<DllImport("msvcrt.dll", CallingConvention := CallingConvention.Cdecl)> _
Overloads Shared Function printf ( _
format As String, i As Integer, d As Double) As Integer
End Function
<DllImport("msvcrt.dll", CallingConvention := CallingConvention.Cdecl)> _
Overloads Shared Function printf ( _
format As String, i As Integer, s As String) As Integer
End Function
End Class 'LibWrap
Public Class App
Public Shared Sub Main()
LibWrap.printf(ControlChars.CrLf + "Print params: %i %f", 99,
99.99)
LibWrap.printf(ControlChars.CrLf + "Print params: %i %s", 99, _
"abcd")
End Sub 'Main
End Class 'App