PDA

View Full Version : calling DLL problem



zak
07-01-2011, 17:40
Hello
i have found a good regular expressions dll here:
http://www.codeproject.com/KB/library/deelx.aspx?fid=348264&fr=1
the dll demo contains the dll and a vb6 example on how to call it.
the vb6 example are working okay, i am trying to port it to thinbasic, the simplified vb6 example like this:

Private Declare Function regexp_create Lib "libdeelx.dll" () As Long
Private Declare Function result_create Lib "libdeelx.dll" () As Long
Private Declare Sub regexp_free Lib "libdeelx.dll" (ByVal hhh As Long)
Private Declare Sub result_free Lib "libdeelx.dll" (ByVal result As Long)
Private Declare Sub regexp_compile Lib "libdeelx.dll" (ByVal hhh As Long, ByVal pattern As String, ByVal flag As Long)
Private Declare Function regexp_replace Lib "libdeelx.dll" (ByVal hhh As Long, ByVal Text As String, ByVal replaceto As String, ByVal startpos As Long, ByVal times As Long, ByVal result As String, ByVal Size As Long) As Long
Private Declare Sub regexp_match Lib "libdeelx.dll" (ByVal hhh As Long, ByVal Text As String, ByVal startpos As Long, ByVal result As Long)
Private Declare Function result_ismatched Lib "libdeelx.dll" (ByVal result As Long) As Long
Private Declare Function result_start Lib "libdeelx.dll" (ByVal result As Long) As Long
Private Declare Function result_end Lib "libdeelx.dll" (ByVal result As Long) As Long
Private Sub Command1_Click()
Dim handle As Long
Dim result As Long

handle = regexp_create()
result = result_create()

regexp_compile handle, "23", 0
regexp_match handle, "ww123456", -1, result

If result_ismatched(result) <> 0 Then
MsgBox Str$(result_start(result))
MsgBox Str$(result_end(result))

Else
'...
End If

result_free result
regexp_free handle
End Sub

the corresponding non working thinbasic example like this:

Declare Function regexp_create Lib "libdeelx" () As Long
Declare Function result_create Lib "libdeelx" () As Long
Declare Sub regexp_free Lib "libdeelx" (ByVal myHandle As Long)
Declare Sub result_free Lib "libdeelx" (ByVal result As Long)
Declare Sub regexp_compile Lib "libdeelx" (ByVal myHandle As Long, ByVal pattern As String, ByVal flag As Long)
Declare Function regexp_replace Lib "libdeelx" (ByVal myHandle As Long, ByVal Text As String, ByVal replaceto As String, ByVal startpos As Long, ByVal times As Long, ByVal result As String, ByVal Size As Long) As Long
Declare Sub regexp_match Lib "libdeelx" (ByVal myHandle As Long, ByVal Text As String, ByVal startpos As Long, ByVal result As Long)
Declare Function result_ismatched Lib "libdeelx" (ByVal result As Long) As Long
Declare Function result_start Lib "libdeelx" (ByVal result As Long) As Long
Declare Function result_end Lib "libdeelx" (ByVal result As Long) As Long
Declare Function LoadLibrary Lib "KERNEL32.DLL" Alias "LoadLibraryA" (ByVal s As String) As Long
Declare Function FreeLibrary Lib "KERNEL32.DLL" Alias "FreeLibrary" (ByVal hLibModule As DWord) As Long

Dim myHandle As Long
Dim result As Long
Dim mylib As String
Dim hinst As Long
mylib = "libdeelx.dll"
myHandle = LoadLibrary(mylib)

If myHandle = 0 Then
MsgBox 0,"libdeelx cannot be found"
End If

myHandle = regexp_create()
result = result_create()

regexp_compile myHanfle, "23", 0
regexp_match myHandle, "ww123456", -1, result

If result_ismatched(result) <> 0 Then
MsgBox 0,Str$(result_start(result))
MsgBox 0,Str$(result_end(result))

Else
'...
End If

result_free result
regexp_free myHandle


but i get an error :
Variable not defined or misspelled Keyword
myHandle = regexp_create
Token found REGEXP_CREATE
even this "REGEXP_CREATE" function are declared before. and i have used also LoadLibrary.
i attach the vb6 demo the original and my simplified one with the dll.
regards

Petr Schreiber
07-01-2011, 18:40
Hi Zak,

make sure the DLL is in the directory and then try this:


Uses "Console"

' -- Declares
Declare Function regexp_create Lib "libdeelx.dll" Alias "regexp_create" () As Long
Declare Function result_create Lib "libdeelx.dll" Alias "result_create" () As Long
Declare Sub regexp_free Lib "libdeelx.dll" Alias "regexp_free" (ByVal myHandle As Long)
Declare Sub result_free Lib "libdeelx.dll" Alias "result_free" (ByVal result As Long)
Declare Sub regexp_compile Lib "libdeelx.dll" Alias "regexp_compile" (ByVal myHandle As Long, ByVal pattern As String, ByVal flag As Long)
Declare Function regexp_replace Lib "libdeelx.dll" Alias "regexp_replace" (ByVal myHandle As Long, ByVal Text As String, ByVal replaceto As String, ByVal startpos As Long, ByVal times As Long, ByVal result As String, ByVal Size As Long) As Long
Declare Sub regexp_match Lib "libdeelx.dll" Alias "regexp_match" (ByVal myHandle As Long, ByVal Text As String, ByVal startpos As Long, ByVal result As Long)
Declare Function result_ismatched Lib "libdeelx.dll" Alias "result_ismatched" (ByVal result As Long) As Long
Declare Function result_start Lib "libdeelx.dll" Alias "result_start" (ByVal result As Long) As Long
Declare Function result_end Lib "libdeelx.dll" Alias "result_end" (ByVal result As Long) As Long

Function TBMain()
Dim eHandle As Long
Dim result As Long

eHandle = regexp_create()
result = result_create()

regexp_compile(eHandle, "23", 0)
regexp_match(eHandle, "ww123456", -1, result)

If result_ismatched(result) <> 0 Then
PrintL "Result start:", result_start(result)
PrintL "Result end :", result_end(result)

Else
'...
End If

result_free(result)
regexp_free(eHandle)

PrintL
PrintL "Press any key to quit..."
WaitKey

End Function
The problem was missing ALIAS in this case.


Petr

peter
07-01-2011, 18:41
Declare Function regexp_create Lib "libdeelx" Alias "regexp_create" () As Long
Declare Function result_create Lib "libdeelx" Alias "result_create" () As Long
Declare Sub regexp_free Lib "libdeelx" Alias "regexp_free" (ByVal myHandle As Long)
Declare Sub result_free Lib "libdeelx" Alias "result_free" (ByVal result As Long)
Declare Sub regexp_compile Lib "libdeelx" Aias "regexp_compile" (ByVal myHandle As Long, ByVal pattern As String, ByVal flag As Long)
Declare Function regexp_replace Lib "libdeelx" Alias "regexp_replace" (ByVal myHandle As Long, ByVal Text As String, ByVal replaceto As String, ByVal startpos As Long, ByVal times As Long, ByVal result As String, ByVal Size As Long) As Long
Declare Sub regexp_match Lib "libdeelx" Alias "regexp_match" (ByVal myHandle As Long, ByVal Text As String, ByVal startpos As Long, ByVal result As Long)
Declare Function result_ismatched Lib "libdeelx" Alias "result_ismatched" (ByVal result As Long) As Long
Declare Function result_start Lib "libdeelx" Alias "result_start" (ByVal result As Long) As Long
Declare Function result_end Lib "libdeelx" Alias "result_end" (ByVal result As Long) As Long
Declare Function LoadLibrary Lib "KERNEL32.DLL" Alias "LoadLibraryA" (ByVal s As String) As Long
Declare Function FreeLibrary Lib "KERNEL32.DLL" Alias "FreeLibrary" (ByVal hLibModule As DWord) As Long

Dim myHandle As Long
Dim result As Long
Dim mylib As String
Dim hinst As Long
mylib = "libdeelx.dll"
myHandle = LoadLibrary(mylib)

If myHandle = 0 Then
MsgBox 0,"libdeelx cannot be found"
End If

myHandle = regexp_create()
result = result_create()

'regexp_compile myHanfle, "23", 0
regexp_match myHandle, "ww123456", -1, result
MsgBox 0, "Error, regexp_compile myHanfle doesn't go! "

If result_ismatched(result) <> 0 Then
MsgBox 0,Str$(result_start(result))
MsgBox 0,Str$(result_end(result))

Else
'...
End If

result_free result
regexp_free myHandle

Peter

peter
07-01-2011, 18:44
sorry Petr,

I didn't see your post!

Petr Schreiber
07-01-2011, 18:47
No problem!

Thanks for helping Zak!

Just one thing - when using DECLARES with LIB and ALIAS, it is not needed to use LoadLibrary.


Petr

zak
07-01-2011, 19:23
thank you Petr and Peter :p very much, i have spent 3 days trying to see where is the problem, so it is the Alias.
also i remember Eros said once in an old post that no need to use LoadLibrary since thinbasic do all the stuff once we use declare.
best wishes
zak

ErosOlmi
07-01-2011, 23:03
Thanks a lot for helping so quickly.
Yes, once you have declared your external DLL functions, they become native functions in thinBasic script so there is no need to manually get pointers to library (LoadLibrary) and to functions (GetProcAddress) because thinBasic does it for you

Just one consideration about the DLL: it requires MSVCRT.DLL (http://support.microsoft.com/kb/259403) that is the Microsoft Visual 6 C++ Runtime. It should be present in almost all Windows computer but you cannot be sure 100%

Ciao
Eros

kryton9
08-01-2011, 08:12
Microsoft requiring runtimes for c++ has really turned me off of c++.

For instance, Blender3D now requires a certain microsoft c++ runtime on Windows. But from the error you get, you have no idea that is the cause of the error. You have to dig around on forums to find that is the reason a user gets that error.

Just when I warm up to Microsoft they seem to throw a hard punch. I warmed up to them because Windows 7 is so good, but everything else MS is a pain from IE to what they are doing to c++.

John Spikowski
08-01-2011, 09:00
It's tough being a Windows programmer these days. By the time you get your framework written, you're already over budget and crying in your beer.

The CLR direction may be Microsoft's way to stop folks from running Windows applications on anything other than Windows. It's much harder to reverse engineer a blackbox CLR than a bunch of API calls.

I hope Eros doesn't paint himself into a corner with PB and Windows and running on Linux under Wine is as good as it gets.

ErosOlmi
08-01-2011, 11:04
It's tough being a Windows programmer these days. By the time you get your framework written, you're already over budget and crying in your beer.

The CLR direction may be Microsoft's way to stop folks from running Windows applications on anything other than Windows. It's much harder to reverse engineer a blackbox CLR than a bunch of API calls.

I hope Eros doesn't paint himself into a corner with PB and Windows and running on Linux under Wine is as good as it gets.

Considering last "promises" from Microsoft at CES 2011, next Windows version (Windows 8 ???) will run everywhere from usual PC to tablets to smart phones even on ARM processors. And as long as there will be Windows, there will be PB. So PB future seems very bright. But maybe better to talk into another thread not to much abuse of this one that is talking about a library.

John Spikowski
08-01-2011, 11:47
With gigbyte(s) installs of their applications and development tools, how will that be possible?

ErosOlmi
08-01-2011, 13:48
http://www.techflash.com/seattle/2011/01/windows-on-arm-more-details.html
http://www.pcworld.com/businesscenter/article/215693/microsoft_to_put_next_windows_os_on_arm_chips.html

Anyway this may put some doubts
http://www.theregister.co.uk/2011/01/08/intel_shows_no_fear_of_windows_arm_deal/