Converting C# DateTime field into Native C object

M

minboymike

Hello everyone,

I am working on a project when I have to convert a C# program into
Native C for speed purposes. I am using a .dll that creates a DateTime
object. Obviously, there is not DateTime object in Native C, but I
would like to know if there is a work-around to parse out the
day/month/year from this DateTime object. Any ideas?
 
V

Vladimir S. Oka

minboymike said:
Hello everyone,

I am working on a project when I have to convert a C# program into
Native C for speed purposes. I am using a .dll that creates a DateTime
object. Obviously, there is not DateTime object in Native C, but I
would like to know if there is a work-around to parse out the
day/month/year from this DateTime object. Any ideas?

There's no such thing as "Native C". Do you mean ISO/ANSI Standard C?

If you want an answer to this, this group actually would be the right
place, had you went to the trouble of telling us what is a DateTime
object, so we can suggest C equivavalent.

If you specify what you need, there surely is a way of doing it in C.
 
M

minboymike

Hello,

The DateTime object i am speaking about is found under .NET.

Here is a link:
http://msdn.microsoft.com/library/d.../cpref/html/frlrfsystemdatetimeclasstopic.asp

Basically, as I said before, I am writing a C program and want to parse
out the day/month/year from this DateTime object, but do not see any
means to do this in C. The time.h library uses time_t object/struct,
but when converting, there is a tyep-mismatch (obviously), causing the
time_t object i created to be set to deafult (1/1/1970).
 
V

Vladimir S. Oka

minboymike said:
Hello,

The DateTime object i am speaking about is found under .NET.

Here is a link:
http://msdn.microsoft.com/library/d.../cpref/html/frlrfsystemdatetimeclasstopic.asp

Basically, as I said before, I am writing a C program and want to parse
out the day/month/year from this DateTime object, but do not see any
means to do this in C. The time.h library uses time_t object/struct,
but when converting, there is a tyep-mismatch (obviously), causing the
time_t object i created to be set to deafult (1/1/1970).

If you're looking to read the binary representation of this (i.e. you
are given a pointer to it), then you really need to know how .NET
stores it. Knowing that, you can construct a C `struct` that matches,
and read it out, or you could just walk through it byte by byte and
reconstruct the fields. This is going to be very non-portable, not
least for the possibility that the raw binary representation in .NET
may change.

You may be better off writing the fields of interest (maybe all) into a
text file, or some file of known, and well defined type, from your .NET
code, and read it out from your C code. For "file" you may substitute
memory buffer as well. NB, I'm suggesting that you design and document
the exchange format used, so it's under your control.
 
M

minboymike

Thanks for such a quick reply....

I understand the approach you are coming from, but unfortunately, had I
had the option to write those specific fields to a file, then read them
into my C program, than i wouldn't have the problem to begin with.
This problem of type mis-matching between .NET object DATETIME and C
seems to be causing the most problems for me. Thanks for giving me your
2 cents! Much appreciated.
 
V

void * clvrmnky()

minboymike said:
Hello,

The DateTime object i am speaking about is found under .NET.

Here is a link:
http://msdn.microsoft.com/library/d.../cpref/html/frlrfsystemdatetimeclasstopic.asp

Basically, as I said before, I am writing a C program and want to parse
out the day/month/year from this DateTime object, but do not see any
means to do this in C. The time.h library uses time_t object/struct,
but when converting, there is a tyep-mismatch (obviously), causing the
time_t object i created to be set to deafult (1/1/1970).

Get the DateTime.Ticks Property and use that to construct a time_t
object. Either pass the long, or an object that contains only this long.
 
M

minboymike

Thanks for the reply!

I found a work around to my problem. The sample code provided with the
..dll I was implementing actually uses a COleDateTime object to store
the DateTime object I was looking at. Simply #include "ATLComTime.h"
did the trick! Thanks for everyone's help on this
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top