Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Possible Bug
#1
Hi, I'm trying to make a small function that allows you to call DLL's from the LoadLibrary and GetProcAddress functions. However the following code doesn't compile.

Code:
'$Include: 'win\kernel32.bi'
Declare Function DLLFunc(dllname As String, dllfunc As String) As Integer

Dim MsgBox As Function (hwnd As Integer, lptext As String, lpcap As String, msgtype As Integer) As Integer

Function DLLFunc(dllname As String, dllfunc As String) As Integer
Dim dllhand As Integer, tempfunc As Integer

dllhand = LoadLibrary(dllname)

If dllhand Then
   tempfunc = GetProcAddress(dllhand, dllfunc)

   If tempfunc Then
      DLLFunc = tempfunc
   Else
       DLLFunc = 0
   End If
Else
    DLLFunc = 0
End If

End Function

MsgBox = DLLFunc("user32.dll","MessageBoxA")

Print MsgBox(0,"Test", "Test",0)

Do Until Inkey$ <> ""

Loop

The problem is in the lines with dllhand = LoadLibrary(dllname) and
tempfunc = GetProcAddress(dllhand, dllfunc).

The following which does compile does not work either:

MsgBox = GetProcAddress(LoadLibrary("c:\windows\system32\user32.dll"), "MessageBoxA")

Help? Smile

Thanks,
Kris
Reply
#2
Hmm, another check to do, arguments with same name as the function itself (dllFunc is a function and dllfunc is a string argument too), will fix later..

Working code:

Code:
'$include: 'win\kernel32.bi'
Declare Function DLLFunction(dllname As String, dllfunc As String) As Integer

Dim MsgBox As Function (byval hwnd As Integer, byval lptext As String, byval lpcap As String, byval msgtype As Integer) As Integer


Function DLLFunction(dllname As String, dllfunc As String) As Integer     
    Dim dllhand As Integer, tempfunc As Integer

    dllhand = LoadLibrary(dllname)

    If dllhand Then
           tempfunc = GetProcAddress(dllhand, dllfunc)

           If tempfunc Then
              DLLFunction = tempfunc
           Else
               DLLFunction = 0
           End If
    Else
        DLLFunction = 0
    End If

End Function

    MsgBox = DLLFunction("user32.dll","MessageBoxA")

    Print MsgBox(0,"Test", "Test",0)

    Do Until Inkey$ <> ""

    Loop
Reply
#3
Thanks! Stupid me. BTW, do you think you will support calling DLL's directly with the Declare Lib command anytime in the future? If not it's cool. Good job with the quick progress of the compiler! Smile
Reply
#4
Just make an import lib for the DLL.
Reply
#5
That's cool but It would be easier just to be able to call it directly.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)