Tech Support > Microsoft Windows > Development Resources > Re: [Rookie] Date-Function, calling external files. JAVA -> C
Re: [Rookie] Date-Function, calling external files. JAVA -> C
Posted by Jugoslav Dujic on July 18th, 2003


Raskolnikow wrote:
[c.l.c. snipped]
| I have some beginner questions about C(++),
| so please be gentle if the things I ask are trivial.
|
| What I want to do is a program (in Windows) that
| - changes the current system date,
| - calls an external program and
| - resets the system date again (after a delay).
|
| I have just written that in Java, but I wanted it to
| be a small and nice tool (i.e. without loading the VM)
| in C or C++, so perhaps someone can help me
| converting it.
| Unfortunately I have only Borland C++ 5.5 and
| TurboC 2.0. Which compiler options can I use to
| make the executable as small as possible ?
<snip>

OK, here's the outline -- fill in the missing pieces by reading
the docs:

#include "windows.h"

int WINAPI WinMain(
HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int
nCmdShow )
{
SYSTEMTIME newST, oldST;
HANDLE hProcess;
STARTUPINFO SI;
PROCESSINFO FI;
GetSystemTime(&oldST);
newST.dwYear = ...
SetSystemTime(&newST);

ZeroMemory(&SI, sizeof(SI));
SI.cb = sizeof(SI);
if (hProcess = CreateProcess("C:\\Program Files...\\Whatever.exe", NULL,
NULL, NULL,
FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &SI, &PI))
{
// Wait until the process dies. You can replace it with a Sleep() if
it's not
// necessary to wait that long.
WaitForSingleObject(PI.hProcess, INFINITE);
}
else
{
MessageBox(NULL, "Error", "Creation of the process failed!", MB_OK).
}
SetSystemTime(&oldST);
}

Check your compiler's documentation about how to build a Windows application
(you can use normal console application with main() instead of WinMain --
this one, however, will not create any windows). Check the docs about how
to specify libraries -- in order to minimize size, you should probably link
with "DLL Run-time libraries" or whatever it's spelled in Borland.

....and, yes, tell the authors of Whatever.exe that they should pay some more
attention to protection ;-).

--
Jugoslav
___________
www.geocities.com/jdujic