I've been a C# dev for several years...better part of a decade I guess. I'm a systems administrator by trade so rather than building web apps, I mainly use C# to do things that are out of the reach of vbscript. At least that's how it started. Now I have started spending more time with C++ because of an interest in systems level programming.
Before anyone gets all indignant on me I know that Win32 was developed in C and not C++. I really don't want to argue about the pedigree of API's or languages.
I guess what I'm wondering is how one gets over the hurdle of dealing with strings in native code and actually gets to a productive place like we are at with C# (or the rest of .Net). I'm really interested in C++ and native programming for the capabilities that it brings...so I guess what I would like is to be able to work with the native platform in a productive way.
Libraries like poco and boost seem to have some features that simplify something's like filesystem access...but I'm not really interested in portability.
For instance, Boost has a great recursive directory iterator. (Creatively named recursive_directory_iterator.) But once you have a file path if you want to know anything about it...the ACL applied, if the folder is encrypted via NTFS, or if it's junction/soft link/whatever you have to call Win32. Then starts the "you can't cast a blah to a blah to a pointer of a blahblah".
Right now I keep butting my head against marshaling different types of strings in and out of Win32. Is there any chance that some of the C++ softies could give us some direction for how to navigate this? I don't really care about UNICODE or ANSI...I realize why there are functions that end with A and W. I'm not going to ship software in China anytime soon. I would need to actually turn out something useful first.
I need to cut down on the friction here. Can anyone help?
You should be able to find a lot of information on the internet regarding marshaling strings between managed and native code. PInvoke.net is another good place to look for general P/Invoke information.
But I hear you. I also have to do some C/C++ string manipulation after many years of being spoiled by C# and was surprised to realize how difficult (non-obvious/convoluted/verbose) it was to do simple string manipulation.
Actually in Win32 there is only CHAR* and WCHAR* (ok and BYTE*)- almost everything else is either one of those or some way of saying how to do reference-counting or memory freeing of one of those.
You can convert between the two via MultibyteToWideChar or WideCharToMultibyte respectively.
If you're moving strings between C# and C++, then the "Marshal" class is your friend
Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.