|
I have some code reading and writing to a USB Windows CE device (it's actually using the ActiveSync driver). On Windows XP I use CreateFile to open the port and ReadFile and WriteFile to do IO - this works fine. On Vista I can open the port but ReadFile and WriteFile always return this invalid function error (error code 1). Any ideas?
|
|
|
|
|
If it works on XP, but not on Vista, the usual response has to be "Mmmm, security?"
Having seen this page[^], though, it could be that you need to use this WIndows Mobile Device Center thing?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
You reply does not help. I need specific details not vague references.
|
|
|
|
|
|
Hi,
In the application that I am developing, I wants to store a list(using map) of structures.
Here I want the key to be an array of wide characters i.e of type TCHAR.
typedef struct
{
int nID;
int somedata;
}MyStruct;
The structure list would be of the form.
typedef std::map<tchar mystruct=""> MyStructMap;
MyStructMap objStructMap;</tchar>
I want to filling the map using a key of type TCHAR which will uniquely identify each instance of the struct that is inserted.
The place where I am inserting an structure with an unique TCHAR key is as follows.
Mystruct structobj1;
structobj1.nID = 100;
structobj2.somedata = 253;
objStructMap.insert(MyStructMap::value_type(_T("Unique1"), structobj1)).second;
The Insert operation mentioned above is failing with error
error C2665: 'std::pair<_Ty1,_Ty2>::pair' : none of the 3 overloads could convert all the argument types e:\vc05\sam\MyApp\MyApp.cpp 398
error C2228: left of '.second' must have class/struct/union e:\vc05\sam\MyApp\MyApp.cpp 398
I could you an pointer to a TCHAR as a Key for the map, but don't want to do that because I have to create an object on the heap and dont want to do that.
Is my technique of inseting an TCHAR array and struct pair in the map object briefed above correct?
Please point the cause of the error.
|
|
|
|
|
struct str
{
char cFileName[247];
};
struct cmp_str
{
bool operator()(str const a, str const b) const
{
return strcmpi(a.cFileName, b.cFileName) < 0;
}
};
typedef std::map<str,> GetFileMap;
typedef GetFileMap::value_type GetFileValType;
typedef GetFileMap::iterator GetFileItor;
|
|
|
|
|
liangyenchyen,
I am not able to get you.
All i want to achieve is add my user defined structure and associate a key which is an TCHAR array.
some thing like
objStructMap.insert(MyStructMap::value_type(_T("Unique1"), structobj1)).second;
objStructMap.insert(MyStructMap::value_type(_T("Unique2"), structobj2)).second;
objStructMap.insert(MyStructMap::value_type(_T("Unique3"), structobj3)).second;
and so on.
Later I can access a member using the key as follows
MyStructMap::iterator iter = objStructMap.find(_T("Unique1"));
How do i achieve this?
|
|
|
|
|
You are using pointers to TCHAR as the string, in effect, not arrays. Arrays are funny things in C and C++ - they're really just pointers in drag.
Anyway, you're better off using a string class, like std::basic_string<TCHAR> , because it already defines comparison operations that std::map needs, whereas a TCHAR* doesn't.
Something like this should work:
typedef std::basic_string<TCHAR> tstring;
typedef std::map<tstring, MyStruct> MyStructMap;
MyStructMap objStructMap;
objStructMap.insert(std::make_pair(_T("Unique1"), structobj1));
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
It works now.
Thanks a lot for the code snippet.
Thanks to others who have contributed to this thread.
|
|
|
|
|
First, you have to insert the < and > symbols yourself using the buttons just above the emoticons, oyherwise they will disappear.
Next, why don't you use a std::string or std::wstring to do that ? It will make your life way much easier. The map will rely on fact that the objects you provide as a key are comparable, which is not the case with C strings (what will be compared is the pointer address, not the contents). Thus this will simply not work. The other reply you got was simply to say that you can get over it by providing your own structure which overrides the == operator.
But, it is making your life complicated. If I were you, I would simply use the std::string (in non unicode build) or std::wstring (in UNICODE build) for that. If you have to support both builds, then simply define your own type:
#if defined _UNICODE || defined UNICODE
typedef std::wstring TMyString;
#else
typedef std::string TMyString;
#endif
|
|
|
|
|
To simply make it work,
std::map<const TCHAR*,MyStruct> myMap;
MyStruct obj;
myMap.insert(std::make_pair(_T("ONE"),obj));
Hey but look that's a TCHAR pointer, In general you should be careful while using pointers in containers, if scope goes out, you will get a bang. What I've suggested is not a solution, it's just to get your code compile. As Cedric has said, std strings gets along well with maps.
OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus
Best wishes to Rexx[^]
|
|
|
|
|
I was wondering if someone could help me out as a C++ newbie (also newbie in C++ in Eclipse)
I'm from a Java background, and within eclipse (running on Kubuntu) when I
set external Java projects as references to a project, I can simply do "import externalClass;" and voila, i can use that class in the current project ...
This doesn't seem to be the case for C++ ...
I've created a new project as a SharedLibrary -> Empty Project
Then created my class, say MyClass in this project, say project A.
(then built it)
Now in project B (new project -> empty project but not shared lib) I want to use the class created in A (which i have set as a project reference in B)
but #include MyClass.h throws an error. Am I missing something fundamental with how C++ shared libraries work?
Help would be much appreciated,
gvanto
the noob
|
|
|
|
|
gvanto - it helps to tell us what error occurs (I presume it's a compiler error, that it can't see MyClass.h ?)
Anyway - building against a library in C/C++ requires that you specify two things - the source-code interface (that's MyClass.h in your case) and an object-code interface (hmmmm - Linux - that'll either be a .a or some shared thing - a .so file? - my only *nix experience is with OS X - which is probably close enough!).
You also need to ensure that the directory in which these files live is specified. That means telling project B what directory contains project A's header file(s) and what directory contains project A's library file(s). The header file directory option will live with compiler options, while the library file directory option will live with linker options - I've never used Eclipse (with CDT?), so I can't be more exact than that.
Anyway - give us a bit more detail and maybe we can sort you out!
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
(I suppose you're using the g++ compiler) see [^].
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]
|
|
|
|
|
Thanks for the link. Some useful fundamental stuff in there.
But a tutorial on using shared C++ libs in eclipse, from start to end and cover things like: which header files to put where? - which project reference to select, which directory structure to use, etc would be good. (Just a simple example would be amazing)
This one here comes close: http://janmagnet.wordpress.com/2007/09/30/eclipse-cdt-and-shared-libraries/[^]
I followed that tutorial exactly and still I simply get a "make: *** [WLFeeder] Error 1, Type: C/C++ Problem " problem ...
Double-clicking it doesn't do anything, no more info, thats it.
If someone who knows how to use CDT in eclipse can make one project reference another (containing a class that needs to be used)
it would be really really awesome. I'm left stumped.
gvanto
modified on Thursday, February 12, 2009 6:55 PM
|
|
|
|
|
ok found the problem: was using shared instead of static library!
thanks guys for your help!!
gvanto
|
|
|
|
|
Hello,
I need to make a message loop that (also) ends when an event is signaled. I could probably do it myself, but I know messing with message loops is a tricky thing. If you could point me to a resource, where someone has already done this and ironed out all the potential bugs, I'll be grateful.
V.
|
|
|
|
|
There's example code here[^].
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
|
thanks for the responses, I'll try to put all the pieces together...
|
|
|
|
|
My application freezes after my while loop is in effect. The thing is everything in the while loop executes while the gui remains frozen and windows saying the application is not responding. Cpu usage is at 3% and its still executing properly, its just that the gui is frozen! I cant click my button which resets activeR to false thus ending the loop!
I first tried a simple Sleep(5000) at the end of the while loop, but that ended up with 100% cpu usage.
So i looked up on t_time and worked this out... like i said, it works... but the gui freezes. It still executes the keypress every 5 seconds though.
void roger()
{
int count = 5;
time_t seconds;
time_t curseconds;
bool seq = false;
curseconds = time (NULL) + count;
while(activeR){
if(activeR && seq){
curseconds = time (NULL) + count;
numRogers = numRogers + 1;
keybd_event(VK_PRIOR, 0xc9, 0, 0);
keybd_event(VK_PRIOR, 0xc9, KEYEVENTF_KEYUP, 0);
seq = false;
}else{
seconds = time (NULL);
if(seconds >= curseconds)
{
seq = true;
}
}
Sleep(1);
}
}
|
|
|
|
|
you need to implement this on a different thread.
your loop utilizes the main thread and thus the UI freezes.
You need to google first, if you have "It's urgent please" mentioned in your question.
_AnShUmAn_
|
|
|
|
|
As suggested above, you should call this function on a separate thread. If MFC, look up AfxBeginThread.
OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus
Best wishes to Rexx[^]
|
|
|
|
|
That was a fabulous way of doing things not only the wrong way, but to also complicate it beyond recognition.
If I haven't misunderstood it seems like what you want to do is synthesize a PgUp keystroke every fifth second.
Use CWnd::SetTimer() , or similar, to set up a timer that is fired every fifth second and call ::keybd_event() from the WM_TIMER message handler.
You do not need a secondary thread for this.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
lol it looks like you've answered his call "roger()" . I didn't actually look at the intention of the code. It looked like it's a strong while loop. So didn't opt for timers. Yep timers can do if that's his requirement.
OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus
Best wishes to Rexx[^]
|
|
|
|