Solved

Are system calls more reliable from MFC than .NET?

Posted on 2007-12-05
5
352 Views
Last Modified: 2013-11-20
Are there any known problems with making system calls (such as Desktop calls, WIndowing calls, or ShellExecute or CreateProcess) in .NET? Is it better to write such an application in MFC?
0
Comment
Question by:jobrems
5 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20412020
As far you specify marshalling properly, it will have the same reliability as MFC. Indeed you don't call from MFC (unless you are using a MFC wrapper class), you call natively the WinAPI applications.
Of course there is a little cost to invoke WinAPI function from .net, since .net makes additional checkings.
0
 
LVL 19

Expert Comment

by:alb66
ID: 20412673
Sometimes is more easy to make system calls from native code (MFC) because you can use "ready to use" include files. As jaime_olivares said you have also  little better performance.
0
 
LVL 7

Accepted Solution

by:
multithreading earned 250 total points
ID: 20413991
There are a million ways to get into trouble making calls into the various DLLs from C#, but if you know enough to program in C++, and if you know the CLR well, then you are unlikely to run into them. Given that you can probably avoid the various problem areas in maping functions, the choice of language comes down to what you are gaining and what you are losing, with regard to these system calls, by using .Net.

The more complicated the call, the more likely you are to have problems. If you call a method that takes no arguments and returns nothing, then there isn't much room for trouble. On the other hand, if you call a method that takes a struct, which contains pointers to other structs, and returns a handle, you have several complications. In addition to needing to build a object hierarchy in .net with pointers, you have gotten back a handle (like you would expect to see with some of the calls you mentioned) which (depending on the level of support for that particular RAW handle) may not be directly useable in .Net. Getting back handles etc. can force you to make more system calls, and the next thing you know, you are writing a C++ application, except that you keep having to look up #defines for all kinds of int values etc., and figuring out how you are going to represent things in C#. All of that is before we get into any object lifetime issues...

Look at the overall application. How many different calls are you going to need? What are the arguments and return values? If the calls can be made using regular c# types, and you aren't getting pulled into the vortex, then c# is your answer. If you find that looking up and defining the calls and argument types is taking you more time than you are saving by using c#, then use C++ instead.
0
 

Author Closing Comment

by:jobrems
ID: 31412863
Thanks for your detailed answer. I also wanted to know: Are there some system calls which, when made from unmanaged code in .NET, execute incorrectly or with unexpected results?
0
 
LVL 7

Expert Comment

by:multithreading
ID: 20427644
It's kind of complicated. Most calls work fine. Calls that involve callbacks can get you into trouble. I've also seen people frequently get into trouble with calls that take pointers to character buffers. There are other ways to get into trouble, but the more you know the less likely that is to happen. I think the best advice would be only programmers with a solid understanding of the CLR, C/C++, and the Win32 API should be making these mappings. There is a little bit more to it than meets the eye, especially with calls that take pointers to various objects. In the hands of someone with a thorough understanding of the various issues, you will be fine.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
fix34  challenge 9 96
scoreUp challenge 14 48
Can not remove SSL certificate on iPhone 6 - iOS10.2 12 84
CKEditor - will not function 7 32
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now