I notice the event loop in the template still doesn't deal with the return from GetMessage being TRUE, FALSE or -1. For details on this little treasure of the Win32 API see the middle-bottom of the following page (under return value): GetMessage function | Microsoft Docs[^] Regarding MFC, I always found it a bit of a cludge in places and fairly incomplete. I often had to resort to Win32 calls to get stuff done. I recently had to do some additions to an old MFC project and started to think this wasn't all that bad...until I realised that a list control needs each line measuring to determine whether to show a horizontal scrollbar! Mercifully, you get a vertical one automatically. When the .NET framework/Forms/WPF came along this sort of thing just went away. The API was much more complete, along with the revelation that you can still use something that looks like C++ (C++/CLI, NOT managed C++ which needed taking out the back and shooting) to program it - it seemed like a whole new world! I still use C++/CLI rather than p/invoke as I find it much cleaner where I need to get down to low level stuff or interface with pure C++ libraries.
ian__lindsay 0
Posts
-
Windows C++: a bit shocked -
Typical issues in managed c++Hi, 1) I tend to use the msclr::interop::marshal_as templates for string conversions rather than pinning memory as they work in a nice tidy C++ RAII way, clearing up any temporary/locked memory when going out of scope. They handle stl, COM and straight const char * type conversions. See http://msdn.microsoft.com/en-us/library/bb384859.aspx[^] 2) Yes. Works just the same, except with C++/CLI syntax. You will need to do some translation (e.g. to copy into an stl data type) to send to purely native code though. 3) The general rule is if you are creating a managed object, use gcnew, otherwise use straight c++ new. The garbage collector will do the rest. You can still delete sooner if you want to. Hope that helps.
-
Book for Managed Extenstion for Vc++You can do a lot worse than Nish's book, C++/CLI in action (see http://www.manning.com/sivakumar/[^] ). I found it a really good introduction to one of the better things to come out of Microsoft in recent years, C++/CLI. Highly recommended.
modified on Tuesday, July 5, 2011 4:33 AM
-
static_cast vs cli::safe_castAs far as I know, safe_cast is more like dynamic_cast (which you can also use on managed types). safe_cast and dynamic_cast are for casting between handles to polymorphic types within a class hierarchy (much as you would do in C++ with pointers). The difference is that safe_cast throws an exception when the cast is not possible rather than returning nullptr. This means you don't have to write code that checks to see whether the cast succeded, just handle the exception, meaning potentially less cluttered code.
-
VS 2008, or VS2010If you have anything at all to do with C++/CLI, avoid VS 2010 - even 'plain' C++ with the /clr switch on for some interop in the project turns the source editor into little more than notepad with syntax highlighting. VS 2008 was much better for our use case - lots of existing (and still valuable) C++ with a .net front end. Unfortunately, we have had to migrate to 2010 as we needed some functionality in .net 4, but source browsing, intellisense and F1 help are just painful. See: https://connect.microsoft.com/VisualStudio/feedback/details/501921/c-cli-intellisense[^]
-
What's your favorite browser extension?The only one I use regularly is ie tab for Firefox for those sites that *still* only work in ie!
-
Conversion between array<String^>^ and const char *const* and back?If you are using .Net 3.5 or newer, you can use the marshalling library: http://msdn.microsoft.com/en-us/library/bb384865.aspx[^] For your example, the marshal_context methods are probably most appropriate, then you can leave RAII to clear up the HGlobal stuff internally. You will still need to loop over the array elements though.
-
Damn you C language and all it's compilers!I would say that it is because in C, no parameter type ends up being interpreted as just an int passed in (same as if you don't specify a return type). Add in the comma operator which if memory serves correctly does something like execute each expression and return the value of the last one, and you have compiling code. So what ends up happening is something like void die(int a) { } die(3);
-
VS2010 beta2 and C++Microsoft have a connect bug registered for this (ID#501921), maybe if enough people express an interest, they might get the implementation of this into the first service pack. - you never know :)
-
Message for MS (Re: VS2010)Just so that Microsoft realise how much of a pain this is, please register your interest on Microsoft connect bug id 501921.
-
Visual Studio 2010 is coming out soon. Does anyone care?Am quite excited too, things I am looking forward to playing with: - C++0x features, auto and lambdas particularly - never did like functors - Direct2D and DirectWrite look cool (not sure if they are particularly are a .net 4 feature though) - Improvements for intellisense in C++ (but see below) and the IDE in general - Task parallel library - Proper multi monitor support Things I am not looking forward to: - No intellisense in C++/CLI - might even mean I wait for SP1 before seriously adopting VS2010 as we make heavy use of C++/CLI (thanks for the book by the way Nish - extremely helpful in teaching an old C++ dog some new .net tricks!) - WPF for the IDE - sure it will look pretty, but will it run as fast - from our experience of WPF, I'm not so sure, but they may have made improvements while using it in anger themselves.
-
Programming's Foul LanguageShowing my age here: - anything in setjmp.h - ie setjmp, longjmp, etc basically a goto on steroids! - VARIANT_BOOL .... why oh why is VARIANT_TRUE -1 not 1 which is what TRUE is defined as, source of much pain in the past - oh and anything COM related actually! - MFC (need I say more...)
-
Source Control with Branching and VS support?We have used VSS for about 10 years - we had some horrible thing called PVCS before that. It has its quirks and it works better if the source database is regularly pruned, but for us - a dev team of 5 - it does the job. It got a whole lot easier when Visual Studio brought in the 'change source control' functionality (about 2003/2005, can't remember exactly). It was manual editing of the project file after a branch before that! I guess we really ought to investigate the alternatives, but we are fairly happy with what we have, and there are other priorities...