No I hadn't tried anything in the manifest. I've had a quick scan of the link you set and (initially)took the quick option of pasting in the example #pragma just as it's given for a version version= '22.214.171.124' to set the version from a .h file. No obvious difference yet as its still loading a v5 and a v6.
Of relevancet, I have a WTL/ATL version that I can step through side by side with the Win32 version and the WTL/ATL only loads one ComCtl32.dll, the v6.
Adding manifest as recommended prevents v5 ComCtl32.dll loading, just the v6 but as soon as I open the my dialog with my ListView control on it's gone. Just flickers on the screen and disappears. Calling
The dialog with listbox using one ComCtl32 6 and not loading a v5 at well that flicked out of existence didn't bode too well for debug success so I started from scratch putting in a manifest line at the beginning and it displays. Only one ComCtl32 6.0.9200.16579 is loaded so that looks like success (apart from having to cut'n past stuff stuff).
I am wondering what might be the advantage of CStringArray over CArray<CString, LPCTSTR>. The background is that I am planning to implement a CStringArray-like template class which is either explicitly ANSI or explicitly Unicode, and would like to implement it as CArray<CStringA, LPCSTR> and CArray<CStringW, LPCWSTR>, respectively.
I have never mastered the usage of MFC container classes but I have an advice: support only unicode unless you are forced to support ansi. WinNT uses unicode/UTF16 inside, the codepaging/ansi api is just heritage from older windows versions. Supporting both is just a waste of time and unecessary complication if you don't have to support Win9x.
EDIT: Regarding the difference between CStringArray and CArray<CString...> I have a tip: The old versions of MFC didn't contain any templated containers, those mfc versions had only some non-template containers for a few types and CStringArray was one of them (among the others like CByteArray). I guess CStringArray exists just because of backward compatibility. CString didn't have reference counting in some older versions of MFC so in theory it is possible for a specialized CStringArray to reallocate the array memory without copying strings if CStringArray knows the internal implementation of CString, but a templated CArray has to work with copying/deleting. With reference counting a general CArray can do a relatively good job and with today's move ctors it can be even better if MFC supports it.
There are situations when I must support ANSI, for example when it comes to dealing with ANSI text files or serial protocols. I want to have the CStringArray functionality available for the must-be-ANSI situations while generally compiling for Unicode. Btw, I find MFC containers quite useful (unless, of course, you are using STL). The documentation is quite good, and you can debug-step through the source code.
Do you receive single bytes/ascii or really ansi on the serial port? Many people confuse ansi with ascii or latin1. Similarly, many windows coders confuse utf16 with unicode (they are two different things) and wchar_t with a unicode character. Can you clearly separate these concepts because if not I can write you a very little mini tutorial about these here. I want to convince you that compiling your program only for unicode is probably enough. Btw, what is on the other end of the serial port and what kind of codepage do you use in the "ansi" text for communication, is the text bare ascii (characters below chr(128))?
Containers: No matter what containers you use, its easy to debug either implementation. One of the project I'm currently working on contains own container implementations (array, hashmap, ...) and even these containers are debuggable if you can adjust the autoexp.dat file of your visual studio accordingly to teach the debugger how to get out items from the container. When I choose containers I consider 2 aspects: portability to different platforms and whether I need hardcore performance optimization later in the project or not. If we consider portability then stl is a much better choice than mfc containers, thats why I never really used mfc containers. Writing your own containers isn't practical in 99% of the projects.
Well in fact I should use proper terminology. When I said "ANSI" I meant 8-bit character stuff. When I said "Unicode" I meant 16-bit characters. Speaking of Unicode code points, mostly in the range 0000 through 007f. In other words, ASCII characters in different representations. But this discussion is getting beside the point. My question was, what is the advantage of CStringArray over CArray<CString, LPCTSTR>? Rephrase: Why is there a CStringArray class when CArray<CString, LPCTSTR> has the same functionality? Or does it not?
Here is a nice page that can help you in choosing between the two options: http://msdn.microsoft.com/en-us/library/y1z022s1%28v=vs.71%29.aspx[^]. In my previous post I mentioned that in the early days of MFC there were no template usage in the mfc library so they created several array implementation for some basic types like WORD, CString, Int,... Later they introduced templated classes like CArray<> but they kept the earlier container classes as well for backward compatibility so as to keep old legacy code compilable. Today you can use either of them but probably the CArray<cstring> is preferred in new code.
I would compile only a single unicode-aware version from my program and I would convert my strings to ascii only before sending them over serial connection and converting them back after receiving the string from serial but of course this is your choice. If you used utf-8 to represent strings then the conversion would be unnecessary - with utf8 you should convert between utf8 and utf16 only when you call winapi that has string parameters and/or return values. I like using utf-8 internally because its compatible with ascii, unicode aware, and its very easy to port to unix like systems at the same time.
Thanks for that link... actually it doesn't tell me why I should use one or the other. There table in that page lists two differences between CArray and CStringArray: 1. The former uses templates while the latter doesn't - well, that is obvious. 2. CArray isn't type safe while CStringArray is - but I fail to see why. A CArray<CString, LPCTSTR> can only contain CString objects, so what should be type unsafe? So actually, my question remains open
Regarding your advice, I have to deal with tons of old code. Many parts of that code work well with Unicode, but I know some places that confuse bytes with characters, and I sure don't know all of them, and I just don't have the time to clean everything up. I will have to live with a mix of 16 and 8 bit character strings. Besides, it is a pity that there is no built-in or MFC UTF-8 string type in C++. I love Perl for that.
I'm pretty sure that CStringArray and CArray<CString> provide the same functionality. If later you find out then its still an easy search and replace. I wouldn't worry about this choice. I myself prefer templates as in some cases templated containers are easier to handle (from other templates) than specific types like CStringArray.
I got a question about the Win API with C++,
Some problems in the use of the
OpenComm(mbPortName, INQSIZE, OUTQSIZE);
The "COM1" to "COM32" is OK! But The "COM32" or higher always return error.
The function can't return ID to me.
How can I modify my parameter to solve this problems.
I can open COM32 or Higher in hyperterminal.
It is an exclusive device, and the device is "MOXA" device.
The one is support COM1 to COM256 that is use a configuration UI to setting it.
I can change any port to different COM port. and request and response data is ok in hyperterminal.
Next thing to consider is permissions. In CreateFile you have to specify the permission level you want. Use MAXIMUM_ALLOWED, that way the open will always succeed and give you whatever permissions it can. If yuo ask for FULL_CONTROL, and you dont have ownership of the object, then it will fail to open.