|
hi all
i want to use the following code to set the time of the system by some numericUpDown (hour,minute,second) objects that user input, but i don't know where is the problem when i set the time it changes but it does n't correctly change, please have a look at it, it should be something that i may do not know about it, i just have changed a code that i found on the internet, here is the code:
[StructLayout(LayoutKind.Sequential)]
public struct MyDateTime
{
public ushort Year;
public ushort Month;
public ushort wDayOfWeek;
public ushort Day;
public ushort Hour;
public ushort Minute;
public ushort Second;
public ushort Milisecond;
}
[DllImport("kernel32.dll", EntryPoint = "SetSystemTime", SetLastError = true)]
private static extern bool SetSystemTime(ref MyDateTime st);
[DllImport("kernel32.dll", EntryPoint = "GetSystemTime", SetLastError = true)]
private extern static void GetSystemTime(ref MyDateTime sysTime);
MyDateTime Persian;
.
.
.
GetSystemTime(ref Persian);
Persian.Hour = (ushort) hour.Value;
Persian.Minute = (ushort) minute.Value;
Persian.Second = (ushort) second.Value;
SetSystemTime(ref Persian );
thank you everybody
|
|
|
|
|
I don't know the structure the winapi uses for this, but I suppose I would look for clues by seeing how the method to *get* system time works. Or just double-check the structure. It immediately seems odd to me that it would use shorts for day of week, day, hour, minute, and second, all of which logically require just a byte, but I have almost no experience with system level programming so it may well be that I simply don't know what I'm talking about!
|
|
|
|
|
Hm... according to this it would appear the structure is even less compact and uses four bytes (on a 32-bit platform) for each..??
Best of luck!
|
|
|
|
|
I see nothing wrong in what you are doing. Its just that, when you use SetSystemTime(), the time set is UTC - not your local time. So, in order to set your local time, then you need to calculate the difference between your local timezone and UTC (use Offset class to calculate the difference like
Offset diff = DataTime.Now - DateTime.UtcNow). Once you know the time difference, update the hours and minutes by the Offset.Hours, Offset.Minutes and you will get the correct local time set. Hope that helps!!
|
|
|
|
|
Hi guys,
Is there any way through which I can see the list of hidden files in a drive or folder with a console application?
Your help will be appreciated,
Rajdeep.NET
Edit: Are only files with .ini extension invisible? And why do they remain hidden.....Hmmmmmm....A gr8 mystery.....maybe only for me! Help me in this regard somebody!
|
|
|
|
|
By using GetAttributes method you can check it.
mailto: anubhava.prodata@gmail.com
|
|
|
|
|
Rajdeep.NET wrote: Is there any way through which I can see the list of hidden files in a drive
Use Directory.GetFiles . It retruns all files irrespective of hidden status. After getting the file, you need to supply the path into a FileInfo class and check Attributes[^] property. If it has Hidden attribute, consider the file as hidden.
|
|
|
|
|
Hi
I'm using list view to display files and folders of a directory. I suppose to provide an option for sorting that is when i hit column header it should get sort and group which means files should be club together and folders as like XP Windows explorer sorting. For me Name,Size sorting are works fine but date sorting doesn't looks good as files and folders are shuffled together but name and size are works as expected. Please advise.
Thanks
...
|
|
|
|
|
|
Hi All,
I am sending a structure object to another machine through TCP/IP by connecting through socket,so that i have to convert this object into byte array and also viceversa...
Please help me,it is urgent.
Regards,
Lalit Narayan
|
|
|
|
|
/ Convert an object to a byte array
private byte[] ObjectToByteArray(Object obj)
{
if(obj == null)
return null;
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
bf.Serialize(ms, obj);
return ms.ToArray();
}
private Object ByteArrayToObject(byte[] arrBytes)
{
MemoryStream memStream = new MemoryStream();
BinaryFormatter binForm = new BinaryFormatter();
memStream.Write(arrBytes, 0, arrBytes.Length);
memStream.Seek(0, SeekOrigin.Begin);
Object obj = (Object) binForm.Deserialize(memStream);
return obj;
}
[Serializable] attribute need to be enable serialization
|
|
|
|
|
Hi
Thanks for ur reply......
When i am deserializing the object from bytes array,then i am getting error
"Unable to find assembly 'DeviceApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'."
Please give any solution for that.
Regards,
Lalit Narayan
|
|
|
|
|
Hi,
I have a listening port using socket, number of clients will connect with that port. Lot of messages like images,text,docs etc are send between the clients using the listening port. These communication will occur concurrently.
eg: a,b,c,d .... are connected to a listening port. 'A' sent a image to 'B', at that same time 'C' send an text to 'D', 'B' to 'D', 'D' to 'A'.......etc at the same point of time.
My question.
Will the listening port can manage all these correctly?
Will there be any traffic jam? or slow in communucation?
Can the listening port manage any number of clients?
What is the standard way to manage these messages?
Can i open diffrent port for diffrent type of messages?
I am using socket.Blocking = true; method.
Thankyou
YPKI
|
|
|
|
|
If you say
socket.Blocking = true
then it is more like Synchronous call, looks like you might require Asynchronous environment as you are trying to handle multiple clients.
|
|
|
|
|
|
i am writing some code, if will act different ways on x64 and x86,
does there is a way to justify the code is compiled by x64 or x86,
as i know i cpp i can use
#ifdef __x64
doA
#elif __x86
doB
#endif
|
|
|
|
|
sorry, but why the hell is your first name "Dracula"?
dev
|
|
|
|
|
just for fun.
there is a movie with this name, and some games
|
|
|
|
|
Check the Operation System Name.In X64 Bit Operation System have X64.
mailto: anubhava.prodata@gmail.com
|
|
|
|
|
for now, i am just using the return IntPtr.Size == 8,
|
|
|
|
|
Good People,
I have a log file that I open to write to while my application is running. If I don't close it and my application exits, can I write to it again when my application opens? If I don't close it and my application exits, will it cause operating system instability or any other problems?
Thanks,
Blitz
|
|
|
|
|
Hi,
a Windows process cleans up after itself upon exit, no matter what.
So your old log file will be closed; it may however not contains the latest log entries, since these probably were still in some buffers somewhere.
That is why I often implement a log method as an open-for-append, write, close sequence, increasing the probability the last entries are in the file; they probably are the ones you want to see when things suddenly go wrong! Of course open/write/close is slower than a simple write, so you may want to switch back to a simple write in a release build.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Thanks Luc, I appreciate the information.
|
|
|
|
|
How can I read the photo taken date(not the created date or modified date). I found on Google that can be do by propertyItems. There’s no date taken property in Property items.
Is there any possible way to read the photo taken date???
A S E L A
|
|
|
|
|
Some file formats (including JPEG) allow for a lot of metadata, and most camera's seem to provide at least some of these pieces of information.
Here is some code that may be useful to you; I will not provide support on it though.
string s=readImageProperty(image, 0x132);
log("datetime="+s);
DateTime exposureDate=ParseExposureDate(s, equipModel);
log("Exposure DateTime = "+DateToString(exposureDate, false, ""));
private static string readImageProperty(Image image, int ID) {
try {
PropertyItem pi=image.GetPropertyItem(ID);
if(pi!=null) {
if(pi.Type==2) {
return ASCIIencoding.GetString(pi.Value, 0, pi.Len-1);
}
if(pi.Type==5) {
byte[] bb=pi.Value;
uint uNominator=BitConverter.ToUInt32(bb, 0);
uint uDenominator=BitConverter.ToUInt32(bb, 4);
if(uDenominator==1) return uNominator.ToString();
return uNominator.ToString()+"/"+uDenominator.ToString();
}
}
} catch {
}
return null;
}
private static DateTime ParseExposureDate(string exposure, string equipModel) {
DateTime dt=DateTime.MinValue;
bool OK=false;
if(!OK) {
OK=DateTime.TryParseExact(exposure, "yyyy:MM:dd HH:mm:ss",
null, DateTimeStyles.None, out dt);
}
log("ParseExposureDate: \""+exposure+"\" >>> "+dt);
return dt;
}
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|