Call external function from bat file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
boogy
Posts: 1
Joined: 07 Sep 2016 02:08

Call external function from bat file

#1 Post by boogy » 07 Sep 2016 02:11

Hi,i was wondering if i can call a function i have in my Visual Studio project from a batch file

e.g : The function Logoff() from Form1 in my project to be called when the bat file is opened


penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Call external function from bat file

#3 Post by penpen » 07 Sep 2016 07:13

Depends on your c++ source, and how you compile it, and what you allow for "calling from batch".

It should be possible if you compile your source as dll (and correctly export this function):

Code: Select all

extern "C" __declspec(dllexport) <return type> __cdecl myfunc(<paramlist>) {
   // function body
}
(Edit: Should also be possible for VB.NET, but i'm not familiar with this.)

Then you could write a batch/c# hybrid, to compile an executable that calls the above c++ function.
You could also use powershell to call the c# code (which probably compiles an executable temporary).

For both solutions this may be of interest:
http://www.dostips.com/forum/viewtopic.php?p=45441#p45441


penpen
Edit: Added a comment.

Post Reply