04-06-2005, 11:51 PM
Hallo all!
I still have some trouble using "Dim ... As Function", I tried it several times with different functions.
Look at the example below, it's working (downloading a file from Internet), but only if I'm using the assembler-routine.
Change the line "If 1=1 ..." to "If 1=2 ..." Then it's crashing because then it's using "Dim Download As Function(...)".
I think it's crashing here (from the ASM-File that FBC was creating):
Kind regards from Germany
Peter
I still have some trouble using "Dim ... As Function", I tried it several times with different functions.
Look at the example below, it's working (downloading a file from Internet), but only if I'm using the assembler-routine.
Change the line "If 1=1 ..." to "If 1=2 ..." Then it's crashing because then it's using "Dim Download As Function(...)".
Code:
Option Explicit
Option Private
'$include once:'win\kernel32.bi'
'$include once:'win\user32.bi'
'$include once:'win\gdi32.bi'
Declare Sub DownloadFile(sUrl As String, sFile As String)
Declare Function WinMain(ByVal hInstance As Long, _
ByVal hPrevInstance As Long, _
szCmdLine As String, ByVal iCmdShow As Integer ) As Integer
End WinMain( GetModuleHandle( NULL ), NULL, Command$, SW_NORMAL )
'
Function WinMain ( ByVal hInstance As Long, _
ByVal hPrevInstance As Long, _
szCmdLine As String, ByVal iCmdShow As Integer ) As Integer
DownloadFile("http://www.daxa-chart.de", "C:\test.htm")
WinMain = 0 'wMsg.wParam
End Function
'
Sub DownloadFile(sUrl As String, sFile As String)
Dim addr As Long, hUrlmonDll As Long, back As Long
Dim UrlPtr, FilePtr
Dim Download As Function(ByVal pCaller As Long, _
ByRef szURL As String, ByRef szFileName As String, _
ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
hUrlmonDll = LoadLibraryEx("URLMON.DLL", 0, 0)
addr = GetProcAddress(hUrlmonDll,"URLDownloadToFileA")
If addr<>0 Then
If 1=1 Then ' here is version No. 1 (working)
UrlPtr=StrPtr(sUrl)
FilePtr=StrPtr(sFile)
ASM
Push 0
Push 0
Push [FilePtr]
Push [UrlPtr]
Push 0
Call [addr]
Mov DWord Ptr [back], eax
End Asm
Else ' here is version No. 2 using "Dim ... As Function" (crashing)
back = Download(0, sUrl, sFile, 0, 0)
End If
If back<>0 Then
MessageBox(0, "Download Error Number "+Str$(back), "Error", 0)
End If
Else
MessageBox(0, "Urlmon.dll-Initialisation-Error", "Error", 0)
End If
FreeLibrary(hUrlmonDll)
End Sub
I think it's crashing here (from the ASM-File that FBC was creating):
Code:
push 0
push 0
mov eax, dword ptr [ebp+12]
push eax
mov eax, dword ptr [ebp+8]
push eax
push 0
call dword ptr [ebp-16] ' <- crashing here?
mov dword ptr [ebp-12], eax ' <- crashing here?
Kind regards from Germany
Peter
erman freeBASIC-mailinglist: de.groups.yahoo.com/group/free-basic.
For subscribing send an empty e-mail to free-basic-subscribe@yahoogroups.de.
For subscribing send an empty e-mail to free-basic-subscribe@yahoogroups.de.