Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Converting C# DateTime field into Native C object

Reply
Thread Tools

Converting C# DateTime field into Native C object

 
 
minboymike
Guest
Posts: n/a
 
      03-23-2006
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?

 
Reply With Quote
 
 
 
 
Vladimir S. Oka
Guest
Posts: n/a
 
      03-23-2006

minboymike wrote:
> 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.

--
BR, Vladimir

 
Reply With Quote
 
 
 
 
minboymike
Guest
Posts: n/a
 
      03-23-2006
Hello,

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

Here is a link:
http://msdn.microsoft.com/library/de...classtopic.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).

 
Reply With Quote
 
Vladimir S. Oka
Guest
Posts: n/a
 
      03-23-2006

minboymike wrote:
> Hello,
>
> The DateTime object i am speaking about is found under .NET.
>
> Here is a link:
> http://msdn.microsoft.com/library/de...classtopic.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.

--
BR, Vladimir

 
Reply With Quote
 
minboymike
Guest
Posts: n/a
 
      03-23-2006
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.

 
Reply With Quote
 
void * clvrmnky()
Guest
Posts: n/a
 
      03-23-2006
minboymike wrote:
> Hello,
>
> The DateTime object i am speaking about is found under .NET.
>
> Here is a link:
> http://msdn.microsoft.com/library/de...classtopic.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.
 
Reply With Quote
 
minboymike
Guest
Posts: n/a
 
      03-23-2006
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: [2.4.4] creating a datetime.datetime from an XML xs:dateTime skip@pobox.com Python 2 01-06-2009 01:31 PM
[2.4.4] creating a datetime.datetime from an XML xs:dateTime Martin Python 0 12-27-2008 08:08 PM
mx.DateTime to datetime.datetime mp Python 1 07-28-2006 10:57 PM
datetime: .datetime-.datetime = .timedelta, .time-.time=TypeError ? Christos TZOTZIOY Georgiou Python 3 09-13-2003 10:44 AM
RE: datetime: .datetime-.datetime = .timedelta, .time-.time=TypeError ? Tim Peters Python 0 09-09-2003 12:57 AM



Advertisments