|
Thank you very much Prasad
|
|
|
|
|
Dear all,
I am programming against an API of an application that simulates robot movements.
Whenever I send a command that makes the robot move, the application starts a new thread for that movement and sends a callback when this thread and the accompanying movement have ended. I have no access/handle to that thread, but only the callback. However, the movement only starts, when the function, in which the movement command was issued, returns to the main runloop. So I cannot wait inside the function for the callback to occur, because then the motion would never been started, I cannot wait (or ::Sleep) "outside", because the runloop would get blocked and would also prevent the motion from beeing started.
The reason for waiting is that I have to check feedback from that particular motion (e.g. whether there is a collision), before I can start a new motion.
Is there any way to work around for what seems to me like an unsolvable dilemma?
Thanks a lot for all your comments
|
|
|
|
|
Assuming that you have an event based application (a windows application with GUI), then you could simply let the callback handler post a message to your event queue. If you can provide a value (context) to the callback handler, you could have one static method in your class that does something like the following:
RobotApi::RegisterCallback(CRobotOverlord::OnRobotCallback, (DWORD)this);<br />
<br />
void CRobotOverlord::OnRobotCallback(DWORD dwContext)<br />
{<br />
ASSERT(dwContext);<br />
CRobotOverlord* my = reinterpret_cast<CRobotOverlord*>(dwContext);<br />
ASSERT(my->m_hTargetWnd);<br />
<br />
::PostMessage(my->hTargetWnd, WM_APP, 0, 0);<br />
}
In your application's message map create a handler for message WM_APP:
BEGIN_MESSAGE_MAP(CDialogMain, CDialog)<br />
...<br />
ON_MESSAGE(WM_APP, OnRobotEvent)<br />
END_MESSAGE_MAP()
Using PostMessage() and a message handler makes sure that you will process the event in the thread context of your application, so even when the callback would be in the thread context of the robot library's worker thread you would (in this example code) process it in your own thread context. Saying this I welcome our robot overlords!
Hope it helps
-- modified at 5:50 Wednesday 2nd May, 2007
|
|
|
|
|
can anyone help me to read a tiff image byte by byte and draw its histogram then equalize it and change it to a desired histogram drowed by mouse?
thnx alot
ndadashi
|
|
|
|
|
Hi,
The following is the example I have (and works):
const char *labels[] = {"Mon", "Tue", "Wed"}
SomeFunctions(labels, 3);
Now I want to initialize the contents of the array at run-time.
I tried the following but an error comes up:
const char *labels= NULL;
*labels = new char[3];
labels[0]=_T("Mon");
labels[1]=_T("Tue");
labels[2]=_T("Wed");
SomeFunctions(labels, 3);
error C2665: SomeFunctions : none of the 3 overloads can convert parameter 1 from type 'const char *'
Can someone please show me how declare the same type of array as the examples? Thanks.
|
|
|
|
|
Joe Smith IX wrote: *labels = new char[3];
This is wrong.
labels = new char *[3];
looks better.
You want to create three char *s, not an array of three chars
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
oops, you are right.
But now that I changed it as you suggested, it added a new error:
<br />
error C2440: '=' : cannot convert from 'char ** ' to 'const char *'
|
|
|
|
|
const char *labels= NULL;*labels = new char[3];labels[0]=_T("Mon");labels[1]=_T("Tue");labels[2]=_T("Wed");SomeFunctions(labels, 3);
Something like
char ** labels = new char *[3];
labels[0] = "test";
label[1] = "Not sure if this is exactly right, you may need to use new and strcpy";
label[2] = "I agree with the other poster, you should use vector if you can";
In fact, a vector is a dynamic array, so if you use char * instead of string, the index of the first char in the first item, would represent the start of a block of memory with three strings in it.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Yup, you nailed it exactly. Thanks a lot.
P.S.: Since this is not my class, I cannot change it.
|
|
|
|
|
can you please show us how is declared SomeFunction(), and what you're trying to do exactly...
just a guess: why aren't you using std::vector<> ?
-- modified at 4:39 Wednesday 2nd May, 2007
[edit]
what about overloading SomeFunction() into Somefunction(const std::vector<std::string>&) and use this code instead :
std::vector<std::string> vec;
vec.push_back("mon");
vec.push_back("tue");
vec.push_back("wed");
SomeFunction(vec);
[/edit]
|
|
|
|
|
This function is from a lib. here is the declaration in the header file
(Somefunction=StringArray)
<br />
class StringArray<br />
{<br />
public :<br />
int len;<br />
const char * const *data;<br />
StringArray() : len(0), data(0) {}<br />
StringArray(const char * const *data, int len) : len(len), data(data) {}<br />
const char *operator[](int i) const { return data[i]; }<br />
};
|
|
|
|
|
Joe Smith IX wrote: StringArray(const char * const * data, int len)
oh my god !!! does this really compile, and even if so, is this really necessary, rather that const char* ??
and is this class yours ?
why using C style stuff in a C++ code ? (i mean, char* strings when you obviously use classes, so, could use std::string ...)
|
|
|
|
|
like i wrote before, it's not my class. it's part of a lib i am using.
and i am bit confused myself (since I always use the easier path - MFC
so, is there anyway to get around this?
|
|
|
|
|
i have to parse an xml file using basic c program. i had seen in vc++ and also in c#. but how to do this in c programming. pls help me
|
|
|
|
|
Write your own parser. Use string functions like strcpy,strcmp etc.
Or find some third party libs.
If u can Dream... U can do it
|
|
|
|
|
hmm yes but i dont have any idea in that. how to parse the tag
<cardname>kumaran</cardname>
<cardtype>DISCOVER</cardtype>
<cardno>6011766587484374</cardno>
<cvv>232</cvv>
<EXPDATE>05/2015</EXPDATE>
pls help me
|
|
|
|
|
Basically C processing is identical to C++ one. Of course if you use DOM, then you have to take into account how to access COM objectd from plain C (there are good articles about, see, 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.
|
|
|
|
|
I need to open "*.tar" folder that was created on unix server then using FTP transfered to local (Windows) PC!
THX!
|
|
|
|
|
|
I need the code if any one did this. I used 'DecompresLibrary' article but didn't help. I posted question there but got no replay from author.
|
|
|
|
|
thats not really a programming question as you've phrased it, so you could be flamed for posting it here .. but since Im in a good mood ....
you could do that with WinZip, or 7-Zip (free) http://sourceforge.net/projects/sevenzip/[^]
There are freebie toold with source around that will let you do this, if you want to do it programatically
'g'
|
|
|
|
|
may be u can use winzip or winrar and pass the file as command line. You can
do it with shellexecute function or createprocess..
If u can Dream... U can do it
|
|
|
|
|
|
Then you obviously need to buy or find a tar library, I doubt you'd want to be writing one.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Your application is a windows application right ? or dos?
anyway there are apis for starting an application from your application. if it is dos there are functions like system(<command>) , in windows there are functions like winexec, createprocess,shellexecute.
So call the decompressing utitiles like winrar or winzip from ur app.
Also u can find the registread application for a file from registry (may some api are there). In that u can invoke that apps.
[IF you have winrar installed there is an exe named unrar , check it out . ]
If u can Dream... U can do it
|
|
|
|