12,763,337 members (25,729 online)
Forgot your password?
Sign in with
Chapters and Sections
Article Help Forum
Submit an article or tip
Post your Blog
Ask a Question
View Unanswered Questions
View All Questions...
All Message Boards...
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Design and Architecture
C / C++ / MFC
ATL / WTL / STL
Objective-C and Swift
Hardware & Devices
Hosting and Servers
Silverlight / WPF
Site Bugs / Suggestions
Spam and Abuse Watch
The Insider Newsletter
The Daily Build Newsletter
Most Valuable Professionals
The Insider News
The Weird & The Wonderful
General Indian Topics
General Chinese Topics
What is 'CodeProject'?
Ask a Question
Bugs and Suggestions
Article Help Forum
Advertise with us
About our Advertising
Comments by Nemanja Trifunovic (Top 19 by date)
That's fine - just be aware that it solves a slightly different problem: converting UTF-16 to/from current system code page, which can really be anything. Internaly it uses Windows conversion API.
Why does this question have MemoryBarrier tag?
As I repeated several times: this is from ASCII to Unicode. ASCII characters are *always* < 127. Encoding detection is way beyond the scope of this little tip.
The sample could be improved. std::string is guaranteed to store memory in a single block (well, at least in C++ 2011, but all current STL implementations do that anyway) so you can just reserve the string buffer with an appropriate size (which BTW needs to be done via a separate call to WideCharToMultiByte - your sample will work only for ASCII characters) and pass it directly instead of dealing with a temporary array.
Reason for my vote of 5
Nice. However, be aware that your approach is not exactly equivalent to the original. CP_UTF8 means the resulting string will be UTF-8 encoded. CW2A macro converts the string to the system encoding on the user's machine.
Well, you said: "but when you are dealing with unicode data this doesn't work fine...". My point is that it works as described - it converts an ASCII string to a UTF-16 Unicode one (on Windows). The tip is not about best practices for developing "world-ready" software.
Mital, please check the title of the tip: "ASCII strings to Unicode". Of course it does not work if anything other than ASCII is stored in the source string; the point is that if you know you have only ASCII there is no way to call conversion functions - all you need to do is "widen" existing characters to.
The question is tagged with C, C++. Your example is in neither of these languages.
Yep, very good :)
@Gernot: The title of my tip is clear: from ASCII to Unicode. ASCII is a 7 bit encoding and there can't be any characters > 127. If you have some other encoding of course you need to use something like MultiByteToWideChar or iconv.
IMHO, it is an incomplete answer. OP wants to know how to pass a multidimensional array to a function. Passing just a pointer without the size(s) is not enough.
It is not about style here. Because array decays into pointers when passed as function arguments, there is no way to determine the size of the array from within a function. Therefore, either the size needs to be passed as a separate parameter, or array needs to be terminated by some well-known value that the function will recognize.
It is not a good idea to hardcode the array size within the function. It is better to pass it as another parameter instead.
In my sample, it is the derived classs that is instantiated and it does not have any virtual functions.
You can distribute the dll's even without the redistributable package - the difference is, depending on the version of VC++ (or even Windows?) you need to supply a manifest file together with the dlls.
Microsoft replaced the Intellisense C++ compiler completely and the new one was not ready for C++/CLI in time for VS2010.
It would be interesting to add that early in C++ days there was no delete version, and plain delete was supposed to be used to clean up both after new and new. Of course, one should not assume that it would be OK to do such a thing nowdays.
This is a correct answer. References are in practice implemented as pointers, but that is just an implementation detail. A reference is really an alias.
As I stated in my answer
Web01 | 2.8.170217.1 | Last Updated 1 Jan 1900
All Rights Reserved.
Terms of Service