|
Have you considered SetWindowsHookEx() with WH_KEYBOARD ?
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
|
Use SetWindowsHookEx with WM_KEYBOARD_LL
if bit LLKHF_INJECTED in KBDLLHOOKSTRUCT.flags is set,then this key press is injected by SendInput function.
if the key press is simulated by posting WM_KEYDOWN directly,the hook procedure wont be called at all
|
|
|
|
|
Ths code does just what you asked for.
Ok, the timing is not well..... just press the keys down rapidly to get a good time measure.
#include <windows.h>
#include <iostream>
#include <time.h>
#include <cmath>
using namespace std;
int main(int argc, char *argv[])
{
HANDLE hInput = GetStdHandle(STD_INPUT_HANDLE);
INPUT_RECORD ir;
DWORD dwRead = 0;
bool bLoop = true;
clock_t timer_start, timer_stop;
int Number_of_Keypresses=0;
ZeroMemory(&ir,sizeof(INPUT_RECORD));
timer_start = clock ();
timer_stop = clock ();
while(bLoop)
{
if( ReadConsoleInput( hInput,&ir,1,&dwRead) )
{
if(ir.EventType == KEY_EVENT )
{
if(ir.Event.KeyEvent.bKeyDown )
{
timer_start = clock ();
Number_of_Keypresses++;
switch(ir.Event.KeyEvent.wVirtualKeyCode)
{
case VK_DOWN:
cout << "DOWN" << endl;
break;
case VK_UP:
cout << "UP" << endl;
break;
case VK_RIGHT:
cout << "RIGHT" << endl;
break;
case VK_LEFT:
cout << "LEFT" << endl;
break;
case VK_ESCAPE:
bLoop = false;
default:
break;
}
}
else
{
timer_stop = clock ();timer_start = clock ();
}
cout <<"Number_of_Keypresses = "<< Number_of_Keypresses<<"\n";
cout <<"Millisecond delay = "<<abs(timer_start - timer_stop ) <<" (from KEY_EVENT_keydown to KEY_EVENT_KeyUp)" << endl;
cout <<"______________________________________________________\n";
}
}
}
return 0;
}
|
|
|
|
|
In Visual Studio 2010 C++ the function GetSchemaObject() returns -1 and not the schema number set wit the IMPLEMENT_SERIAL macro. The prototype of the function returns UINT and in pratice -1 is returned ? How can I solve this problem ?
|
|
|
|
|
I Think you GetSchemaObject() get failed. You better look at the documentation how to retrieve the error information may be it will give you a way out.
|
|
|
|
|
Hello Friends
I am writing a XMl file using MSXML.
Some of nodes are having child.When I am rewriting the same node then first I am deleting the node And All its child one by one like this :
void fnDeleteChildNode(MSXML::IXMLDOMNodePtr pMainNode)
{
MSXML::IXMLDOMNodePtr pChild,pDeletedNodePtr;
MSXML::IXMLDOMNodeListPtr pChildList = pMainNode->GetchildNodes();
int noOfChild = pChildList->Getlength();
if(noOfChild > 0)
{
for(pChild = pMainNode->firstChild; pChild != NULL; pChild = pDeletedNodePtr)
{
pDeletedNodePtr = pChild->nextSibling;
pMainNode->removeChild(pMainNode->firstChild);
}
}
}
But I dont want to delete its child one by one.I want to know is there any fn tht will directly delete all of its child ?
Thanks In Advance.
Regards
Yogesh
|
|
|
|
|
I guess that replaceChild of current node's parent should be enough.
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
yogeshs wrote: I am rewriting the same node then first I am deleting the node
Not sure what you think "rewriting" means but other than that.
If you have a node X, and you want to delete it, then you do the following
1. Get the parent of X
2. Delete X from the parent.
In the above it does not matter whether X has children or not. When you delete X then its children, if any, will be deleted too.
There is no delete all, but if you are recreating X then it is pointless to worry about the children because when you replace X, if you actually replace it (not modify the existing one) then all of the children of X would be gone.
|
|
|
|
|
Hi all,
I have made a linked list using CList class. Inside parameters of CList i have passed structure which has value of CString and int aray type.
If i want to find a item in that list using find function, how can i do it?
struct Person
{
int ID;
CString Name;
int age;
int phno[20];
};
CList<Person *, Person *> person_struct;
void function_add()
{
Person *obj_Per;
obj_Per->ID = 0;
obj_Per->Name = "Bilbo Baggins";
obj_Per->age = "35";
for(int i = 0; i<20; i++)
{
obj_Per->phno[i] = i;
}
person_struct.AddTail(obj_Per);
obj_Per->ID = 1;
obj_Per->Name = "Fredo Frog";
obj_Per->age = "40";
for(int i = 0; i<20; i++)
{
obj_Per->phno[i] = i;
}
person_struct.AddTail(obj_Per);
}
If i want to find item with particular ID then how can i do this??
Thanks in advance
|
|
|
|
|
See the Remarks section here[^].
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
VCProgrammer wrote: obj_Per->age = "35";
Isn't the age member an int ?
VCProgrammer wrote: If i want to find item with particular ID then how can i do this??
At this point, I'd be more concerned with adding an item properly. obj_Per has not been initialized (for each item).
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Well spotted, I failed to notice that.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
you can use GetAt function Gets the element at a given position.
please look for the MSDN CList member function
|
|
|
|
|
I am developing using the MRPT ReactiveNavigationDemo app. I have put the core of the demo inside a dll, and use the dll to call the mrpt library. I then call the dll from the main application. Everything works fine except for one function. The read_vector function from the CConfigFileBase causes a heap error on the deletion of the std::vector tokens within the function. I have been unable to locate the source of the function. I tried to move the tokens to be a class variable instead and when I do, it says that the tokenize function does have valid parameters even though all I chaged was the std::vector tokens from a local variable to a class one. I also tried make the vector a deque instead and still receive the same error. I have undone the changes and still get the same error. I have tried to look on the web for help and no success there. The tokenize portion is properly storing the variables in the vector passed to it, it is just the deletion of any local variables that is causing the problem. My main library is /MTd and the mrpt base is /MDd. Not sure if that makes a difference or not. Any ideas as to what may be causing the error? Is this a problem with the function itself? Or am I missing something somewhere? I have already asked some time ago on the forums for the library with no response. I am hoping someone here will be able to provide me with the insight I am lacking. Thanks. I have included my code below:
template <class VECTOR_TYPE>
void read_vector(
const std::string & section,
const std::string & name,
const VECTOR_TYPE & defaultValue,
VECTOR_TYPE & outValues,
bool failIfNotFound = false) const
{
std::string aux ( readString(section, name, "",failIfNotFound ) );
std::vector<std::string> tokens;
mrpt::system::tokenize( aux,"[], \t",tokens);
if (tokens.size()==0)
{
outValues = defaultValue;
}
else
{
const size_t N = tokens.size();
outValues.resize( N );
for (size_t i=0;i<N;i++)
{
std::stringstream ss(tokens[i]);
ss >> outValues[i];
}
}
}
ReloadRobotShape(vector<float> &xs, vector<float>& ys, string &robotNameUsedInConfigFile)
{
try
{
string robotName = m_configRobotIni->read_string("ROBOT_NAME","Name",robotNameUsedInConfigFile);
vector<float> tempXS, tempYS;
vector<float> type(0);
string xsName = "RobotModel_shape2D_xs";
string ysName = "RobotModel_shape2D_ys";
if (m_iniReactive->sectionExists(robotName))
{
m_iniReactive->read_vector(robotName,xsName,type, tempXS, true );
m_iniReactive->read_vector(robotName,ysName,type, tempYS, true );
xs = tempXS;
ys = tempYS;
}
}
catch( std::exception & e)
{
cout << e.what() << endl;
cerr << e.what() << endl;
}
}
LoadConfigFiles(string &reactiveIni, string &robotIni, bool isMemoryStringInsteadOfFile)
{
if (isMemoryStringInsteadOfFile)
{
m_iniReactive = new CConfigFileMemory( reactiveIni );
m_configRobotIni = new CConfigFileMemory( robotIni );
}
else
{
m_iniReactive = new CConfigFile( reactiveIni );
m_configRobotIni = new CConfigFile( robotIni );
}
m_reacNavObj->loadConfigFile(
*m_iniReactive,
*m_configRobotIni );
}
reloadRobotShape()
{
try
{
vector<float> xs,ys;
string robotName = "SENA";
m_lamps->LoadConfigFiles(EDIT_internalCfgReactive,EDIT_internalCfgRobot,true);
m_lamps->ReloadRobotShape(xs,ys,robotName);
lyVehicle->setPoints(xs,ys,true);
}
catch( std::exception & e)
{
cout << e.what() << endl;
cerr << e.what() << endl;
}
}
Nothing is impossible, It's merely a matter of finding an answer to the question of HOW? ... And answering that question is usually the most difficult part of the job!!!
|
|
|
|
|
Fred Ackers wrote: My main library is /MTd and the mrpt base is /MDd. Not sure if that makes a difference or not. Any ideas as to what may be causing the error?
there's one candidate!
and, in general, you have to be very careful about passing STL objects across DLL boundaries.
http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q172396[^]
|
|
|
|
|
I posted a reply to another in the thread with more information. It is sounding to me like I have a lot of work to get this library to compile with mine though due to the differences in linking with the core c++ libraries. Would you say that is an accurate statement?
Nothing is impossible, It's merely a matter of finding an answer to the question of HOW? ... And answering that question is usually the most difficult part of the job!!!
|
|
|
|
|
Fred Ackers wrote: Would you say that is an accurate statement?
unfortunately, yes.
in general, exporting C++ objects across DLL boundaries is dangerous because you run the risk of creating an object with one version of the C++/CRT and deleting it with another.
|
|
|
|
|
I set all my libraries finally to use attempt to use the same version of the linking. Although I did have to set the compiler option of /FORCE:MULTIPLE. And that fixed the problem with the heap error. True, I discover other errors. But my initial problem is now fixed. Thanks.
Nothing is impossible, It's merely a matter of finding an answer to the question of HOW? ... And answering that question is usually the most difficult part of the job!!!
|
|
|
|
|
"a heap error on the deletion of the std::vector tokens"
I cant see any deletion of anything called tokens but in anycase, you dont want to delete a stack variable. It gets cleaned up when the func exits. You only delete stuff you have allocated with new.
==============================
Nothing to say.
|
|
|
|
|
Run app verifier on it. It looks s if the heap vector is getting corrupted somehow.
==============================
Nothing to say.
|
|
|
|
|
I was able to solve the problem by setting all of the libraries to use multi-threaded dll instead of some multi-threaded and others multi-threaded dll. I had to use the /FORCE:MULTIPLE option but it works now without a heap error. Question though: Where do I find this app verifier you mentioned?
Nothing is impossible, It's merely a matter of finding an answer to the question of HOW? ... And answering that question is usually the most difficult part of the job!!!
|
|
|
|
|
Application Verifier is a Microsoft download. You can get it of MSDN
==============================
Nothing to say.
|
|
|
|
|
In Win32, when you pass an object through DLL boundaries you cannot allocate memory in one module (DLL) and delete it in another module (your main program, another DLL), unless you use the Global Heap for allocation/deallocation. Another approach is to create a deallocator function in the same module and pass it to another module to delete the object.
In Win64, there will be no problem: you can allocate objects in one module and delete them in another.
|
|
|
|
|
hi all,
i have hexadecimal values in the form of CString in my list control.
i want to sort them and my list according to those sorted values.
How can i do this??
|
|
|
|