VC++ is a second language to me so there may be a better way, but here is how I do it.
'VB Code
VB Code:
'Module
Option Explicit
Public Declare Function SayHello Lib "test.dll" (ByVal lpString As String, ByVal MyInt As Long, ByVal lpFunc As Long) As Long
Private Declare Function lstrcpy Lib "kernel32" (ByVal lpString1 As String, lpString2 As Any) As Long
Public Function cbFoo(Obj As Long, count As Long) As Long
Dim sInBuffer As String
sInBuffer = Space$(1024)
Call lstrcpy(sInBuffer, Obj)
Debug.Print sInBuffer
End Function
'Form
Option Explicit
Private Sub Form_Load()
Dim lpString As String, MyInt As Long, lRet As Long
lpString = Space$(1024)
lRet = SayHello(lpString, MyInt, AddressOf cbFoo)
End Sub
VC++ Code
Code:
'CPP File
#include <windows.h>
#include <stdio.h>
typedef void (__stdcall *fnCallBack)(LPTSTR lpszOutPut, long lpn);
fnCallBack ReturnCB;
__declspec( dllexport ) int WINAPI SayHello (LPSTR StringIn, long lpn, long f) {
ReturnCB = (fnCallBack)f;
strcpy(StringIn, "Why do you yahoooo!!");
(lpn) ++;
ReturnCB(StringIn, lpn);
return 1;
}
'DEF File
LIBRARY Test
DESCRIPTION 'Test.dll'
EXPORTS
; DLLXPORT_BEGIN:
SayHello
Greg