|
Couple of observations here
what's the problem? what error code are you getting? what sort of help do you require?
It's extremely unlikely anyone's going to copy your code, compile it and come back with the answer - sorry
A general suggestion, don't use Dispatch interfaces, they are the most unwieldy method of calling com objects, use the 'real' interface
Another one, if you have access to ATL, use CComPtr's to help wrap the pointers, and use OLE DB Client Templates to talk with Access
|
|
|
|
|
thank you answer my question
I think use C to Implement the Dispatch interface.But I find it's not.
|
|
|
|
|
I need to be able to stop COM port from sending the Morse code using space character from keyboard.
I use a button change event to execute the code sending function, however, I am unable to detect the keyboard since the sending function is still executing.
I tried to “insert” PostMessage custom WM_USER message but Windows still waits until the sending function is finished before recognizing the keyboard.
I am using PreTranslateMessage in MFC view.
Would adding another thread work?
I do not have much experience in multithreading, but willing to do it if it solves the problem.
Any other constructive suggestions will be appreciated.
Cheers
Vaclav
|
|
|
|
|
That may work... what you have going on is a classic case of a C/C++ blocking call keeping you from doing what you need... in which case the threading should help. I would however, move the COM interactions to their own thread and stop when needed instead of leaving the blocking call in the main thread.
|
|
|
|
|
OK,I'll will do multithreading. May as well learn it now and I will need to stop other types of transmission in future anyway.
Just a thought - would it be possible to "chop" the Morse code into event function for each element instead of sending the whole string of Morse characters in one event function? Probably too messy and it would still not be stoppable in the middle of dash character anyway.
|
|
|
|
|
You could... don't know about how messy it would get though... depends on the total number of states you need to represent and your actual implementation.
|
|
|
|
|
I got the new thread running with one problem.
Just for test I tried to intercept the keyboard via PreTranslateMessage ( in the new thread) and it did not work.
As suggested , eventually the COM stop will go into another thread, hopefully I can figure out how to communicate between threads.
For now I need to “redirect” the keyboard messages into the new thread.
They are still going ( being intercepted ) to the main thread.
I do not know how to accomplish that in MFC.
|
|
|
|
|
Why are you trying to intercept keyboard messages in the new thread? Why not do that in the main thread and then task the additional thread to do the actual message sending over COM port?
|
|
|
|
|
Because I still cannot get the main thread to intercept the keyboard while the sending function is executing even in the new thread.
I must be doing it wrong - here is the code snippet
// implementing multiuthreading
TRACE("\n Start the C_MorseCode_Thread thread");
m_C_MorseCode_Thread = (C_MorseCode_Thread*) AfxBeginThread(RUNTIME_CLASS(C_MorseCode_Thread));
m_C_MorseCode_Thread->m_C_Morse_Class->C_ConvertText("Test Test Test Test ",m_CFD2008Doc);
Do I need to start the execution in the new thread itself?
|
|
|
|
|
You're doing that wayyyyy wrong. Read an article on AfxBeginThread() first and try again. You're still making a direct call into the method, even if it is on a different thread.
|
|
|
|
|
I am making progress, however, have some minor questions.
1.How does the parameter gets into worker thread control function ?
2.Why does this function need to be defined as static?
3.Per article I am using , the worker thread can be “easily stopped”, however, since the thread sets the COM port (DTR) how do I know it will disable the DTR not just quit the thread? ( I am guessing I need to make sure it will and stopping the thread is no guarantee.)
4.If I use user-interface thread I need to create Cwnd ( Morse code class) It fails but “getLastError” reports “function completed successfully”.
I am using MFC document / view to set / control COM port (DTR) ( outputting Morse code string) and have to be able to stop it ( reset DTR via keyboard ) from the main thread.
I think I will need to use user-interface thread to get better control.
One more – if I want the user interface thread to intercept keyboard messages I am planning to intercept them in the main thread (Cview) via PreTranslateMessage and than PostThreadMessage to thread of interest. Is that the only way to accomplish this?
Thanks for reading,
Any constructive help will be as always appreciated.
Cheers Vaclav
|
|
|
|
|
Hi all
In my aplication menu had a ribbon edit with spin button, I'm using this:
pEdit->EnableSpinButtons(1, 1000);
But when I increment with up arrow over 999 the value is changed to 1,000
I used GetEditText to change this value but what I have is 1
I can't change increment or ignore ',' or remove ',' from value, that is a bug with ribbon.
In old MFC application I have Spinbuttonctrl in create method I have used UDS_NOTHOUSANDS but in ribbon I don't have this option.
If somebody can help me.
Thank you
|
|
|
|
|
Not sure I understand what your problem is... When you do a GetEditText on your control you only get 1 when it should be a 1000? or you don't expect to be able to reach 1000? Can you clarify?
|
|
|
|
|
Seems the comma in 1,000 is his problem (ie GetEditText reads "1,000" then parseInt() or whatever stops at the comma). If there's no suitable style/attribute on the control he's using, then I guess it requires a bit of string-munching.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
The problem is comma, when I use GetEditText() returns '1' and not '1,000', I want 1000 because I'm editing a object and when reach 1000 returns to value 1, that's wrong. I don't have parseInt() method I'm using mfc c++.
thank you
|
|
|
|
|
This seems like such an obvious bug... why would GetEditText() parse out the text (CString never ends on a ',' so I don't see how this bug could occur)? where are you checking your return? Maybe post your actual code and point out where you see the 1.
|
|
|
|
|
Hi
Here is my code:
CMFCRibbonEdit *pEdit = DYNAMIC_DOWNCAST(CMFCRibbonEdit, MyApp->GetRibbonElement(ID_RIBBON_FORMAT_WIDTH));
if(pEdit == NULL)
return;
CDrawObj *pObj = (CDrawObj*)m_selection.GetHead();
if(pObj == NULL){
ASSERT(0);
return;
}
if(_ttoi(pEdit->GetEditText()) < 1) <==== Here GetEditText() return 1 and not 1,000 I tested with MFCOffice2007Sample and they have the same problem
return;
this->InvalObj(pObj);
int nDelta = _ttoi(pEdit->GetEditText()) - pObj->m_position.Width();
if(nDelta < GetDocument()->m_size.cx){
CRect newPosition = pObj->m_position;
newPosition.right += nDelta;
pObj->MoveTo(newPosition);
}
|
|
|
|
|
See... you're problem is probably with the conversion of the CString to an integer... place pEdit->GetEditText() on its own line and look at the text returned. If its 1000, with or without a coma, its correct and the problem is with the function doing the conversion to integer. You can always take your returned CString and remove the ',' character before even attempting the conversion.
CString ret = pEdit->GetEditText();
ret.Remove(',');
|
|
|
|
|
Thank you
Now is working but when I click in Up Arrow the increment shows 1,000, 1,001, 1,002 and when I change focus shows the correct value.
Thanks for all
|
|
|
|
|
that's a different issue, post as new question pls...
|
|
|
|
|
The problem is resolved:
I used:
CString str = pEdit->GetEditText();
str.Remove(`,`);
pEdit->SetEditText(str);
Thank you
|
|
|
|
|
Cool... cheers!
|
|
|
|
|
Thanks. All fixed while I was sleeping... You've spelled out exactly what I was referring to a few message above.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
Hello everyone,
I have a problem... I want to send/post a message to a CDocument object from a CDialog object. I know I have use WM_COMMAND message but the thing is that the CDialog object does not have any access to information of CDocument since it is created from another thread. What should I put in the parameter HWND? Is there a handle for CDocuments?
Any suggestions?
Thanx in advance!
Odysseas Zografos
|
|
|
|
|
Odysseas Z wrote: I want to send/post a message to a CDocument object...
It's not a window, so why?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|