|
Hi!
Thanks for the reply. I tried to login as a non-administrator and debug the application source code to see where it is crashing. The application object gets created but the control never reaches InitInstance. It crashes midway showing error in Kernel32.dll
Any ideas?
Thanks
Pradeep.
|
|
|
|
|
Hello,
I have a problem where I want to update two varibales in my View class through a dialog class CModalmodeDlg. When I press the "OK" button in the dialog I want two separate const char * members to be updated.
The first case is when I select a Cstring from a dropdown and sends it to a const char * member (m_Vectorname) in the view class. That works great,but It doesnt work for the secondview member (m_Modefreq). When a try to display m_Modefreq in the view class it gets all corrupted. But it gets it right when I display it in a messagebox through the dialog.
example.
m_Modefreq in messagebox= "45.23 Hz"
m_Modefreq in ViewClass = "^''*´"
Another observation is that when I in the dialogs OnBnClickedOk() set the second variable (m_Modefreq) to always be the same static value it displays it correct in the view.
below is a code snibbet,
[code]
void CModalmodeDlg::OnBnClickedOk()
{
//get the active view
CFrameWnd* wnd = (CFrameWnd*) AfxGetMainWnd();
if(wnd) m_pView = (CVtkSDIView*) wnd->GetActiveView();
//get the selected string from the dropdown.
CString str;
m_DropDown.GetLBText( idx,str);
const TCHAR *ptr;
ptr = str;
//update the first view member const char *m_Vectorname
//works fine
m_pView->m_Vectorname=(LPCTSTR)str;
int idx = m_DropDown2.GetCurSel();
m_pView->m_Modeindex=idx;
//the method ReturnMode returns a string depending on which index is selected
//from the DropDown.
Currentstring =m_pView->ReturnMode(idx);
//Here I want the other const char * member (m_Modefreq) to be updated.
//it prints out the right in a messagebox but as soon as I try to display it in the view //class it gets all corrupted.
m_pView->m_Modefreq=Currentstring.c_str();
[/code]
When I set it to a static value
[code]
like this:
m_pView->m_Modefreq="45.2 Hz" it manage to update it right.
[/code]
I dont really know what to do about this, please letme know if you have any ideas!
Regards Peter
|
|
|
|
|
m_pView->m_Modefreq=Currentstring.c_str();
This is the error. Currentstring is dialog local std::string. You are just doing a shallow copy of its internal pointer. When the dialog ends, the strings destructor destroys its contents.
You need a deep copy.
If you use a std::string or a CString in your view class, it will be ok. Otherwise you'll have to do the memory management yourself with new, strcpy and delete, which also works.
|
|
|
|
|
The problem most likely lies here:
m_pView->m_Modefreq=Currentstring.c_str(); You are storing a pointer to the internal contents of Currentstring into m_pView->m_Modefreq , but this internal contents can change (or be deleted) as soon as Currentstring is modified or destroyed. In your snippet it is not clear whether Currentstring is a local variable or not: if the former, then the char buffer pointed to by m_Modefreq will be destroyed as soon as CModalmodeDlg::OnBnClickedOk exists.
As a general rule of thumb, never store the pointer returned by std::string::c_string . To solve your particular problem, change the type of m_Modefreq to a std::string .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
Hi,
Thanks for your quick replys, to bad that I didn't notice until now
I will try both of the tips that has been suggested. Niklas you suggested that I should do a deepcopy, I suppose you mean create a new, strcpy, and then pass it, then delete it.
I realized that the buffer that the m_Modefreq points to will be destroyed but how come the other passing of data works.If you remember from my first thread I converted an CString str and passed it to a const char * m_Vectorname. Shouldn't that pointer also be corrupted as the other one since it points to a buffer that is being destroyed when it exists the metohd?
//get the selected string from the dropdown.
CString str;
m_DropDown.GetLBText( idx,str);
const TCHAR *ptr;
ptr = str;
//update the first view member const char *m_Vectorname
//works fine
m_pView->m_Vectorname=(LPCTSTR)str;
|
|
|
|
|
Shouldn't that pointer also be corrupted as the other one since it points to a buffer that is being destroyed when it exists the metohd?
Yep... seems to me you're just being lucky here; the memory pointed to by m_pView->m_Vectorname is free memory, and sooner or later it'll get corrupted. I suggest you also change m_pView->m_Vectorname to be std::string .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
Hi
Friends,
I have come across a problem where i want a presice Timer Intrupt using Windows timer.
i want a resolution of 1 Ms . I am facing a problem that i dont get tick at each time elapse.
Sometimes the response is good ,and sometimes worse.
can any body just pass a few words of comment.
Manish Saha
Whirlpool of India Ltd.
Senior Engineer,EDC
saha_manish@rediffmail.com
|
|
|
|
|
Hi Manish, I recommend you take a look at Nemanja Trifunovic's excellent Timers tutorial[^].
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
Have Gone through the Timer Tutotorial . That was excelent . Great.
Lot of Thanks to Nemanja Trifunovic . And Cheers to CODE PROJECT !!!
I have gone through the Documnet ,and decided to go for Queue Timers.
Since Win 2000 is ok for me .
What do u think about reply from toxcct?
if the windows Latency of 55 Ms (as toxcct Says) then
is it possible that widows will attend to any of the timer messages?
Lets see .. i will try Out. And let u all Know.
|
|
|
|
|
you cannot be 1ms precise just because Windows scheduler is already up to about 55ms. and windows is not a real-time OS, so, timer interrupts don't have priority uppon the kernel.
TOXCCT >>> GEII power [VisualCalc]
|
|
|
|
|
Hello !
I open a serial port using the CreateFile function. I would like to know the number of bytes that are in the in queue of this port. Of course, witout removing them from the queue...
Any idea of how I can do that ?
Thanks
|
|
|
|
|
You can use the ClearCommError function (even though the name does not suggest it.)
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
Yes, the name of the function was not really what I was expecting.
Thank you
|
|
|
|
|
I have a CEdit control on a dialog box and I'm creating a dynamic rectangle on the CEdit but it doesn't scroll vertically when I put the rectangle on the bottom of the CEdit?!! I've set the multiline+ vertical scroll parameters
Please help me! my code has come below:
CRect rc, statusRect;
GetDlgItem(IDC_GRAPH_EDIT)->GetWindowRect(rc);
CWnd* pWnd = GetDlgItem(IDC_GRAPH_EDIT);
ScreenToClient(rc);
statusRect.top = rc.bottom - 40;
statusRect.bottom = statusRect.top + 20;
statusRect.left = rc.Width()/2 - 40;
statusRect.right = statusRect.left + 80;
m_dynamic = new CButton;
m_dynamic->Create("Dynamic",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_OWNERDRAW|BS_MULTILINE,statusRect,pWnd,2000);
m_dynamic->SetFont(fontGeorgia);
m_dynamic->SetColor(BLUE, LBLUE);
m_dynamic->ShowWindow(SW_SHOW);
I've tried the following codes but it didn't help:
((CEdit *)(GetDlgItem(IDC_GRAPH_EDIT)))->SetSel(GetWindowTextLength(),-1);
or
((CEdit *)(GetDlgItem(IDC_GRAPH_EDIT)))->PostMessage(WM_VSCROLL, SB_BOTTOM);
UpdateData(TRUE);
or
((CEdit *)(GetDlgItem(IDC_GRAPH_EDIT)))->LineScroll(2);
Any idea or suggestion will be appreciated.
thanks
|
|
|
|
|
CEdit represents a simple text editor, even if you subclassed the control I dought you could do it. The edit-control client area does not actualy scroll, that's an illusion. When you scroll the text it just changes the position of the upper left courner character, where drawing is to start. The edit-control would have to think that your custom-control is part of the text.
If you need to insert an object into an edit type control then you should be using CRichEditCtrl, and even then it may need to be an OLE control.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Well.....actually I'm going to draw a graph (some colored rectangles that are connected by some colored arrows) on a dialog. Since the display sould be always like a single vertical line of boxes with a scrolling feature, I though CEdit might be a good choice.
Now.. I'm waiting for your suggestion for such an implementation
Thanks a lot
|
|
|
|
|
If you have not already visited controls section of CP, then give it a shot. There are two graph controls at CP that I know of (one is it ATL/COM section). The other two choice would be to: look into how to use a view (CScrollView) in a dialog box or write your own code to handle the scrolling.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
;PThrough registry, will I able to know the information from a mounted drive. (ie LBA, PID, VID, drive letter).
|
|
|
|
|
Hi
Read the keys at
HKEY_LOCAL_MACHINE\System\MountedDevices
Regards
The Best Relligion is Science.
Once you understand it, you will know God.
|
|
|
|
|
I encountered a problem today. I have a dialog containing a rich edit control which I use to highlight certain parts of a text. The control is set to readonly in the dialog editor. I also use SetOptions() to set it as readonly in OnInitDialog. This works pretty much ok.
When I select a text snippet, I am able to drag the text and drop it into any other window accepting text. But when I do, the selected text is deleted from the read-only rich edit control.
Any ideas?
|
|
|
|
|
Hi,
I want to display a simple dialog that displays "Please Wait..." while a task is performed then goes away by itself when the task is complete.
What's the simplest way to do this?
Thanks,
Ali
|
|
|
|
|
when the task ends, just send a WM_CLOSE to the window displaying the "please wait..."
TOXCCT >>> GEII power [VisualCalc]
|
|
|
|
|
In VC++ 6, there's an add-in to insert a progress dialog box. (not sure about vc++7) Once inserted, you could strip out the progress controls/code, and use the default static control for your "Please wait..." message.
Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
|
|
|
|
|
Hi
You can use CStatic Class to show "please wait..." message.
if u wanted to know when task ended u can use Threads API functions or MFC threads functions as AfxBeginThread(threadfun,hwnd,threadpriority) ,
then create thread and Use WaitForSingleObject(....) API function to determine when your task ended
.
if u need more help contact me on faroq_tam2004@yahoo.com.
If this dos'nt help u im sorry.
Bye.
On Earth nothing impossible,
while your mind running.
Faroqtam
|
|
|
|
|
hi CPians, toxcct again.
another wish i had for my prog was to have the possibility to switch all the text between French & English.
I so used the default string table (french) to insert the french strings, and created an US english for the translated strings. all the strings refering to the same thing in both tables had the same IDs (#define names).
Questions :
1. Am i right to set the same IDs (#define names) in the string in both tables, or do they only need to have the same value (int) ?
2. how can i switch from one language to the other and vice versa ?
3. Is there a better/simplest way to do this far away from what i am doing now ?
TOXCCT >>> GEII power [VisualCalc]
|
|
|
|