|
Hi!
how do i convert a date to struct tm?
i want to get day of week for this date.
this code has a run time error:
int yy = 2010;
int mm = 07;
int dd = 12;
struct tm tt;
time_t t;
yy -= 1900;
tt.tm_mon = mm;
tt.tm_year = yy;
tt.tm_mday = dd;
t = mktime(&tt);
struct tm *tt2 = localtime(&t);
int ii = tt2->tm_wday;
please help me.
Zo.Naderi-Iran
|
|
|
|
|
zon_cpp wrote: time_t t;
time_t t = {0};
i.e. never, never, never forget variable initialization.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I can't see what's wrong with your code (but there could be something in there, it's a bit convoluted) but this works on my compiler and uses the same function calls:
std::tm t = { 0, 0, 12, 13, 6, 110 };
std::time_t int_rep( std::mktime( &t ) );
t = *std::localtime( &int_rep );
std::cout << std::asctime( &t ) << std::endl;
It's a bit disgusting but seems to get the job done. I'd be tempted to wrap it up in a function though:
int day_of_week( int day, int month, int year )
{
std::tm t = { 0, 0, 12, day, month - 1, year - 1900 };
std::time_t gratuitous_l_value( std::mktime( &t ) );
return std::localtime( &gratuitous_l_value )->tm_wday;
}
If you're programming in C and not C++ just remove the std:: everywhere, include time.h and not ctime and convert the constructor style initialisations to = and it'll probably work.
Cheers,
Ash
|
|
|
|
|
I have a graphics application which is written in Borland C++ using various classes like TDC, TPen, etc. which I have to convert into Visual C++ application with MFC. What is the best approach to make this more efficient and less time consuming? Is there any third-party library which has Visual C++ wrappers for Borland C++? Please suggest.
|
|
|
|
|
I dont think its possile as I did a try to convert a .cbproj to .vcproj. ie: from rad studio to visual studio. but the project used some vcl.h which is unavailable in visual studio. so making gui is totally depended on ide. you can adopt any code from bc++ proj and manipulate in your vcproj but not gui part.
|
|
|
|
|
Would probably use .NET and then compile your C++ code as managed code using the /clr switch (VS2005 and newer supports this).
.NET Winforms is much closer to Borland VCL library.
If .NET is not an option and wanting to stick to the C++ guns, then you should take a look at Qt, as it ressembles the OO principles of VCL. Or maybe tryout the OWLNext as it should actually be the open source version of Borland C++ GUI library (But it is not VCL).
Converting an application to MFC will not win you any awards.
modified on Monday, December 6, 2010 5:34 PM
|
|
|
|
|
Hi I am creating a datetime control derived from the CDateTimeCtrl. I want to place images on the both up and down arrow of the control. Can anyone pplease help me how to do that..
Thanx..
|
|
|
|
|
Hi sir,
I am doing some mathematical calculation.
where i am reading values from Dialog edit box control.
Here is .h file
ex.h
Dialog Data
enum { IDD = IDD_DIALOG_SOURCE_DETAILS };
CMSMask m_val1;
CMSMask m_val2;
CMSMask m_val3;
here is .cpp file
m_val1.GetText();
m_val2.GetText();
m_val3.GetText();
I am using this exp to get the result
A = B Exp(-0.693 * t/T)
B = m_val1.GetText();
t = m_val2.GetText();
T = m_val3.GetText();
I am trying with this.
h = (-0.693 * t/T);
res = B^h;
Can i pass the values(B,t an T) directly to the expression and get the result or i convert it to double(using atof).
Thanks
Raj
|
|
|
|
|
GetText as the name indicates must be returning strings.
You cannot evaluate expressions on strings.
So you have to first do the conversion.
|
|
|
|
|
You'll have to use something like atof (excuse me while I rinse my fingers off for typing that) or another conversion. What you get off the controls is a string of some sort.
Secondly are you sure your maths is correct? Is:
A = Kexp( -kt )
really
A = K ^ (1 / kt )
or is it
A = K * e ^ (-kt)
where ^ is "raising to the power of"? Most maths texts I've read would say the later, which makes your equation something similar to the one describing radioactive decay, capacitor discharge or acoustic attenuation. Actually thinking about it are you sure the equation isn't:
A = K * 10 ^ (-kt )
as -0.693 is the natural log of 0.5 (IIRC)? This is a big hint to me that T is actually a half-life and something's got very bent in translation.
Final point: C++ has an ^ operator, but it's not going to help you with your code. You're going to need either std::exp or std::pow to get a result here.
Cheers,
Ash
|
|
|
|
|
Hi,
I use this code to terminate calc.exe on Windows Vista and Windows 7
DWORD fdwExit = 0;
HANDLE hProcess = GetProcessHandle("calc.exe");
GetExitCodeProcess(hProcess, fdwExit);
TerminateProcess(hProcess, fdwExit);
CloseHandle(hProcess);
On Windows XP SP3 the above code doesn't have any effect!
any idea? thanks
|
|
|
|
|
TerminateProcess is an iffy call, depending on the dlls and child processes, the code could hang.... Microsoft wrote a "better way" to handle termination:
http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q178893&[^]
basically you send a WM_CLOSE message to the applications main thread and then the application terminates itself. This is similar to what happens to an application when you send a shutdown command while it is running. Of course then you are dependant upon the programmer of the application to have properly handled the WM_CLOSE and terminate.... and we all know all programs exit gracefully and never hang upon shutdown.
_________________________
John Andrew Holmes "It is well to remember that the entire universe, with one trifling exception, is composed of others."
Shhhhh.... I am not really here. I am a figment of your imagination.... I am still in my cave so this must be an illusion....
|
|
|
|
|
Put in some error checking on the return values and debug the program to find out exactly where the problem occurs.
Also, what is GetProcessHandle ?
It is not an API.
It must be a user defined function.
Check if it is returning a valid handle.
|
|
|
|
|
Sorry my mistake, here's the GetProcessHandle void
HANDLE CmyGUIApp::GetProcessHandle(LPSTR szExeName)
{
PROCESSENTRY32 Pc = { sizeof(PROCESSENTRY32) };
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0);
if(Process32First(hSnapshot, Pc)){
do{
if(!strcmp(Pc.szExeFile, szExeName))
{
return OpenProcess(PROCESS_ALL_ACCESS, TRUE, Pc.th32ProcessID);
}
}while(Process32Next(hSnapshot, Pc));
}
return NULL;
}
Debugging the program on Windows 7 where on I have my VC++ installed doesn't show any error or any thing strange, I can terminate any process just by replacing "calc.exe" with another process name, the void above returns the exact process handle and the process gets terminated. Should I debug the program on Windows XP? How? I have only one license of VC++ which is currently installed on Windows 7, can I use WinDbg to debug my program on XP and how? please guide me I am new to all of this staff! Thanks
|
|
|
|
|
If you're familiar with Windbg its fine, but otherwise you could try Remote Debugging[^] in Visual Studio.
|
|
|
|
|
Hi all
Which book is good for MFC Hard disk programing book Or Online tutorial link?
|
|
|
|
|
mdocvc wrote: MFC Hard disk programing
What is MFC hard disk programming ?
Watched code never compiles.
|
|
|
|
|
Maximilien wrote: What is MFC hard disk programming ?
Not easy!
It's time for a new signature.
|
|
|
|
|
I would recommend you this excellent book for MFC if you are advanced [^] and this useful tutorial if you are beginner [^].
Life is a stage and we are all actors!
|
|
|
|
|
Very helpful link. Thanks Hristo!
|
|
|
|
|
|
|
hello guys...im newbie and wanted to learn pocketpc 2003 programing using c++ (using MS VS 2008), but could not find the appropriate book (may be could not find porper key words for query to google). I will be thankful if you suggest me one. Also, I wanted to learn MFC using MS VS 2008, a book on this topic will also be appreiated (i found books on MFC but not MFC using VS 2008).Thanks in advance.
|
|
|
|
|
Muzammil Saeed wrote: may be could not find porper key words for query to google
What could be easier than this[^]?
It's time for a new signature.
|
|
|
|
|
So long story short, I am investigating using Winsock/UDP to communicate between two software packages on separate computers hardwired together.
The issue i am having right away is, on the client&server how do you specify what port/adapter is going to be sending the packets if you have multiple?
I want to be just doing pure UDP broadcast packets(255.255.255.255) as its a point to point connection and setting up IP addresses every time would be too much of a hassle for reasons i wont go into.
|
|
|
|