Windows Programming/C and Win32 API

C and Windows
Many of the low-level functions in Windows were created using the C programming language. C code tends to be relatively small and fast compared to VB code or even C++ code, and has a shorter development time compared to raw assembly code. All of the DLLs in the Win32 API, and most of the kernel-level structures are implemented in C code.

Visual Basic and Windows
Visual Basic is essentially a "Windows-only" programming language - although some ports either exist or are in development for other systems, VB is not nearly as popular on other operating systems as it is on Windows. The VB runtime libraries tap into the Win32 API and the MFC libraries, to implement its functionality. The new version of VB, "VB.NET", uses the .NET platform, and therefore will not be covered in this wikibook. Old versions of VB, or "VB Classic" utilize the same Win32 API and MFC interfaces that C and C++ use to communicate with Windows. However, not all of the functions are identical, because VB uses different data types, and stores data differently than C or C++. As we discuss the Win32 API and MFC, we will attempt to show how the same functionality is implemented in VB.

Visual Basic uses the STDCALL calling convention for implementing function calls. Most of the Win32 API uses the STDCALL calling convention as well, so much of the hard work for interfacing the two is done by the compiler. C and C++, on the other hand, do not use STDCALL by default, and if you want to manually link a VB object code file    with a C object file, you will need to explicitly make the C interface a STDCALL one.

COM and Windows
Microsoft implemented a technology known as the Component Object Model for Windows. COM essentially takes the object-oriented programming paradigm to the next level, by standardizing the class interface, and allowing classes to be written in different languages (C++, VB, etc.) and interfaced together seamlessly. COM programs (or "COM clients") can be written in most languages that allow object-orientation. More specifically, the only language requirement for COM is that code is generated in a language that can create structures of pointers and, either explicitly or implicitly, call functions through pointers.

Other Languages
Many other programming languages have been implemented on Windows systems, and many of them have some sort of method for interfacing the Win32 API, or the MFC libraries. These interfaces are known collectively as wrappers, because they wrap the functionality of the Win32 API in another programming language. Common wrappers are provided for Perl, Ada, Python, PHP, AutoIT, etc.

Next Chapter

 * 