Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SystemTimeToFileTime problem

Status
Not open for further replies.

cadoltt

Programmer
Jun 9, 2005
85
CA
Hi everybody,

Here is a simple code I am trying to get work:

Code:
int main()
 {
  SYSTEMTIME    st = {2000,10,15,0,0,0,0,0};
  FILETIME      ft;
  int intRet;
  LPVOID lpMsgBuf;
  char chrMsg[256];

  intRet = SystemTimeToFileTime(&st,&ft);


  FormatMessage
   (
    FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
    NULL,
    GetLastError(),
    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
    (LPTSTR) &lpMsgBuf,
    0,
    NULL
   );

  sprintf(chrMsg, "%s\n", lpMsgBuf);

  return 0;

 }//int main()


But the SystemTimeToFileTime function gives me an error message: 'The parameter is incorrect'.


Can anyone tell me what is wrong with the code?

I am using Borland C++ Builder-3.

Thanks,

Alex
 
A fast check tells me that
SYSTEMTIME st = {2000,10,15,0,0,0,0,0};
FILETIME ft;
should be
const SYSTEMTIME st = {2000,10,15,0,0,0,0,0};
const FILETIME ft;
or that you should cast a little:
intRet = SystemTimeToFileTime(&(const)st,&(const)ft);

Just off the top of my head....

Totte
Keep making it perfect and it will end up broken.
 
Hi Totte,

Thanks for responding.

The code I posted is just a simplified piece. In reality I need to copy files from one directory to another but only those whose last update satisfy a certain time range. This time range I am giving as two parameters from the command line. So I need those st and ft as variables, not constants.

But I tried your suggestion anyway and it didn't work. By the way only st can be a constant as it is being initialized in the piece of code I posted. Declaring it as a constant didn't help - I got the same runtime error message.

Casting (&(const)st,&(const)ft) gave me errors on compilation: "Cannot cast from '_SYSTEMTIME' to 'int'" and "Cannot cast from '_FILETIME' to 'int'".


More ideas?...

Alex
 
Try looking at the TDateTime class; It's functionality will probally be more helpful for your purposes. You would be able to convert a string version of the date (as passed by the commandline) to a TDateTime variable, and from there convert directly to a DOS Date time stamp with the FileDate memeber function.

The simplest solution is the best!
 
I think I see two things wrong First, SystemTimeToDateTime is expecting a single value (at least according to my help files), and second, SystemTimeToDateTime wants to return a TDateTime type. You are trying to return an integer. The following code is an example from my help files

Code:
SYSTEMTIME SystemTime;
GetLocalTime(&SystemTime);
TDateTime SysDatTim = SystemTimeToDateTime(SystemTime)

For a good article on date and time functions, see
James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!
 
Prattaratt, 2ffat,

Thank you for taking part in it.

What #include should I add to use the class TDateTime? I thought it's <vcl.h> but got a compilation time error: Undefined symbol 'TDateTime'.


...Alex
 
The functions are defined in systdate.h. Odd, though, I've never had to manually include the header file as the IDE will usually auto include it for me.

James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!
 
2ffat,

I added the include but another strange thing is happening now, it tells "Unable to open include file 'systdate.h'"

Do I need to change something in my settings to make it work? - I am using Borland C++ Builder-3.


Thanks,
Alex
 
First, do a search for the systdate.h file on your system.

Second, if your settings are the default that Borland set up, you shouldn't have to change anything. I've been using TDateTime since BCB3 without any problems so it surprises me that you are having some.

James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!
 
You need to check your project directory settings; your include directory settings should have the following:
{$BCB}\include;{$BCB}\include\vcl;
Followed by any other project specific directories other than the current project dir.

The simplest solution is the best!
 
Gents,

Thanks a lot for your support.

Here is what I did:

1. Code (daytime2.cpp) I am trying to compile

Code:
#include <condefs.h>
#include <Windows.h>
#include <systdate.h>

void main()
 {
  SYSTEMTIME SystemTime;
  GetLocalTime(&SystemTime);
  TDateTime SysDatTim = SystemTimeToDateTime(SystemTime);
 }

2. Settings in Project Options:

Include path: $(BCB)\include;$(BCB)\include\vcl;
Library path: $(BCB)\lib\obj;$(BCB)\lib

3. Settings in Environment Options:
Library Path: $(BCB)\LIB;$(BCB)\LIB\OBJ


On compilation I am getting the following message:
Unable to open include file 'systdate.h'.

If I comment out the line '#include <systdate.h>' I am getting a linker error:

Unresolved external 'Sysutils::SystemTimeToDateTime(const _SYSTEMTIME&) __fastcall' referenced from M:\AP\C\CB\TIME2\DAYTIME2.OBJ.

???

Sorry for my stupidity and all the trouble I am making...

Alex
 
I only have two ideas left. One, the header file is corrupt. Can you locate the file and open it with an editor. If you can, then the file should be OK.

Two, it looks like you are writing a program to run at the command prompt. It MAY be that some other header files are needed that the IDE includes by default that you might not be including manually. I'll have to look around when I get the time.


James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!
 
2ffat,

I've checked if the file systdate.h exist in Borland folders and it doesn't. Strange thing.

I've found though what was wrong in the first code. When trying to create a SYSTEMTIME var I initialized it as

st = {2000,10,15,0,0,0,0,0}.

But the thing is that the third parameter in the structure is not the day of month, it is the day of the week, and the day of month is the fourth parameter. So if to initialize like this

st = {2000,10,0,15,0,0,0,0}

it works. How stupid of me.


I will aprreciate you help with that systdate.h business when you have time. I really want those things working.


Thank you, and all the the guys helping me with the stuff.


Alex
 
Are you using the free command line compiler or the CBuilderX IDE? if so the vcl header files aren't included; this would explain why you can't find the systdate.h file. If you are using the C++Builder Develpment program, the systdate.h will be in the \include\vcl directory. if that directory doesn't exist, you have a bad or corrupt install; I recommend a re-install.

The simplest solution is the best!
 
Prattaratt,

I am using CBuilder3 IDE. And there is no such header file in the include\VCL folder. I'll try to re-install.

Thank you.


Alex
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top