|
tyagineha wrote: But i think the function of GetText() is that watever text is at index(watevr value) will be stored in _case.
You could have read MSDN about GetText(). The index is zerobased.
Hence my repeated question (which you seem to refuse to answer): What are you calling GetText() with?
Are you calling it with invalid indices (like, perchance, -1)?
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
ok i m sorry 4 that....
i m inputting a ListBox value..........
NT
|
|
|
|
|
And your Listbox does have 5 entries?
Or does it have 4, and the last one is selected?
Then you have falling in the ole off-by-one trap.
Indices are counting from 0: the last element of the Listbox has the index (SizeOfListbox -1)
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
rite now listbox has only one entry.
this function i m defining in one class and calling in another class...
the problem which u r saying..
that problem i m nt gntng when i m in same class
but when calling this function fron another class then error is cuming.
tell me watshld i do now??
Nt
|
|
|
|
|
tyagineha wrote: tell me watshld i do now??
Write proper English. I am not a native speaker and may get your abbreviations wrong. Also, this stuff is complicated enough.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
Tell me what should i do now????
NT
|
|
|
|
|
Set a breakpoint on return _case; and see if it looks OK in the debugger.
If it does, single step into your other class and look if it is still OK.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
its not ok in debugger...
its giving debug error.
i just want to return the value which is in _case.
i want to use this value furthur.
NT
|
|
|
|
|
tyagineha wrote: i just want to return the value which is in _case.
So the CString _case is ok at the end of your function (as listed above). And it is not OK in the function calling that?
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
tyagineha wrote: rite now listbox has only one entry.
But you are calling for the 4th one?
Could this work?
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
sorry i m not getting you.
Nt
|
|
|
|
|
You said:
"The index is 4"
and
"rite now listbox has only one entry."
Are you calling CListBox::GetText( 4, _case) in a CListBox that has only 1 entry?
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
hey i didnt said 4....
i said only that my listbox has only 1 entry..
NT
|
|
|
|
|
You are right. I was unable to decipher you SMS-style 1337-speak.
Here.[^]
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
Okey let me explain in detail.
void CMyProj::OnSelchangeList()
{
CClientdemoDlg dlgobj;
dlgobj.OnClientChangeListbox();
}
void CClientdemoDlg::OnClientChangeListbox()
{
CMyProj objnew;
CString _temp;
_temp=objnew.OnTextList();
}
CString CMyProj::OnTextList()
{
int index;
CString _case;
index = m_caselist.GetCurSel();
m_caselist.GetText(index,_case);
return _case;
}
notice the classes.......
NT
-- modified at 5:54 Thursday 16th August, 2007
NT
|
|
|
|
|
tyagineha wrote: void CClientdemoDlg::OnClientChangeListbox()
{
CMyProj objnew;
CString _temp;
_temp=objnew.OnText();
}
But in your example you show the code for CMyProj::OnTextList().
It seems as you think you are calling CMyProj::OnTextList(), but in your sample you call CMyProj::OnText()
Maybe you should look for the problem in CMyProj::OnText() ?
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
Ok. What and where is your Error?
Not just "Debug Assert", but complete details, please.
I get from what you have written, that _case ist still OK, but after it has been assigned to _temp it is no longer OK?
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
So you corrected your code sample without telling anyone?
I suggest you do like this:
1. Learn how to use the debugger. (It's not too hard).
2. Put a breakpoint on this line: _temp=objnew.OnTextList();
3. Single-step your code, line by line and examine what's happening.
That's it. And that's exactly what other people do, IMO.
For a good reason.
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
Short answer: You have created an object of type CClinetdemoDlg but you have not created the actual dialog. The call to both GetCurSel and GetText will fail because they required a window to operate on.
Long answer: You appear to be creating lots of temporary instances of the dialog and your CMyProj class. The act of creating the instance does NOT associate the just-created instance with the already existing one. In OnSelChangeList, you create a CClientdemoDlg. This is NOT associated with the actual dialog that I assume you created elsewhere. You then call OnClientChangeListbox in an instance not associated with a window. This causes the problem I mentioned earlier. Also, in that function, you create an instance of CMyProj. This instance is NOT the same as the one that called the function. This is important because you then call OnTextList in the just-created instance of CMyProj and in that function reference the member variable m_caselist. This variable is not the same as the one in the original class that started this calling chain. Accessing this variable will not affect the original caller.
Judy
|
|
|
|
|
What line of what file is asserting?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
tyagineha wrote: can any body tell me why i m getting error in this code?????????
You failed to indicate the error. We are not mind readers. Set a breakpoint on the GetCurSel() statement and single-step over each statement, noting the values of index and _case along the way.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hello All,
actually i have to made a project using VS2005 with CLR support so can anybody tell me how can i use ofstream class in this project.
i am also "iostraem" but still it is giving error like
"error C2061: syntax error : identifier 'fstream'"
please share your knowledge
thanks
Bankey
|
|
|
|
|
Banks K wrote: how can i use ofstream
"error C2061: syntax error : identifier 'fstream'"
a) Did you #include <fstream> ?
b) Are you writing std::fstream OR do you have using namespace std; at the top of the file?
c) You seem to want to program a managed C++ program. You should use the .NET classes and ask question in the managed C++ forum.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
Sure you can, but Microsoft is stepping so far out of previous specifications that it is becoming hard to tell where the line is.
Unless you are just using ‘ofstream’ for reading, then you have a problem that I can not solve with-out the code.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
I've written a class with only three attributes:
<br />
class UTILITIES_API CStartupManager<br />
{<br />
...<br />
protected:<br />
string m_strConfigFileName;<br />
ifstream m_oConfigFile;<br />
multimap<string, string> m_oApplicationConfig;<br />
};<br />
The main application does this (and nothing else):
<br />
void InitApplication()<br />
{<br />
CStartupManager oStartupManager;<br />
<br />
oStartupManager.StartUp("app.config");<br />
<br />
return;<br />
}<br />
<br />
int main(int argc, char* argv[])<br />
{<br />
InitApplication();<br />
return 0;<br />
}<br />
I ran it and it crashed with message "User breakpoint called from code at 0x7c901230"..
I debugged with WinDbg as Visual Studio tells me that the fiasco happens in the destructor that dooes nothing -
<br />
CStartupManager::~CStartupManager()<br />
{<br />
return;<br />
}<br />
Reading stack trace appear it's coming from attempt to free/deallocate the same chunk of memory twice:
<br />
NTDLL! 7c901230()<br />
NTDLL! 7c96cd80()<br />
NTDLL! 7c960af8()<br />
KERNEL32! 7c85e9cf()<br />
_CrtIsValidHeapPointer(const void * 0x004433a8) line 1697<br />
_free_dbg_lk(void * 0x004433a8, int 1) line 1044 + 9 bytes<br />
_free_dbg(void * 0x004433a8, int 1) line 1001 + 13 bytes<br />
free(void * 0x004433a8) line 956 + 11 bytes<br />
operator delete(void * 0x004433a8) line 7 + 9 bytes<br />
std::allocator::deallocate(void * 0x004433a8, unsigned int 33) line 64 + 38 bytes<br />
std::basic_string,std::allocator >::_Tidy(unsigned char 1) line 592<br />
std::basic_string,std::allocator >::~basic_string,std::allocator >() line 59 + 39 bytes<br />
CSomeClass::~CSomeClass() line 16 + 51 bytes
Following advice from my mentors, in hope of locating where the fault is exactly by debugging with WinDbg. Launch and attached to the target process, then run until I get:
<br />
Break instruction exception - code 80000003 (first chance)<br />
To drilldown further, "!analyze -v" seems to be telling me (the same information as Visual Studio) access violation happens in CStartupManager::~StartupManager (which does nothing)
<br />
...<br />
ERROR_CODE: (NTSTATUS) 0xc0000005 - The instruction at "0x%08lx" referenced memory at "0x%08lx". The memory could not be "%s".<br />
BUGCHECK_STR: ACCESS_VIOLATION<br />
...<br />
<br />
STACK_TEXT: <br />
0012fb20 7c968b5e 01741000 018defb0 0012fb48 ntdll!RtlpDphIsNormalHeapBlock+0x81<br />
0012fb40 7c9697ae 00000007 00001002 018defb0 ntdll!RtlpDphNormalHeapValidate+0x2d<br />
0012fb84 7c960a4e 01740000 00000000 018defb0 ntdll!RtlpDebugPageHeapValidate+0x5a<br />
0012fbe8 7c85e9cf 01740000 00000000 018defb0 ntdll!RtlValidateHeap+0x36<br />
0012fbfc 1002ed00 01740000 00000000 018defb0 kernel32!HeapValidate+0x14<br />
0012fc20 1002e051 018defd0 0012fce8 0012fe14 Utilities!_CrtIsValidHeapPointer+0x120 [dbgheap.c @ 1697]<br />
0012fc3c 1002df81 018defd0 00000001 0012fce8 Utilities!_free_dbg_lk+0xa1 [dbgheap.c @ 1044]<br />
0012fc70 1002df0e 018defd0 00000001 0012fc8c Utilities!_free_dbg+0x41 [dbgheap.c @ 1001]<br />
0012fc80 1001605c 018defd0 0012fce8 100038b6 Utilities!free+0xe [dbgheap.c @ 956]<br />
0012fc8c 100038b6 018defd0 0012fd4c 0012fe14 Utilities!operator delete+0xc [delop.cpp @ 7]<br />
0012fce8 100030d2 018defd0 00000021 0012fda8 Utilities!std::allocator<char>::deallocate+0x26 [c:\program files\microsoft visual studio\vc98\include\xmemory @ 64]<br />
0012fd4c 100029b7 00000001 0012fe00 0012fe14 Utilities!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::_Tidy+0x82 [c:\program files\microsoft visual studio\vc98\include\xstring @ 592]<br />
0012fda8 10006571 0012ff20 0012fe14 7ffd9000 Utilities!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::~basic_string<char,std::char_traits<char>,std::allocator<char> >+0x27 [c:\program files\microsoft visual studio\vc98\include\xstring @ 59]<br />
0012fe0c 00402912 0012ff80 00d2f778 7ffd9000 Utilities!CStartupManager::~CStartupManager+0x71 [C:\...path...\Utilities\StartupManager.cpp @ 15]<br />
0012ff2c 0040298d 00d2f6f2 00d2f778 7ffd9000 DesktopAPI!InitApplication+0x92 [C:\...path...\DesktopAPI.cpp @ 17]<br />
0012ff80 00404849 00000001 0185afb0 0185cf50 DesktopAPI!main+0x1d <br />
[C:\...path...\DesktopAPI.cpp @ 24]<br />
0012ffc0 7c816fd7 00d2f6f2 00d2f778 7ffd9000 DesktopAPI!mainCRTStartup+0xe9 [crt0.c @ 206]<br />
0012fff0 00000000 00404760 00000000 78746341 kernel32!BaseProcessStart+0x23<br />
"It happen in destructor" is getting nowhere. And its seems that the fault wasn't caught instantly but rather detected when memory is freed -- how can I enable "Full-page heap" from Global Flags so I get the violation as it happens?
While WinDbg indicates this happens in destructor CStartupManager::~CStartupManager ... seems like it's actually happenning before that.
Reference here:
Full-Page Heap
Full-page heap should be enabled for individual processes, or under limited parameters for large processes, because of its high memory requirements. It cannot be enabled system-wide, because it is difficult to evaluate the required page file size. Using a page file that is too small with system-wide full-page heap renders the system unbootable.
The advantage of full-page heap is that it causes a process to access violate (AV) exactly at the point of failure. This makes the failure easy to debug. In order to be able to pinpoint failures, first use normal page heap to determine the range where a process is failing, and then use full-page heap on individual large-scale processes for that restricted class of allocations (that is, a specific size range or a specific library).
Normal Page Heap
Normal page heap can be used for the testing of large-scale processes without the high memory consumption that full-page heap requires. However, normal page heap delays detection until blocks are freed, thus making failures more difficult to debug.
In general, use normal page heap for initial large-scale processes testing. Then, if problems are detected, enable full-page heap for a restricted class of allocations in those processes.
Many thanks!
|
|
|
|
|