Code: Select all
@ECHO OFF
SET MB_OK=0
CallDllFunc.exe msvcrt printf "Hex representation of 35 = 0x%%X" @35
CallDllFunc.exe msvcrt.dll puts
callDllFunc.exe user32.dll MessageBoxA @0 "This is a test." "Hello" @%MB_OK%
CallDllFunc.exe msvcrt printf "Backslash symbol \ to escape the ASCII to UInt converter @ , %%s" \@2022
CallDllFunc.bas :
Code: Select all
' Source code compiled with
' FreeBASIC Compiler - Version 1.09.0 (2021-12-31), built for win32 (32bit)
'CallDllFunc Version 1.0
#include "windows.bi"
Const ASCII_At_Symbol = 64
Dim As Ulong argc = __fb_argc__
Dim As ZString Ptr Ptr argv = __fb_argv__
Dim param(1 To 64) As Integer
Dim As Integer stack,i,LastParam,NumbOfParams,ParamNumb=1
Dim As HMODULE hMod
Dim As FARPROC DllFunc
If argc < 3 Then
Print "CallDllFunc library.dll function [parameter1] [parameter2] ..."
End
End If
hMod=LoadLibrary(argv[1])
If hMod=0 Then
Print "LoadLibrary could not load ";*argv[1]
End
End If
DllFunc=GetProcAddress(hMod,argv[2])
If DllFunc=0 Then
Print "GetProcAddress could not find the address of ";*argv[2]
FreeLibrary hMod
End
End If
If argc = 3 Then
Asm Call DWORD Ptr [DllFunc]
Else
For i=3 To argc-1
' ASCII 92 = \
' ASCII 64 = @
' \Q => 64+256*92 = 16476
If *Cast(Ushort Ptr,argv[i])=16476 Then
param(ParamNumb)=Cast(Uinteger,argv[i]+1)
Elseif *Cast(Byte Ptr,argv[i]) = ASCII_At_Symbol Then
param(ParamNumb)=Valuint(*(argv[i]+1))
Else
param(ParamNumb)=Cast(Uinteger,argv[i])
End If
ParamNumb=ParamNumb+1
Next i
LastParam=Cast(Uinteger,@param(ParamNumb-1))
NumbOfParams=argc-3
Asm
push DWORD Ptr [NumbOfParams]
pop ecx
push DWORD Ptr [LastParam]
pop edx
push esp
pop DWORD Ptr [stack]
_loop:
push DWORD Ptr [edx]
sub edx,4
dec ecx
jnz _loop
Call DWORD Ptr [DllFunc]
'Take care to balance the stack if DllFunc is a C function \ __cdecl
push DWORD Ptr [stack]
pop esp
End Asm
End If
FreeLibrary(hMod)