DOTNET C # Programmer's Guide To The Win32 API (Win32 API Declaration C # Edition)
Small god 2001.09.07
Oh, I am sorry that I use this title. In fact, if I can do 10%, I am very happy. Because my table is putting a Dan Appleman's book, it has been accompanied by me many years, maybe you also have a: 1215 pages, blue books, machinery industry publishing house. English name is: "Dan Appleman's Visual Basic 5.0 Programmer's Guide to the Win32 API". In addition to borrowing this similar name, I just made a finishing work, but this is a small workload (Haha) I put kernel32.dll, user32.dll, gdi32.dll, advapi32.dll, shell32. DLL, SPOOLSS.DLL, Winmm.dll's functions and declarations have been sorted, and the syntax of C # re-rewritten, and organize a C # version. In this way for DOTNET's Platform Invocation Services (Pinvoke), you can use these Win32 API functions directly. At present, MS has not announced the entire Win32API how much can be used in DOTNET, how much is it. Some functions have no corresponding implementation in the DOTNET, so you may also need to use the Win32 API function. Structure and enumeration statement, kernel32.dll, user32.dll, gdi32.dll is placed in three CS files; the remaining advapi32.dll, shell32.dll, spoolss.dll, Winmm.dll four DLL The function is placed in a CS file, the entire Namespace is called Win32APi. The rough architecture should be like this: Namespace Win32API {
Using system;
Using system.Runtime.InteropServices;
First, all structures and enumeration statements
Class kernel32 {....
Class user32 {....
Class GDI32 {....
Class Advapi32 {....
Class shell32 {....
Class spoolss {....
Class Winmm {....
}
Corresponding to the following C # file: strunts.net.cs kernel32.net.cs user32.net.cs gdi32.net.cs OtherFNC.NET.CS
Then compile them, so you can use them, I don't calculate all the accurate numbers included in 5 files, but there should be hundreds of structures and enumerations, and thousands of functions declaration. After completing these, I can use this most commonly used messagebox now: use system;
Using Win32API;
Public Class TestWin32API
{
Public static void
Main
()
{
Irge;
Iret = user32.MessageBox (0, "Hello C # Win32 API", "My Pinvoke", 0);
}
}
Just when I test this example, I had an interesting thing, because I didn't add NET's identity, I had a NET identity, and I'm using kernel32.cs, user32.cs, etc., MessageBox is User32.dll , And the default generated User32.cs is also called user32.dll, and finally happened when I execute this test program, I always thought that my statement had a problem, then I used the example in Frameworksdk or wrong until it was When I was running normally in other directories, I found out that my own DLL name and the system's DLL name is exactly the same. Then it is changed to the above, but it is very strange CSC / T: EXE /R:User32.dll testwin32api.cs compile instructions actually have no error tips, it is really disgusting. Remind you not to be like me. The nightmare may still be behind, I still don't know how many mistakes in the real CS statement, and then debug it when I use it anyway. Because too much, it is impossible to test, and I don't dare to test one by one. I only hope that I have the role of the brick introduction. If you have a new version, don't forget to give me a copy of Mail. In the included zip package, all CS source code is compiled under Framework SDK Beta2. Windows 2000 Adv Server SP2 EN Visual C # Compiler Version 7.00.9254 Cl R Version V1.0.2914 You can compile according to your situation (you must compile structs.cs, because others must /r:Structs.Net.dll) Or use a binary DLL. DOTNET's compilation technology is very good, 5 DLL adds up to more than 100 K.
Here's the source code for the source code:
// Write by ccboy // Date: 2001.09.07 // CSC / T: library /r :system.dll structs.net.cs // CSC / T: library /R: Structs.Net.dll kernel32.net.cs // EMEDITOR 3.14
Namespace Win32API {
Using system;
Using system.Runtime.InteropServices;
[Structlayout (layoutkind.sequential)]
PUBLIC CLASS ABC {
Public int abca;
Public Int ABCB;
Public int abcc;
}
[Structlayout (layoutkind.sequential)]
Public class abcfloat {
Public float abcfa;
Public float abcfb;
Public Float ABCFC;
}
Public class kernel32 {
[DLLIMPORT ("kernel32.dll")]]]]
Public Static Extern Int GlobalHandle (INT PMEM);
[DLLIMPORT ("kernel32.dll")]]]]
Public Static Extern Int Globalock (int HMEM);
[DLLIMPORT ("kernel32.dll")]]]]
Public Static Extern Void GlobalMemoryStatus (MemoryStatus lpbuffer);
[DLLIMPORT ("kernel32.dll")]]]]
Public Static Extern Int GlobalRealloc (int HMEM, INT DWBYTES, INT UFLAGS);
[DLLIMPORT ("kernel32.dll")] Public Static Extern Int GlobalSize (int HMEM);
[DLLIMPORT ("kernel32.dll")]]]]
Public Static Extern Bool GlobalUnwire (int HMEM);
}
PUBLIC CLASS USER32 {
[DLLIMPORT ("User32.dll")]]]]]
Public Static Extern Bool MessageBeep (int utYPE);
[DLLIMPORT ("User32.dll")]]]]]
Public Static Extern Int MessageBoxEx (int hWnd, string lptext, string lpcaption, int utype, short wlanguage);
[DLLIMPORT ("User32.dll")]]]]]
Public Static Extern Int MessageBoxIndirect (msgboxparams anonymous0);
[DLLIMPORT ("User32")]]
Public Static Extern Int MessageBox (int hwnd, string lptext, string lpcaption, int utYPE);
}
Pubic Class Winmm {
[DLLIMPORT ("Winmm.dll")]]]]]
Public Static Extern Int SendDrivergeMessage (int HDriver, int message, int lpaam1, int lparam2);
[DLLIMPORT ("Winmm.dll")]]]]]
Public Static Extern Int AuxgetDevcaps (int UDeviceID, Auxcaps PAC, INT CBAC);
[DLLIMPORT ("Winmm.dll")]]]]]
Public static extern Int auxgetnumdevs ();
[DLLIMPORT ("Winmm.dll")]]]]]
Public Static Extern Int AuxGetVolume (int UDeviceID, int [] pdwvolume);
[DLLIMPORT ("Winmm.dll")]]]]]
Public Static Extern Int AuxOutMessage (int UDeviceID, int UMSG, INT DW1, INT DW2);
[DLLIMPORT ("Winmm.dll")]]]]]
Public Static Extern Int AuxsetVolume (int dwvolume);
}
...... .., ..,.. ..,. .., .. .., .., .. too much hahaha ..
}