|
Need the wrapper class for CMap using the STL map(Because i have some problems using CMap i want the same functionality of CMap but internally i have to use map)
Hi this Ravinder
|
|
|
|
|
So you need the interface of CMap and the implementation of std::map..? If so, then you need to declare your own CMyMap with an std::map member variable declared in it, and try to implement CMap similar functions in your CMyMap. However, you cannot simulate hash code related functions of CMap via a std::map..
Did I understand your problem correctly?
--
Arman
|
|
|
|
|
Hi All,
How to get the available ports for serial port communcation.
Thanks & Regards,
Anitha
|
|
|
|
|
You can use CP article Search engine..
See here[^]. I hope it helps.
Regards,
Sandip.
|
|
|
|
|
Check out the Win32_SerialPortConfiguration and Win32_SerialPort WMI classes.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Hi all,
I am just curious to know if there is a way to find the HWND of a window, given no actual window title and no definitive process name. Although I could get a handle by using the process name, I'd rather not since users might rename the executable file to something else.
I am attempting to prevent two instances of one app from being run at once, so I stuck a mutex in. I want my app to send a message to the already running program and close. However, my app needs the HWND of the other running app to send a message to it with SendMessage. The problem is, my app does not have an actual "window", meaning that I can't get it's HWND with FindWindow. It's derived from CFrameWnd and doesn't show up in taskmgr (FindWindow).
Any suggestions on how to accomplish this? Thanks in advance
|
|
|
|
|
How about saving the HWND into a registry location?
«_Superman_»
|
|
|
|
|
That'd actually be a good idea.
I'll try that. But is there any more...elegant..way to do this?
|
|
|
|
|
What about using events..??
Regards,
Sandip.
|
|
|
|
|
Rather than a mutex (which I'm presuming has a unique name), you could have a uniquely named bit of shared memory, in which the first process to run could store things like the HWND to post a message to?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I'm probably going with this idea. Thanks a lot.
|
|
|
|
|
Hi,
I was wondering what is the order of API calls to replace a peice of text in a Rich Edit Control Dialog
I do the following
WM_SETSEXT to send the Text the Rich Edit Dialog BOX
The EM_SETSEL 0,7 setting the selection for char 0 - 7
Then doing the SetCharFormat to set the Character fromat to red
memset( &cf, 0, sizeof cf );
cf.cbSize = sizeof cf;
cf.dwMask = CFM_COLOR;
cf.crTextColor = RGB(255,0,0);
SendMessage(RichWindow,EM_SETCHARFORMAT,SCF_SELECTION,(LPARAM) &cf);
Then the replacement text
strncpy(addr,"00000000",8);
SendMessage(RichWindow,EM_REPLACESEL,TRUE,(LPARAM) addr);
However more then 8 charcters are replaced seeems like 9 or 10
|
|
|
|
|
I was wondering what people reckon a good way of logging in C++ would be?
Coming from a java background, I very much like log4j's system:
- it handles file output (and sizing) automatically
- very configurable
- easy to install and use in eclipse
Now, I've come across two loggers for C++ which seem
to be the C++ version of log4j: log4cxx (by apache) and log4cpp (by someone else: http://log4cpp.sourceforge.net/[^] )
OK, so first attempt at getting log4cxx working in Eclipse (running on kubuntu) was not fruitful:
The apache website, nor anywwhere else has much info on getting log4cxx up and running in eclipse.
(after installing log4cxx via "sudo aptitude install liblog4cxx9c2a" and including the header files in my c++ project in eclipse, it says it cant find the header files... i've searched and cant find them either !)
I would so love to use log4cxx since it was built by Apache and probably works really well but I really dont want to waste hours
again trying to get it to work in Eclipse (or anywwhere else for that matter). Same with log4cpp
IF anyone knows of a good logging library / class which handles (log)file creation automatically and is
easily used within eclipse, it would be much appreciated !!!!
gvanto
c++ logging newbie
|
|
|
|
|
gvanto wrote: I was wondering what people reckon a good way of logging in C++ would be?
How about Windows Event Log?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Sorry guess I didn't mention: this is on a Linx (Kubuntu) machine ...
cheers,
gvanto
|
|
|
|
|
Hi,
I have an structure declared in the .h file.
typedef struct
{
int nID;
TCHAR szName[MAX_PATH];
}MyStruct1;
typedef std::map<std:basic_string xmlns:std="#unknown"><tchar>, MyStruct1> MyStructList;</tchar></std:basic_string>
Another struct which contains the MyStructList list as it's member.
typedef struct
{
int age;
TCHAR Place[MAX_PATH];
MyStructList ObjList;
}MyMainStruct;
In the .cpp file.
void MyApp::main()
{
MyMainStruct objMainStruct;
UpdateList( objMainStruct.ObjList);
}
void MyApp::UpdateList(MyStructList &ObjList)
{
MyStruct1 MyStructObj;
_tcscpy(MyStructObj.szName, _T("ABCDE"));
MyStructObj.nID = 2532;
ObjList.Insert(MyStructList::value_type(_T("First"), MyStructObj)).second;
}
I am not able to update the MyStructList list structure in the function below.
When I perform an insert on the list or for that matter any operation on the list, my application (VC2005 on vista) crashes.
Is it because the way I have declared an List object inside another structure that this is not working?
Plesae help me there.
|
|
|
|
|
I am surprised that even compiles.
It should be :
void MyApp::UpdateList( MyStructList &objList )
{
MyStruct1 myStructObj;
_tcscpy( myStructObj.szName, _T("ABCDE") );
myStructObj.nID = 2532;
objList.Insert( MyStructList::value_type( _T("First"), myStructObj ) ).second;
}
|
|
|
|
|
I believe, when I create an instance of MyMainStruct object, the memory is not getting allocated to the MyStructList member. Is my understanding right?
If so how do i get about it?
I dont want to create any object on the heap and store it's pointer in the structure.
|
|
|
|
|
The only flaw I could see is having an implicit cast from CONST TCHAR* into TCHAR*. However, even in this case the code may work. Are you sure the reason of your crash is inside the map::insert?
My quick suggestion is trying the code by declaring the map's key as CONST TCHAR* instead.
--
Arman
|
|
|
|
|
Arman Z. Sahakyan wrote: The only flaw I could see
Well, see my other post.
How is the map comparing the keys ? Using a ==operator.
Now, what happens if you compare two TCHAR* strings using a == operator ? The addresses are compared, not the contents. Thus you will end up with crazy results if you don't use a comparison function like strcmp. The map doesn't know that it has to use such function to compare the keys, thus it will compare simply the pointers and you end up with unexpected results.
|
|
|
|
|
std::map uses operator ==?? I think no. It uses std::less predicate which uses operator < by default. And for string pointers it's common to use them as keys because identical strings are stored in the same location and different strings (I mean const char* ) in different.
But surely, I'd chose std::string as a more modern (and event more) alternative to those const char pointers!
--
Arman
|
|
|
|
|
Arman Z. Sahakyan wrote: std::map uses operator ==?? I think no.
Honnestly, I don't exactly what it uses internally, but it uses an arithmetic operator anyway (operator < for instance). And this is not really nice working with pointers
Arman Z. Sahakyan wrote: And for string pointers it's common to use them as keys because identical strings are stored in the same location
No, not necessarily. Otherwise you wouldn't need a strcmp function .
I guess it's okay if you are using static strings but once you start maniuplating those strings and copying to another TCHAR pointer, then everything is screwed. And you certainly want to use something else than just the same TCHAR pointer for your key.
|
|
|
|
|
Please, first fix the typos. For instance, you are missing a < character on the map declaration so we can't see the type you are using as a key. If you are using a TCHAR*, then review what we discussed yesterday, because it won't work. Use a std::string or std::wstring instead (because of the comparison operator that won't work for a TCHAR*).
Second, if you have a crash, it is very helpfull if you provide the exact location of the crash in your code (using the call stack from the debugger) and any other assert message that you get.
Third, the way you use the insert (and not Insert function) is a bit akward: why are you accessing the return value (you write a .second at the end) ? The insert function returns an iterator (the place where your data was inserted), why do you access this iterator ? It doesn't make any sense and makes the code difficult to understand.
Furthermore, you I find easier to use the [] operator directly:
ObjList[_T("First")] = MyStrucObj;
Anyway, as said yesterday, your problem certainly comes from the fact that you are using TCHAR* as key for the map. Please, consider seriously using a string wrapper class instead, or you will make your life a hell for nothing.
|
|
|
|
|
If you are not yet convinced about using a std::string as a key, here[^] is a discussion about a guy having issues because he is using a char* as key for the map. I'm almost sure that your problem is because of that (maybe not the crash but at least your program won't work at all the way you would expect it).
Just because it compiles doesn't mean that your code is correct. Just because it compiles with a TCHAR* as key doesn't mean that it is valid.
|
|
|
|
|
I am not sure if you guys understand the issue that I am facing.
typedef struct
{
int nID;
TCHAR szName[MAX_PATH];
}MyStruct1;
typedef std::map, MyStruct1> MyStructList;
Another struct which contains the MyStructList list as it's member.
typedef struct
{
int age;
TCHAR Place[MAX_PATH];
MyStructList ObjList;
}MyMainStruct;
//This code gives a crash.
void MyApp::UpdateList(MyStructList &ObjList)
{
ObjList.clear();
MyStruct1 MyStructObj;
_tcscpy(MyStructObj.szName, _T("ABCDE"));
MyStructObj.nID = 2532;
ObjList.Insert(MyStructList::value_type(_T("First"), MyStructObj)).second;
}
//But the given function adds all the structure object with their key without any crash.
void MyApp::UpdateList2()
{
MyStructList localObjList
MyStruct1 MyStructObj;
_tcscpy(MyStructObj.szName, _T("ABCDE"));
MyStructObj.nID = 2532;
localObjList.Insert(MyStructList::value_type(_T("First"), MyStructObj)).second;
}
Which means that there is nothing wrong with the insert operation that is performed on the localObjList list object which is a local copy.
when I create an instance of MyMainStruct object, will the MyStructList member of MyMainStruct also be instantiated.
void main()
{
MyMainStruct MainObj;
UpdateList(MainObj.objMyStructList);//This call crashes.
}
modified on Friday, February 13, 2009 3:22 AM
|
|
|
|