|
DavidCrow wrote: Hey, another Oklahoma fan.
Or Kyle has strayed out of the Soapbox again.
led mike
|
|
|
|
|
Cedric Moonen wrote: So, did you do it ?
Indeed he did. And the debugger reported:
Unhandled exception at 0x00413641 of application.exe: 0xC0000005:
the server application window disappeared
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.
[my articles]
|
|
|
|
|
Please make sure there is no curse cast on your software
|
|
|
|
|
Ehm... I'm quite sure there is, actually...
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.
[my articles]
|
|
|
|
|
CPallini wrote: 0xC0000005
That is an access violation. Did you renew your passport in time?
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- 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 PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
I was about to remove or mangle the number, but, after a quick look at the forum, I said to myself: "Don't worry buddy, Luc isn't around... "
My bad!
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.
[my articles]
|
|
|
|
|
I'm always lurking around, and access violations don't go unnoticed.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- 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 PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Hello,
I'm banging my head on a problem that I first though will be easy to solve.
I have a date contained in a COleDateTime object and I would like to 'increment' it. For example, I would like to add one month, or two days, or 3 years, ... This is will always be one single component of the date (second, minute, hour, day, month or year) but this could overflow.
Suppose my date is 31 November 2007 and I would like to add two months to it, the result should be 31 January 2008.
I know that I can use the COleDateTimeSpan class but it only supports Days, hours and seconds, not months and years . And I really don't want to calculate the number of days that correspond to a month increase (being too variable).
Does anybody know how I can solve the problem ? Maybe by manipulating the wrapped DATE object (which correspond to a double) but I don't know exactly how to do that.
|
|
|
|
|
Well, the tricky part is the month addition, since for seconds, minutes, hours, days you can indeed use COleDateTimeSpan objects.
I suggest a dirty but simple workaround: call GetMonth (and GetYear , and...) on the COleDateTime object, add the amount of months required, handle overflow (it is a simple matter of month%12; and year+=month/12; , you know... ) and use SetDate (or SetDateTime ) method to obtain the final result.
Adding years is similar though much simpler.
I know is ugly hybrid design, but using directly the raw double value don't free you froma making the daunting number of days calculation.
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.
[my articles]
|
|
|
|
|
Yes, that's right. I didn't think about that (sometimes you are just too concentrated on one part of your problem and fail to see other paths). One little annoying thing is that, when I change the year or month I'll need to "set back" the day, hour, minute and second parts. But that's a small price to pay for a working solution
Thanks !
|
|
|
|
|
You know, you're welcome.
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.
[my articles]
|
|
|
|
|
Cedric Moonen wrote: Suppose my date is 31 November 2007 and I would like to add two months to it..
The problem is that a month does not have a constant value.
Also, suppose you wanted to add three months to the date. Since February does not have 31 days, do you stop at February 28, or go 3 days into March? If the latter, it looks odd since March would then be four months away.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: The problem is that a month does not have a constant value.
Yes I know and that's what complicate my problem .
DavidCrow wrote: Also, suppose you wanted to add three months to the date. Since February does not have 31 days, do you stop at February 28, or go 3 days into March? If the latter, it looks odd since March would then be four months away.
Well, I see now that my example was very badly chosen. In fact, when I increment a date by a certain amount of months, it will always start at the 1st of the month (so, November 1st + 3 months = February 1st).
But CPallini's answer is the way to go I suppose (didn't implement it yet).
|
|
|
|
|
Cedric Moonen wrote: But CPallini's answer is the way to go I suppose (didn't implement it yet).
It looks to be a viable solution:
COleDateTime AddMonths( const COleDateTime dt, const int nMonthsToAdd )
{
COleDateTime dateTemp;
int nMonth = (dt.GetMonth() - 1) + nMonthsToAdd,
nYear = dt.GetYear(),
x = 0;
dateTemp.SetStatus(COleDateTime::invalid);
while (dateTemp.GetStatus() == COleDateTime::invalid && x < 4)
{
dateTemp.SetDateTime(nYear + (nMonth / 12),
(nMonth % 12) + 1,
dt.GetDay() - x,
dt.GetHour(),
dt.GetMinute(),
dt.GetSecond());
x++;
}
return dateTemp;
}
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hello everyone,
I need to know the wide character (unicode) and multibyte (UTF-8) values of a character string of czech. I personally know nothing about czech. Is the following approach correct?
1. I use L on the character string and watch memory to get the wide character representation of the character string in little endian form;
2. I change the computer region/language to czech, and use function WideCharToMultiByte, and use CP_ACP as input code page and use the L character string as input to get the output multibyte character string output from parameter lpMultiByteStr.
Is (1) and (2) correct? Any more efficient and smart ways?
thanks in advance,
George
|
|
|
|
|
try this
wcstombs function.
i think this will help you.
|
|
|
|
|
Hi Nitheesh,
Is this function relates to my question? I think I am using almost the same approach. Could you describe the steps to get wide character and multibyte value for a given czech character string please?
regards,
George
|
|
|
|
|
Who gives you a czech string?
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.
[my articles]
|
|
|
|
|
Hi CPallini,
I am parsing some information of multi-language. Could we come back to the original question please?
Any ideas?
regards,
George
|
|
|
|
|
Well, IMHO if you have the string then you either already have the Unicode or the Multibyte format of it, hence you need only one conversion.
BTW What's the difficult about examininig a character of a string?
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.
[my articles]
|
|
|
|
|
Thanks CPallini,
Sorry that I may not make myself understood enough. I only have the literal format. The strings are something like MÍST, I want to get the wide character binary value and the multibyte binary value,
1. To get the wide character binary value, I use L"MÍST" and use debug mode to watch its internal buffer in Visual Studio.
2. To get the multibyte (UTF-8) binary value, I use WideCharacterToMultibyte API to convert L"MÍST" to multibyte value;
Is (1) and (2) correct solution?
regards,
George
|
|
|
|
|
George_George wrote: 1. To get the wide character binary value, I use L"MÍST" and use debug mode to watch its internal buffer in Visual Studio.
Fine. Since wide chars are unsigned shorts, I'm sure you're also able to figure out how programmatically find the encoded values.
George_George wrote: To get the multibyte (UTF-8) binary value, I use WideCharacterToMultibyte API to convert L"MÍST" to multibyte value;
When you use WideCharacterToMultibyte you must be aware that (of course) not all wide string characters can be mapped to the codepage you're specifying (I'm not an expert, but I think CP_UTF8 gives you have unmapped chars than Czech codepage (1250?))
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.
[my articles]
|
|
|
|
|
Thanks CPallini,
1.
CPallini wrote: Fine. Since wide chars are unsigned shorts, I'm sure you're also able to figure out how programmatically find the encoded values.
I just use the unsigned short value itself (as binary hex value format). You mean we need additional conversion?
2.
CPallini wrote: but I think CP_UTF8 gives you have unmapped chars than Czech codepage (1250?))
Good point! I missed it. You mean using 1250 as code page value is better?
How do you find the magic value numebr 1250, in some Windows header (.h) file?
regards,
George
|
|
|
|
|
George_George wrote: How do you find the magic value numebr 1250, in some Windows header (.h) file?
here http://www.microsoft.com/globaldev/reference/WinCP.mspx[^], for instance.
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.
[my articles]
|
|
|
|
|
Thanks CPallini,
Good link!
When using WideCharacterToMultiByte or using debugger to see the hex binary value of L string, there is no need to change the language setting of control panel, right?
regards,
George
|
|
|
|
|