ufairiya / mongoose

Automatically exported from code.google.com/p/mongoose
MIT License
0 stars 0 forks source link

Using mongoose.dll from Visual Basic 6.0 #88

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Is there any option for using mongoose.dll from Visual Basic 6.0????

I can use mg_start() and mg_set_uri_callback(), but when the control
returns to my callback function in vb, program crashes.

I'm trying with the following code:

Declare Function mg_start Lib "mongoose.dll" () As Long
Declare Function mg_set_option Lib "mongoose.dll" (ByVal ctx As Long, ByVal
opt_name As String, ByVal opt_value As String) As Long

Declare Sub mg_set_uri_callback Lib "mongoose.dll" (ByVal ctx As Long, _
                                                                  ByVal
uri_regex As String, _
                                                                  ByVal
func As Long, _
                                                                  ByVal
user_data As String)

Declare Function mg_write Lib "mongoose" (ByVal conn As Long, ByVal fmt As
String, ByVal the_len As Long) As Long
Declare Sub mg_stop Lib "mongoose.dll" (ByVal ctx As Long)

Declare Function mg_version Lib "mongoose.dll" () As String

Public Function UriHandler(ByVal conn As Long, ByVal info As Long, ByVal
userdata As String)
Dim i As Integer

    i = 0
End Function

Public Sub InitMongoose()
On Local Error GoTo err
Dim ret As Long
Dim ud As String * 1024
Dim version As String * 5

    version = mg_version()

    ctx = 0

    ctx = mg_start()
    ret = mg_set_option(ctx, "ports", "9090")
    ret = mg_set_option(ctx, "root", "C:\\")

    ud = "hello"
    Call mg_set_uri_callback(ctx, "/vb", AddressOf UriHandler, Chr(0))

    Exit Sub
err:
    MsgBox err.Description
End Sub

Original issue reported on code.google.com by patogat...@gmail.com on 2 Sep 2009 at 6:57

GoogleCodeExporter commented 9 years ago
I believe VB is crashing because it expects __stdcall exports. Mongoose's API is
exported as __cdecl. VB cleans up the stack, and so does Mongoose, leading to 
stack
corruption.
There are couple of soultions can be found on Internet.

Original comment by valenok on 2 Sep 2009 at 8:54

GoogleCodeExporter commented 9 years ago
i want to someone do my code from VB 6.0!
How to i make antivirus system but that who
doesnt wrealy see viruses in my compyter also he must
to look like he doing that phisicly!

                       I'm sorry becouse my bad writting
                           i'm from the Serbia!

Original comment by pilly.va...@gmail.com on 30 Sep 2009 at 8:54

GoogleCodeExporter commented 9 years ago
The VB6 and older does not work support multi-threading, so correcting the call 
convention may not solve the problem, because the dll is multi-threaded...

If more than one thread call the callback function at the same time we can have 
problems in VB6. But in VB.Net there is no problems.

Original comment by k...@krog.cjb.net on 13 May 2010 at 12:52

GoogleCodeExporter commented 9 years ago

Original comment by valenok on 7 Sep 2010 at 8:45