Windows API calls in .NET application

  • Thread starter Thread starter Karlsson-on-the-roof
  • Start date Start date
K

Karlsson-on-the-roof

Dear All,
I'm new to .NET and it seems that I'm terribly confused. I'm used to
program windows applications using C++ and native API. I decided to try
..NET windows Form application. Of course, Visual Studio did everything for
me and some empty form showed up on the screen upon starting the
application.

Then I incorporated really hardcore API calls such as RegisterClass and
CreateWindow and implemented wndProc, like in old days. What happened:
another window showed up and behaved as I would expect. Now, how does it
fit together with the idea of the intermediate language and runtime and all
that stuff that is written about the .NET? I was thinking that either the
project would not compile, or it would crash upon startup, but it seems like
you can stick your API code just fine. Am I missing something here?

Tons of thanks,
Alex.
 
C++ is generally unmanaged code more or less like you're used to, but you
can use managed extensions to get the benefits of managed code, i.e. code
that is executed/managed by the CLR of the .NET Framework. Here's a brief
overview with a number of articles that might be of interest to you.
 
Karlsson-on-the-roof said:
Dear All,
I'm new to .NET and it seems that I'm terribly confused. I'm used to
program windows applications using C++ and native API. I decided to try
.NET windows Form application. Of course, Visual Studio did everything
for me and some empty form showed up on the screen upon starting the
application.

Then I incorporated really hardcore API calls such as RegisterClass and
CreateWindow and implemented wndProc, like in old days. What happened:
another window showed up and behaved as I would expect. Now, how does it
fit together with the idea of the intermediate language and runtime and
all that stuff that is written about the .NET? I was thinking that either
the project would not compile, or it would crash upon startup, but it
seems like you can stick your API code just fine. Am I missing something
here?

You are completely free to use platform APIs, that is much of hte point of
having the managed C++ language(which I assume you are using) and the entire
platform invoke subsystem.

The intermediate language and runtime offer non-API methods of doing a great
deal, including creating windows, but it does not preclude the use of the
APIs. There are limitations, of course, portability drops and there might be
security or stability issues that wouldn't be there in fully managed code,
but the runtime was designed to allow interop.
 
Thanks for replies and links to read. Well, things began to clarify a
little bit. Still a question: was my code converted to the intermediate
language or not? In the debugger I was able to see assembly code that
looked like I would expect if I had just a normal API application. I read
something about JIT compilation, and perhaps I saw the assembbly code after
JIT compilation, but still, I'm not sure.

Thanks for any help.
Alex.
 
Karlsson-on-the-Roof said:
Thanks for replies and links to read. Well, things began to clarify a
little bit. Still a question: was my code converted to the intermediate
language or not? In the debugger I was able to see assembly code that
looked like I would expect if I had just a normal API application. I read
something about JIT compilation, and perhaps I saw the assembbly code
after
JIT compilation, but still, I'm not sure.

Well, thats tough to say for sure without knowing what version of the
compiler you were using and what options were specified. Open the executable
in ildasm or reflector[1] to see.

The C++ compiler is capable of generating a mixture of languages. Part of
your code certainly was IL, and some was probably native, but its possible
it was all native, depending on options and the like.

1. http://www.aisto.com/roeder/dotnet/
 
Back
Top