|
A little update on this....
I used the step-trace to try and get a little more information. It's like the compiler messes up the method memory addresses. The problem only occurs when trying to invoke the DoSomething() method. I can invoke DoSomething2() just fine. But when I try to invoke DoSomething(), instead of the step trace moving into MyClass::DoSomething(), it moves into the system file "towupper.c" and tries to call extern "C" wint_t __cdecl towupper (wint_t c).
How can my class method address get crossed with a system function -- especially when DoSomething() is purely a mathematical routine?
|
|
|
|
|
Could you please help me to understand what ( str_time.substr(11,2) != "00" ) would do
in this code. And what normalise does in this code?
unsigned long normalise(unsigned long input_time)
{
bool finished;
// This produces a formatted time string like:
// Thu_Nov_24_18:22:48_1986
string str_time = format_time( input_time );
while( str_time.substr(1,3) != "Sun")
{
input_time -= 24*60*60;
str_time = format_time( input_time );
}
while( str_time.substr(11,2) != "00" )
{
input_time -= 60*60;
str_time = format_time( input_time );
}
while( str_time.substr(14,2) != "00")
{
str_time = format_time( input_time );
input_time -= 60;
}
while( str_time.substr(17,2) != "00")
{
input_time -= 1;
str_time = format_time( input_time );
}
return input_time;
}
Thank you.
Thank you
|
|
|
|
|
Hi,
Substring is explained in the .NET reference manual (use MSDN or Google).
this strange piece of code takes a datetime number and tries to find the previous
sunday midnight, using lots of strings: it repeatedly converts to string, then
checks for "Sun" in it, takes away 24 hours, etc; then forces the hour to "00", etc.
Obviously all the while loops are redundant: if the hour is 23, then subtracting 23*60*60
could happen straight away; etc.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Hello,
I wish it would sound so easy and for me. Have I understood right that this code will be searching for the previous Sunday midnight and it will return formatted Suday’s date, before Thu_Nov_24_18:22:48_1986, if it was inputted.
Kristina
Thank you
|
|
|
|
|
as you can see it returns an unsigned long (representing seconds since some reference point),
i.e. the input parameter with some days/hours/minute/seconds subtracted.
It is a terrible piece of code, with the .NET Framework one should use the DateTime class
to do the same in a much cleaner way. So that will be your home work for today.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Luc Pattyn wrote: It is a terrible piece of code
Nah. It's a decent piece of code for the daily WTF
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
If it is decent, could you help me to understand, where is one bug? I found one in this statement while( str_time.substr(14,2) != "00")
{
str_time = format_time( input_time );
input_time -= 60; those two statements are all mixed up.
}
And also, could you suggest how would you handle, if the input_time would be "Thu Jan 1 00:00:00 1970" . What do you think about this code’s decency now?
Thank you
|
|
|
|
|
653057337 wrote: What do you think about this code’s decency now?
It has not improved yet.
You asked what it meant, you got that answered. Do you plan on doing anything yourself ?
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Well, perhaps I was a bit harsh about the decency of the code. If it works, I guess nothing's wrong
with it.
653057337 wrote: ould you suggest how would you handle, if the input_time would be "Thu Jan 1 00:00:00 1970"
I guess to fit the method shown, you'd have to check for "year-wrap" and subtract a year's worth
of seconds if necessary.
I personally prefer to work with the COleDateTime class and its companion, COleDateTimeSpan.
COleDateTime handles date/time from Jan 1, 100 to Dec 31, 9999.
With COleDateTime, to find the date/time for the nearest previous Sunday at midnight,
you could
1) find the day of the week for a given COleDateTime (COleDateTime::GetDayOfWeek())
2) Calculate how many days past Sunday it is (COleDateTime::GetDayOfWeek() - 1)
3) Create a COleDateTimeSpan representing the number of days from Sunday and the
hours, mins, and seconds from midnight. (value from step 2 with COleDateTime::GetHour(),
COleDateTime::GetMinute(), and COleDateTime::GetSecond())
4) Subtract the COleDateTimeSpan from the original COleDateTime (COleDateTime::operator -=)
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thank you,
Also I have to think how to answer this question what would be a better implementation of this function, If the input_time represents an integer value in seconds since the epoch – and has the value 0 at precisely "Thu Jan 1 00:00:00 1970". I am totally tired to study this topic; I never studied about this and did not have an opportunity to use practically. I am having headache. I will take a little break for few hours and come back to this later.
Thank you,
Appreciate your help
Thank you
|
|
|
|
|
hi all
I should use from GIF format file for load its in to DOS
but I don't know how I use from LZW code for decode data of image and draw image in consul
plz help me
thanks alot
bye
|
|
|
|
|
Please don't cross-post.
This forum is for Managed C++/CLI.
Regular C++ questions should be posted on the Visual C++/MFC[^] board,
where you also posted this question.
Thanks for your cooperation
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi all.
Here are the two classes one base and other Derived ( virtually inherited from Base)
Class Base
{
Public:
Virtual void FunB(){}
};
Class Derived: virtual public Base
{
Public:
Virtual void FunD(){}
};
When I derived class Derived virtually from Base, and when I saw the memory layout of objects of Derived in debug window; I saw two separate vfptrs; one for Base and one for Derived.
But if I do not derive class Derived virtually from Base, then there is only single vfptr in object of Derived class?
Why an extra vfptr is added/required in case of virtual inheritance?
Sameer Thakur
|
|
|
|
|
Sameer_Thakur wrote: Why an extra vfptr is added/required in case of virtual inheritance?
No, I could not see, if it is added ? Which version of VS you are using ?
P.s. Ask this question in VC++ forum, where it is suited.
Prasad
MS MVP - VC++
|
|
|
|
|
Hi, I am using Visual Studio 2005 C++/CLI. My application has a lot of functions that are used to display information on a Form. Visual Studio starts with a default form called Form1. Because my display depends on what is and is not checked in the Form1->ToolStripMenuItems I placed all of the display code in the Form1 class. What I would like to do is strip all of the display code out of the Form1 class and put it into a class of its own. I can do this but then when my display functions try to access a value in Form1 it cannot. There are no friend classes. Is there a way to allow my new Display class to access whether or not Form1->ToolStripMenuItems have been checked? I tried to pass Form1 to my Display class as an argument but I couldn't get that to work. What is the right approach to do this?
Thanks
Buck
|
|
|
|
|
I pass events.
I create delgates and events
Here is part of a help note I created for myself some time back
(May be just a bit over blown or out of date.)
-------------------------------------------------------------------------
Friday, September 08, 2006 5:04:17 PM
Problem: A form needs data back from its dialog prior to its close
One control needs to pass data to another control
[some cut]
II. A close dialog event -- the dialog closes and the form is told of the closeure
In the dialog
this->FormClosed += gcnew System::Windows::Forms::FormClosedEventHandler(this, &AddColorDialog::AddColorDialog_FormClosed);
private: System::Void AddColorDialog_FormClosed(System::Object^ sender, System::Windows::Forms::FormClosedEventArgs^ e)
{
AddColorDiagCloseEvent();
}
public: delegate void AddColorDiagCloseEventHandler(void);
public: event AddColorDiagCloseEventHandler^ AddColorDiagCloseEvent;
In the form
AddColorDiag->AddColorDiagCloseEvent += gcnew WSColorTabLib::AddColorDialog::AddColorDiagCloseEventHandler(this, &WSColorTabLib::WSColorTab::AddColorDiagClosed);
void AddColorDiagClosed(void)
{
// From AddColorDiagCloseEventHandler in AddColorDialog
if (AddColorDiag)
{
delete AddColorDiag;
AddColorDiag = nullptr;
}
}
WedgeSoft
|
|
|
|
|
I have a C++/CLI Win Forms app. I am forced to provide an unmanaged
Dialog. I assume I need to write a CDialog as part of my CLR solution.
I need a little hand holding. My MFC is RUSTY! Can someone tell me
how to create a CDialog (unmanaged DLL) to be called from my WinForms
Load event.
(I have been reading, searching and trying; but no cigar. Need some help.)
WedgeSoft
|
|
|
|
|
|
It is been quite a while. I have a task to identify a calling Windows' batch script's name and its location. Basically, the batch script calls/spawns my C++ executable as a parent process and I failed to identify the parent. I can identify a number of different calling processes using NtQueryInformationProcess(), but failed to do so to the batch script. The main reason is that the batch process is shown as cmd.exe not a real script name.
Thanks a lot for the help.
|
|
|
|
|
Hi Dear,
I need to make the report view of the list control non sortable( Disable Sorting) at run time. But i could not find out any API. Can Any body help me
|
|
|
|
|
Hi!
CListCtrl sounds like MFC (i.e. unmanaged), so I guess you've asked this question in the wrong forum. Try here: Visual C++ / MFC[^]
But wait... try if this answers your question:
CListCtrl yourListCtrl;
...
CHeaderCtrl* pHeader = yourListCtrl.GetHeaderCtrl();
if(pHeader)
{
pHeader->ModifyStyle(0, HDS_BUTTONS);
pHeader->ModifyStyle(HDS_BUTTONS, 0);
}
cheers,
mykel
OMM: "Let us be thankful we have an occupation to fill. Work hard, increase production, prevent accidents and be happy."
|
|
|
|
|
Hello,
I have a few warnings in c++/ cli that I don't know how to resolve:
1)
Warning 1 warning C4835: 'startupDirectory' : the initializer for exported data will not be run until managed code is first executed in the host assembly FileUtils.cpp 76
okay in this there is a unmanaged class (#pragma managed(push,off)) with a static variable
<br />
class CFileUtils{<br />
std::wstring startupDirectory(L"");<br />
}<br />
and in the c++ file
<br />
std::wstring CFileUtils::startupDirectory(L"");<br />
2)
Warning 6 warning C4965: implicit box of integer 0; use nullptr or explicit cast AlarmViewerControl.h 594
in this case I have the following code. I have tested already all casts that I know...
<br />
DataRow ^dr = dt->NewRow();<br />
<br />
dr["clmId"] = 0;<br />
Best regards and thanks for any hint!
Hansjörg
|
|
|
|
|
First issue: If native code executes before managed code, your application may have problems with loader lock: http://msdn2.microsoft.com/en-us/library/ms172219(vs.80).aspx[^]
Second Issue: If the dr["clmId"] is an object, for example a String^ , the compiler believes you are trying to set the object to NULL with zero which is not permitted.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Okay I understand the problems, but what I can do? How I can have the warnings away (not only with pragma)?
1) I need unmanaged classes and there I have static instances...
2) I understand also this, but in this case the column is a integer...What I have to do?
Best regards
Hansjörg
|
|
|
|
|
I am only seeing small snippets of your code and don't know anything about your programming requirements. So, I can only give you general advice about what I think may be wrong.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|