Private Declare
Function subtraction Lib "TestDLL.DLL" (ByVal A
As Double, ByVal B
As Double)
As Double
Private Declare
Function addition Lib "TestDLL.DLL" (ByVal A
As Double, ByVal B
As Double)
As Double
Private Declare
Function showmsg Lib "TestDLL.DLL" ()
As Long
// Windows API Declaration
Private Declare
Function lstrlen Lib "kernel32" Alias "lstrlenA" ( _
ByVal lpString
As Long _
)
As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
ByRef Destination
As Any, _
ByRef Source
As Any, _
ByVal Length
As Long _
)
Private Sub btnTime_Click()
lblTime.Caption = VBStrFromAnsiPtr(showmsg())
End Sub
Private Sub cmdExit_Click()
End
End Sub
Private Sub Form_Load()
lblResult(0) = "9.87 + 2.99 = " & CStr(addition(9.87, 2.99))
lblResult(1) = "10 - 8.43 = " & CStr(subtraction(10, 8.43))
lblResult(2) = "9999 + 1543 = " & CStr(addition(9999, 1543))
End Sub
Private Function VBStrFromAnsiPtr(ByVal lpStr
As Long)
As String
Dim bStr()
As Byte
Dim cChars
As Long
On Error Resume Next
// Get the number of characters in the buffer
cChars = lstrlen(lpStr)
// Resize the byte array
ReDim bStr(0
To cChars - 1)
As Byte
// Grab the ANSI buffer
Call CopyMemory(bStr(0), ByVal lpStr, cChars)
// Now convert to a VB Unicode string
VBStrFromAnsiPtr = StrConv(bStr, vbUnicode)
End Function