I don't have a problem w/ writing (only) to the .NET api, the problem is that
there is a lot of functionality that just isn't there.
For example, how do you do MessageBeep in .NET? You can't.
When and if MS gets around to creating a complete framework, the P/Invoke will
largely be unneeded for Win32 functionality. Unfortunately, by that time,
there will be enough 3rd party or other related libs that provide the missing
functionality that existing code managability will be seriously compromised.
Microsoft should have completed the framework *before* releasing it. Big
mistake, but MS support for the developer has been on a downhill slope since
shortly after Win 95 was released.
"Sam Gentile [MVP - C#/.NET]" wrote:[color=blue]
>
> You're right that it's not easy but there is a good reason for that IMHO.
> With .NET, Microsoft is actively discouraging people from writing unmanaged
> code and instead using managed APIs for obvious reasons. While there are
> some valid reasons for going to the Win32 API, they are in fact few in
> comparison to going out from VB 6 for instance (multimedia is an obvious
> exception). I would guess this was not done so that people stay mostly with
> writing "pure" managed code and program one way to the .NET Framework SDK.
> This results in many benefits. Of course, I have no insight into their
> decision but this would be my take.
>
> --
> --------------------------------------------------------------
> Sam Gentile [C#/.NET MVP]
> .NET Blog
http://samgentile.com/blog/
> MSDN Column:
>
http://msdn.microsoft.com/library/de...tml/bridge.asp
> Please reply only to the newsgroup so that others can benefit.
> This posting is provided "AS IS" with no warranties, and confers no rights.
> ---------------------------------------------------------------
> "Julie J." <unlisted@.> wrote in message news:403BAAF3.1CAC1BE4@....[color=green]
> > It would have been nice (and not asking too much) if MS had created an
> > additional namespace that contained all the Win32 APIs.
> >
> > The current way makes porting a real pita.
> >
> > "Jeff Schwartz [MSFT]" wrote:[color=darkred]
> > >
> > > Here is an example of how you can create PInvoke signatures for these
> > > native methods. I found which DLL had the exported function by[/color][/color]
> searching[color=green][color=darkred]
> > > MSDN.
> > >
> > > Hope this example helps.
> > >
> > > using System;
> > > using System.Runtime.InteropServices;
> > >
> > > internal class NativeMethods {
> > > [DllImport("kernel32.dll", CharSet=CharSet.Auto,[/color][/color]
> SetLastError=true)][color=green][color=darkred]
> > > internal static extern IntPtr OpenProcess(int dwDesirdedAccess,[/color][/color]
> bool[color=green][color=darkred]
> > > bInheritHandle, int dwProcessId);
> > >
> > > [DllImport("psapi.dll", CharSet=CharSet.Auto,[/color][/color]
> SetLastError=true)][color=green][color=darkred]
> > > internal static extern bool EnumProcesses(int[] lpidProcess, int[/color][/color]
> cb, out[color=green][color=darkred]
> > > int cbNeeded);
> > > }
> > >
> > > public class PClass {
> > > public static int Main() {
> > > int[] pids;
> > > int bytesNeeded;
> > >
> > > pids = new int[1024];
> > >
> > > if (NativeMethods.EnumProcesses(pids, 1024, out[/color][/color]
> bytesNeeded)) {[color=green][color=darkred]
> > > // returned true;
> > > for(int i=0; i<(bytesNeeded/4); i++) {
> > > Console.WriteLine("PID{0}: {1}",i,[/color][/color]
> pids[i]);[color=green][color=darkred]
> > > }
> > > } else {
> > > // got error
> > > Console.WriteLine("NativeMethods.EnumProcesses()[/color][/color]
> failed");[color=green][color=darkred]
> > > }
> > >
> > > return 100;
> > > }
> > > }[/color][/color][/color]