Call Exported DLL Function

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jazu100
Posts: 4
Joined: 25 Apr 2009 00:54

Call Exported DLL Function

#1 Post by jazu100 » 25 Apr 2009 01:39

Hi all,

I have created handy and portable command line utility that is
able to call dllexported functions:
http://www.2shared.com/file/5485995/4b969d2c/_call.html

Few examples how to use it:

Display message box with yes and no buttons

Code: Select all

@echo off
_call user32.dll MessageBoxA -d 0 -s "Yes or No?" -s "Question" -d 36
rem 36 = MB_ICONQUESTION+MB_YESNO

if %errorlevel% == 6 (goto :yes) else (goto :no)

:yes
echo Yes!
pause > nul
exit
:no
echo No!
pause > nul
exit


Get input typing time

Code: Select all

@echo off
echo Type your name:
_call kernel32.dll GetTickCount
set /a start=%errorlevel%
set /p name=Name :
_call kernel32.dll GetTickCount
set /a end=%errorlevel%
set /a diff=%end%-%start%
echo Hi, %name%. It took you %diff% ms to type your name.
pause > nul
exit


Change your wallpaper...

Code: Select all

@echo off
echo Type your wallpaper file. This must be bitmap (bmp)
set /p img=Bitmap path (bmp) :
_call user32.dll SystemParametersInfoA -d 20 -d 0 -s "%img%" -d 3
echo Wallpaper should be changed now. Press any key.
pause > nul
exit


And string length:

Code: Select all

@echo off
set /p str=Type something :
_call msvcrt.dll strlen -s "%str%"
echo String length: %errorlevel% chars


have fun :D

pusofalse
Posts: 3
Joined: 28 Apr 2009 05:34

#2 Post by pusofalse » 28 Apr 2009 11:20

Hi jazu100,

Please how can I call the functions with a pointer parameter, for example:

The second parameter of the GetProcessImageFileName(in psapi.dll library) function is a pointer to a buffer that receives the full executable path of the specified process, how should I declare the structure and get its pointer, thanks in advance!

jazu100
Posts: 4
Joined: 25 Apr 2009 00:54

#3 Post by jazu100 » 29 Apr 2009 04:41

Hi pusofalse,
I'm sorry but the first release doesn't handle pointers, it only passes arguments to functions. The first release was mostly for test if somebody
really needs utility like that.
But no problem, of course I can do another more improved release
and I will post it here soon!

Batcher
Posts: 74
Joined: 16 Apr 2009 10:36

#4 Post by Batcher » 29 Apr 2009 09:02

Hi jazu100,

You're so kind! I'm waiting for the next release.

BR/Batcher

pusofalse
Posts: 3
Joined: 28 Apr 2009 05:34

Re jazu100:

#5 Post by pusofalse » 29 Apr 2009 11:26

I see, thanks a lot! I am also waiting for your next release!

jazu100
Posts: 4
Joined: 25 Apr 2009 00:54

#6 Post by jazu100 » 30 Apr 2009 01:04

Hello again, I'm back with a new release! 8)

New features and fixes:
- It has now support for string pointers (dll out, in/out)
- Support for hex decimals
- Return value can be used as handle to anyting!
-> Three new definition selectors: -s' (str in/out), -s# (str in) and -x (hex decimal)
- Better help screen

Still missing:
- Support for structures (e.g. COORD {X,Y})
- Decimal pointers (app may crash if you try)

Pointer example:

Code: Select all

@echo off
_call msvcrt.dll gets -s# input
echo You typed %input%.
pause > nul
:: Don't take this as habit ;) "set" is better...


Never thought that this pointer system was so hard to create...
Applications aren't able to set environment variables for
different application (in this situation _call.exe -> cmd.exe)
(I read it here). So "_call" must inject piece of code to cmd's process that will call SetEnvironmentVariableA -function "inside" cmd!

New release can be found ~here~.
I also added zip containing few funny examples.
If you accept updates and new features, keep watching that drop,
it's possible that I will improve "_call".

And please report bugs and suggest new features if you like it!

pusofalse
Posts: 3
Joined: 28 Apr 2009 05:34

#7 Post by pusofalse » 01 May 2009 05:47

Re jazu100:

Nice job! It's really powerful!

If I find bugs, I'll report to you. Thanks a lot!

Post Reply