the code works when i want the dll to return a string to me, (or pBSTR value) this works great, but the moment i want to pass parameters to a dll functions it crashes...
[vb bit]
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hModule As Long) As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Any, ByVal wParam As Any, ByVal lParam As Any) As Long
Private Declare Function lstrlenA Lib "kernel32" (ByVal lpString As Long) As Long
Private Declare Function lstrlenW Lib "kernel32" (ByVal lpString As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal length As Long)
Private Sub Command1_Click()
Dim obj As Long
Dim lngRetProc As Long
Dim strData As String
Dim number As Long
Dim ret As Long
obj = LoadLibrary(App.Path & "\mydll.dll" & Chr(0))
lngRetProc = GetProcAddress(obj, "EngineInfo" & Chr(0))
ret = CallWindowProc(lngRetProc, Me.hWnd, "EngineInfo", ByVal 0&, ByVal 0&)
FreeLibrary obj
DoEvents
MsgBox PointerToString(ret)
End Sub
Private Function PointerToString(lngPtr As Long) As String
Dim strTemp As String
Dim lngLen As Long
If lngPtr Then
lngLen = lstrlenW(lngPtr) * 2
If lngLen Then
strTemp = Space(lngLen)
CopyMemory ByVal strTemp, ByVal lngPtr, lngLen
PointerToString = Replace(strTemp, Chr(0), "")
End If
End If
End Function
Private Sub Command2_Click()
Dim obj As Long
Dim lngRetProc As Long
Dim strData As String
Dim number As Long
Dim ret As Long
Dim sTemp As String
Dim lParam
Dim wParam
obj = LoadLibrary(App.Path & "\mydll.dll" & Chr(0))
lngRetProc = GetProcAddress(obj, "EnginesAvail" & Chr(0))
If lngRetProc <> 0 Then
ret = CallWindowProc(lngRetProc, Me.hWnd, "SayHello", "neochrome", 0&)
MsgBox PointerToString(ret) & lParam
End If
DoEvents
FreeLibrary obj
End Sub
[] Command 1 works, no problem
[PUREBASIC BIT]
;;;;; VERSION 1.0
;;;;; LAST UPDATE: 11-APRIL-2006
;;;;; BUILD : 1.0.1
#PBD_DLL = 1
Global PBD_App_hInstance.l
Global PBD_App_Title.s
Global PBD_LasthWnd.l
Global STRBUILD.s
Global STRDATE.s
ProcedureDLL.l EngineInfo()
Protected buffers.s
buffers = STRBUILD + Chr(10)+Chr(13) + STRDATE
pBSTR = SysAllocStringByteLen_( buffers, Len(buffers))
ProcedureReturn pBSTR
EndProcedure
ProcedureDLL.l SayHello(value.s)
Protected buffers.s
buffers = "HELLO: " + value
pBSTR = SysAllocStringByteLen_( buffers, Len(buffers))
ProcedureReturn pBSTR
EndProcedure
;--------- DLL SYSTEM FUNCTIONS -------------------------------------------------------------
Procedure.l PBD_Initialize()
PBD_LasthWnd = 0
PBD_App_hInstance = GetModuleHandle_(0)
PBD_App_Title = ""
EndProcedure
Procedure.l PBD_LibMain( hInstance, nReason )
STRBUILD = "BUILD: 1.0.1"
STRDATE = "DATE: 11-APRIL-2006"
StrURLUK = "
http://uk.altavista.com/web/results?ita ... stq=*start*"
ProcedureReturn 1
EndProcedure
ProcedureDLL AttachProcess( hInstance )
PBD_App_hInstance = hInstance
ProcedureReturn PBD_LibMain( hInstance, 1 )
EndProcedure
ProcedureDLL DetachProcess( hInstance )
ProcedureReturn PBD_LibMain( hInstance, 0 )
EndProcedure
ProcedureDLL AttachThread( hInstance )
ProcedureReturn PBD_LibMain( hInstance, 2 )
EndProcedure
ProcedureDLL DetachThread( hInstance )
ProcedureReturn PBD_LibMain( hInstance, 3 )
EndProcedure
[end]