Developing applications on the Windows NT platform requires software developers to become well versed with many software development kits (SDKs), application programming interfaces (APIs), technologies, and at least one integrated development environment.
This chapter discusses current and evolving technologies and helps you properly use the available SDKs and APIs to implement them. Armed with the knowledge contained in this chapter, you can begin on an accelerated and correct path to successful development of robust Windows NT applications and services.
Software Development Toolkits
There are several software development toolkits in the suite of development support products Microsoft has released to this date. The Win32 SDK contains the libraries needed to develop OLE and Win32 applications on Windows NT. The Win32 SDK also includes extensions for telephony, electronic commerce, and database access.
Before you can begin to develop applications for Windows NT, you must obtain a Win32 SDK or one of the Microsoft products that include this SDK. The Win32 SDK contains the libraries, sample code, utilities, and Help files needed to successfully develop Win32 applications.
A recommended companion for any serious Win32 platform developer is the Microsoft Developers Network (MSDN) CD. The Professional Edition of the MSDN includes the Win32 SDK.
The Win32 API included with the Win32 SDK enables you to write virtually any kind of application under a full 32-bit environment. Many elaborate APIs for implementing specific technologies are also a part of the Win32 SDK.
The Microsoft Foundation Classes (MFC) object-oriented API, for example, exposes Windows 32 functions to any C++ or object-oriented language.
The Win32 API can be divided into the following categories:
Windows management: Includes a set of functions and messages to extensively manage the Windows operating system resources. These resources include the concepts of Windows, Carets, Clipboards, common dialog boxes, cursors, NT menus, hooks, icons, keyboard accelerators, keyboard inputs, multiple document interfaces, messages and message queues, mouse input, paintings and drawing, rectangles, timers, the window class, window properties, and window procedures.
Window control: Includes several interfaces to manage every aspect of window controls. Window controls include many subcontrols, such as an Animation control, drag list box, Header control, hot-key control, Image lists, List View control, progress bar, property sheet, Rich Edit controls, status windows, tab control, toolbar, toolkit controls, track bar, Tree View control, up-down controls, combo box, controls, dialog box, Edit control, list box, scroll bar, and Static control.
Console shell: Includes a set of functions and messages to manage shell programming. The shell is an application that enables users to group, start, and control other applications for the Microsoft Windows operating systems.
These functions and messages enable you to write Control Panel applications. They also support software version control, File Manager extensions, screen saver libraries, the Shell Dynamic Data Exchange interface for controlling Program Manager Resources, and even a Windows 95 shell extension on Windows NT.
Graphics device interface: This gives you entire function sets to produce and animate advanced graphics objects.
System services: Windows NT provides a variety of resources within the operating system. These resources provide a robust and standard method of working with files, network transports, application data, security, exception handling, processes, threads, IPC methods, application debugging, performance monitoring, and even server backups.
Network services: Win32 network functions are network independent. Applications can use these functions to add and cancel network connections, retrieve information about the current configuration of the network, or administrate a domain.
The network service API includes support for LAN Manager functions, network DDE, and the Windows Socket interface.
Multimedia service: Win32 API gives developers high-level and low-level interfaces for developing multimedia applications. It includes support for high-level audio, low-level audio, a media control interface, multimedia file input/output, multimedia services, a multimedia timer, and joystick services.
The OLE SDK exposes several powerful interfaces and models that enable developers to write platform-independent and language-independent objects. The OLE SDK contains a specification for the Component Object Model (COM), which is the fundamental model of OLE and ActiveX.
The OLE SDK supports the Microsoft Object Linking and Embedding interface; an incredibly broad and powerful abstraction for interfacing between objects. OLE can be used to implement client or server solutions that can utilize all resources within the Windows operating system. Developers who want to write incredibly powerful applications based on any computing abstracts need to consider OLE as the vehicle to do so.
The next sections describe the primary components of OLE in enough detail for developers to understand the basic concepts behind each. Any development effort should probably spend a good deal on prototyping or defining the problem domain before jumping directly into implementation. Many pieces of OLE are very complex. However, once you understand OLE, it is undoubtedly the most powerful software abstraction available on multiple platforms.
Component Object Model
The Component Object Model (COM) is the basic technology behind OLE. It specifies how objects interact within a single application or between applications.
COM defines certain basic interfaces that provide functions common to all COM-based technologies within OLE. You should put some time into understanding the COM standard before you write applications that use some of the more advanced OLE features.
The data-transfer model enables users to transfer data uniformly with a drag-and-drop operation, a copy/paste operation, or programmatically. This model is supported by the IDataObject interface.
The Structured Storage Model
The structured storage model specifies how data is saved and retrieved from storage. Two types of objects exist within this model: storages and streams. Many resources within the Windows operating system are accessible through the structured storage model.
The Compound Document Model
The compound document model is a document within another application (referred to as the container application) that seamlessly integrates various types of data or items, such as sound clips, spreadsheets, or bitmaps. OLE enables you to use compound documents without worrying about switching between the different applications.
Automation is the capability of an application to control another applications objects programmatically. An integral part of OLE automation is the capability of an object to describe its capabilities through type descriptions implemented by an Object Description Language (ODL). ODL is absolutely necessary in order to implement OLE controls.
OLE objects that support the in-place activation features of OLE documents use OLE automation to expose properties and methods and to provide event support within applications.
Win32 API provides remote procedure calls (RPCs) to enable applications to call functions located remotely on another machine. This machine can be anywhere on the network.
Microsofts implementation of RPC is compatible with the Open Software Foundation (OSF) Distributed Computing Environment (DCE) version. This means that RPC applications written using the Win32 API are able to communicate with other RPC applications on other operating systems that support DCE. You can find more information in the Microsoft Win32 Remote Procedure Call Programmers Guide and Reference.
RPC can be configured to use one or more transports, one or more name services, and one or more security servers. It is designed to work with multiple service providers.
Microsoft RPC consists of runtime libraries, an Interface Definition Language (IDL), and its compiler.
IDL is a rich, complex language that enables you to define interface parameters carefully in terms of their direction and type. IDL files consist of two parts: the interface header and body. It must be compiled with the IDL compiler. The compiler takes the IDL files and generates proxy/stub code, an interface header file, and an interface identifier file.
After an IDL file is compiled successfully, the generated files are run through the standard C/C++ compile and link steps.
Microsoft Visual C++ 4.1 contains some RPC samples.
Win32 SDK gives developers both high-level and low-level services for developing multimedia applications that use the extended capabilities of a multimedia computer.
A sample program called SPEAKN is located in Microsoft Visual C++ 4.1 that demonstrates this type of application programming.
OpenGL, originally developed by Silicon Graphics Incorporated (SGI) for its graphics workstations, enables applications to create high-quality color images and animated 3D graphics independent of the windowing system, operating system, or hardware.
OpenGL includes many components, such as a full set of current OpenGL commands, an OpenGL utility library (GLU), the OpenGL programming guide auxiliary library, Windows Graphic Library APIs, and the new Win32 APIs for pixel formats and double buffering.
Microsoft Visual C++ 4.1 contains some OpenGL samples.
Microsoft has developed several powerful and robust extensions for providing programmatic control of Telephony (TAPI), asynchronous communications (RAS), database access (ODBS, DAO, RDO), and electronic commerce (Exchange SDK).
The TAPI Interface
The Telephony Application Programming Interface (TAPI) provides the API to program basic telephonic functionality using the line-device class functions. A line device is a physical device such as a fax board, a modem, or an ISDN card that is connected to an actual telephone line. Line devices support telephonic capabilities by enabling applications to send or receive information to or from a telephone network.
The API includes place, receive, drop a call, call hold, call transfer (blind and consultative transfer), and call-monitoring capabilities.
The MAPI Interface
You use the Messaging Application Programming Interface (MAPI) to communicate with electronic messaging systems such as fax, voice mail, public communication services AT&T EasyLink, CompuServe, and MCI Mail. MAPI is a component of the Windows 95 operating system and is part of NT 4.0. Because MAPI is an integrated part of the operating system, developers of 16-bit and 32-bit Windows applications can standardize on a consistent interface.
MAPI is a messaging architecture that enables multiple applications to interact with multiple messaging systems seamlessly across a variety of hardware platforms. MAPI consists of a few different interfaces of its own. Together, these interfaces offer an open programming standard that is separated into two independent parts. The first part supports front-end messaging for client applications. The second is a programming interface used by the back-end service providers.
MAPI is made up of a set of common application programming interfaces and dynamic link library (DLL) components. The interfaces are used to create and access diverse messaging applications and messaging systems.
The MAPI SDK includes tools to help in the development of MAPI-compliant client applications, service providers, and message services. Both a 16- and 32-bit version of MAPI are available.
The 32-bit version of the MAPI SDK also is included within the Win32 SDK. It contains a variety of samples and tools in C, C++, and Visual Basic. For more information regarding MAPI, see the Messaging Application Programming Interface (MAPI) Programmers Reference. This reference is included in the documentation that accompanies the MAPI SDK.
ODBC SDK 2.1
The Microsoft Open Database Connectivity (ODBC) SDK version 2.1 is a set of software components, tools, and documentation designed to help you develop ODBC drivers and ODBC-enabled applications for the Windows operating systems.
The ODBC interface allows applications to access data stored in database management systems (DBMS) using the Structured Query Language (SQL) as a standard.
Additionally, a single application can access different database management systems. This enables you to develop, compile, and ship an application without targeting a specific DBMS. Users then can add modules called database drivers that link the application to their choice of database management systems.
The ODBC architecture has four components:
Application: Performs processing and calls ODBC functions to submit SQL statements and retrieve results.
Driver Manager: Loads drivers on behalf of an application.
Driver: Processes ODBC function calls, submits SQL requests to a specific data source, and returns results to the application.
Data source: Consists of the data the user wants to access.
For more information on ODBC, see the Microsoft ODBC SDK Programmers Reference.
The DAO SDK
The Database Access Objects (DAOs) and collections provide a framework for using code to create and manipulate components of your database system. Objects and collections have properties that describe the characteristics of database components and methods that you use to manipulate them.
Objects and collections provide different types of containment relationships. Objects contain zero or more collections.
Microsoft Visual C++ 4.x contains a sample using ODBC that shows how to use the MFC DAO classes to create databases, tables, queries, fields, and indexes. MFC and DAO use the Microsoft Jet database engine, currently version 3.0, to retrieve data from and store data in user and system databases. DAO can read any ODBC data source for which you have an ODBC driver.
The Microsoft Jet database engine is the data manager component on which various implementations are built, such as the MFC DAO classes, Microsoft Access, and Microsoft Visual Basic, and the Microsoft Desktop Database Drivers (currently version 3.0).
The sample also shows how to map the properties of the database objects to user controls.
The RAS SDK
The Remote Access Service (RAS) enables remote users to work as if they are connected directly to a computer network. RAS supports accessing other machines on the network as if all machines are on the same physical network.
The RAS API exposes functions that enable an application to establish, communicate, and terminate remote access to other machines. Applications can use a static or a dynamic version of this API.
The Exchange SDK
The Microsoft Exchange Server SDK enables you to use a powerful new message and data-transport system. The SDK provides functions that support new technologies, such as public folders and signing and sealing.
You can use this SDK to develop client and Microsoft Exchange Server Administrator program extensions for Microsoft Exchange. The SDK also enables you to build client and server applications customized for an environment or to develop stand-alone client and server applications that use Microsoft Exchange Server.
Integrated Development Environment
Microsofts Developer Studio is provided with Microsoft Visual C++ or many professional editions of other Microsoft languages. The Microsoft Developer Studio integrates source management and editing, project management, and debugging into a user interface that enables you to effectively manage the window real estate.
The following sections summarize a great deal of information about several new and improved products from Microsoft. All of the new capabilities integrate effectively into the Microsoft Developers Studio. Furthermore, most of the information within these sections are weighted toward C++ and higher-level language development.
Microsoft Visual C++ 4.1
C++ developers will need to purchase Microsoft Visual C++ 4.1 to get the most recent revisions to the following Microsoft products and standards.
Microsoft Development Studio
Visual C++ 4.1 contains the Microsoft Developer Studio, which integrates Visual C++ with other Microsoft products through one common development environment. Visual C++ 4.1 includes many products, each of which integrates nicely into the Microsoft Developer Studio:
Microsoft Development Library
Microsoft FORTRAN Powerstation
Microsoft Visual Test
Microsoft Visual SourceSafe
Microsoft Visual C++ Cross-Development Edition for Macintosh
The Microsoft Developer Studio provides new features, such as a Class Viewer, a Wizard bar, and an extensive editor emulator for Brief and Epsilon. The new online Help viewer, Infoview, supports the guides online and the MSDN.
Visual C++ is a powerful and intuitive development environment that enables you to develop applications faster and better. Visual C++ makes software reuse easy because it provides many existing objects and classes, such as a component gallery, OLE controls, Custom AppWizards, and MFC extensions.
The compiler for Visual C++ 4.1 is state of the art. It supports the latest C++ language features and many new standards, including runtime type information (RTTI), standard template library (STL), name spaces, minimal rebuild, and incremental linking improvements.
Visual C++ 4.1 includes InstallSHIELD, which is the worldwide standard for software distribution of Windows applications.
In addition to performance improvements, Visual C++ 4.1 incorporates new features for developers targeting the Internet. The new features include Internet server classes, an AppWizard for creating Internet applications, and World Wide Web access within the Developer Studio.
With Visual C++ 4.1, you now can access your favorite World Wide Web sites from within Developer Studio. Simply choose the Web Favorites command from the Help menu. Developer Studio Web Favorites comes preloaded with a list of Microsoft Web sites for Visual C++ developer support. Using the Web Favorites dialog, you can edit this list of Web sites and add your own favorite sites.
Microsoft Foundation Classes 4.0
The Microsoft Foundation Class Library(MFC) is an "application framework" (often called framework) for writing applications for Microsoft Windows and other platforms that support the Win32 API. The framework is implemented as a group of C++ classes, many of which represent common objects such as widows, documents, and so on. MFC 4.0 provides the following new classes.
Visual C++ 4.1 provides an updated version of the industry standard, Microsoft Foundation Class Library 4.0, with many new features:
Additional support for Windows 95 applications
New MFC classes for data access objects (DAO)
OLE control container support
New common dialogs
Internet Server Classes
MFC has added five new classes that implement the Internet Server API (ISAPI). Using these classes, you can create DLLs that add functionality to Internet servers and Web pages:
CHtmlStream: Called by CHttpServer to send a HyperText Markup Language (HTML) stream back to the client.
CHttpFilter: A class for creating an Internet server filter to screen messages sent to and from an Internet server.
CHttpFilterContext: A class that CHttpFilter uses to handle concurrent, multiple requests.
CHttpServer: A class for creating an Internet server extension. Internet server extensions provide a more efficient, DLL-based alternative to Common Gateway Interface (CGI) applications.
CHttpServerContext: A class that CHttpServer uses to handle concurrent, multiple requests.
The new ISAPI Extension Wizard creates Internet server extensions and filters. Internet server extensions and filters are DLLs based on the new Internet Server API (ISAPI) MFC classes. To access the ISAPI Extension Wizard, open the New Project Workspace dialog by choosing the New command from the File menu and then choosing ISAPI Extension Wizard from the dialog.
Other MFC Classes
MFC classes shipping with Visual C++ 4.1 include some new classes:
CDockState: A CObject class that can hold the state of a number of control bars. You can save the state to and load the state from the Registry, an INI file, or the binary contents of a CArchive object.
CRecentFileList: A CObject class that supports the most recently used (MRU) file list.
CSharedFile: A CMemFile class that supports RAM-based shared memory files for fast temporary storage and for transferring raw bytes or serialized objects between independent processes.
New MFC Samples
The 4.1 release of Visual C++ has added many new MFC samples that show you how to perform the following tasks:
ACDUAL: Adding dual-interface support to an MFC-based OLE Automation server. The sample implements the normal dispatch interface and then adds a custom interface derived from IDispatch.
BINDSCRB: Writing an OLE document object for use with the Binder tool in Microsoft Office 95 applications. Based on the Scribble tutorial.
DLGTEMPL: Dynamically creating a dialog template and using the template with CreateDialogIndirect or InitModalIndirect.
HTTPSVR: Using MFC and the Windows Sockets (WinSock) classes to implement a simple World Wide Web HTTP server that supports form creation and execution of Common Gateway Interface (CGI) server applications using the standard HTML constructs.
MFCUCASE: Using MFC classes to create Internet filter DLLs.
ODBCINFO: Determining ODBC driver capabilities at runtime by opening a selected ODBC data source and displaying information using property pages.
ROWLIST: Implementing full-row selection in the Report mode of the CListView control class.
WWWQUOTE: Writing a World Wide Web application for retrieving information (in this case, stock quotes).
Visual C++ 4.1 consolidates methods for accessing samples in the InfoView tab. All samples, including the MFC samples, now are located under the Samples heading. MFC samples no longer can be found under the Visual C++ guides/MFC 4.x heading.
Alphabetical and subject lists of MFC samples now are available under Key Visual C++ Topics (under MFC Samples below the MFC Topics subheading).
Visual Basic 4.0
Microsoft Visual Basic gives you the power and the flexibility to develop everything from quick user interface (UI) prototypes to robust client-server solutions.
Analyzing the complexity and requirements of a solution beforehand often makes the implementation language decision for you due to limitations of the language. Today, almost all new Microsoft specifications such as ActiveX and DAO are available through either VB 4.0 or VC++ 4.1.
Microsoft Visual Basic Enterprise Edition CD-ROM is a programming system for the Windows Platform. It contains Visual Basic 4.0 32-bit and 16-bit, MSDN starter kit (Microsoft Developer Network for Visual Basic users), and Visual SourceSafe 4.0 (a source control system for Visual Basic 4.0) that can be used only under NT 3.51 or later versions and Windows 95.
The Visual Basic Application Edition 2.0 has been added as the language engine in Visual Basic. This version is fully compatible with earlier versions of the stand-alone Visual Basic products and Visual Basic 1.0, which is included in Microsoft Excel 5.0 and Microsoft project 4.0. It supports OLE automation. With the OLE automation, you can "borrow" the functionality of other applications by controlling their objects from within your Visual Basic applications. If the object is an OLE Automation object, you can use its properties and methods in your application.
Windows 95 custom controls such as list views, tree views, a status bar, toolbars, and tabbed dialog boxes enable you to create applications with the Windows 95 interface look and feel.
Visual Basic includes new features designed to give you the means to build client/server applications that manage business-critical data.
Remote automation enables you to create shared, reusable components that use the OLE Automation interface for network communication. Remote data objects (RDOs) and the RemoteData control (RDC) permit applications to access ODBC-accessible data sources without using a local query processor. Although RDO and RDC can access any ODBC data source, they are designed to take advantage of database servers that use sophisticated query engines, such as Microsoft SQL Server and Oracle.
The Windows NT 3.51 resource kit includes Perl 5. Perl is a free-form interpreted language optimized for scanning arbitrary text files, extracting information from text files, and printing reports based on the information. It combines some of the best features of C: sed, awk, and sh.
Windows NT Perl 5
Windows NT Perl 5 is based on the Unix distribution of Perl 5, which supports packages. A package can function as a class with support for dynamic multiple inheritance and virtual methods. Perl 5 also supports multiple simultaneous DBM implementations and OLE automation. You easily can imbed Perl 5 into your C or C++ applications.
To run Windows NT Perl 5, you need a computer running Windows NT Workstation 3.5 or Advanced Server 3.5 or later, with at least 2MB of disk free space.
A Perl script consists of a sequence of declarations and statements and a powerful set of keywords. Some of the keywords follow:
For more information on programming in Perl, refer to Teach Yourself Perl in 21 Days by Sams Publishing.
Perl scripts written under Unix terminate lines with a line feed. In Windows NT, however, lines terminate with a carriage return and a line feed. If you are moving Perl scripts over to NT from Unix, you might have to do some formatting.
Getting More Information about Perl
Information on Perl and extensions are available on the Internet through the World Wide Web, Usenet, or anonymous FTP.
On the Usenet, investigate the following newsgroups:
The HyperText Markup Language (HTML) is the language of the World Wide Web. Hypertext refers to text containing connections to other documents.
Every Web page is written in HTML. All the document formatting, clickable hyperlinks, graphical images, multimedia documents, and fill-in forms are supported through HTML commands.
A Word Internet Assistant is available on the MSDN. You can use it to create a home page and to get started on the Web. You also can download it from www.microsoft.com.
Advanced Programming Under Windows NT 4.0
For the developer who designs custom operating system extensions, Microsoft provides several abstracts, API and object interfaces.
Windows 95 Shell Extension
Within Windows NT 4.0 developers can make extensions to the Windows NT shell. This capability is through a set of interfaces that provide programmatic control over the shell through property sheets. For example, you can assign an icon to each file, add commands to the Context menu or File menu, or control many other parts of the shell.
The interface classes for shell extensions follow:
IShellExtInit: Allocates an interface used to initialize a property sheet extension, a context menu extension, or a drag-and-drop handler.
IShellFolder: Allocates an interface implemented by the shell and used to determine the contents of a folder.
IShellLink: Allocates an interface that allows an application to create and resolve shell links.
IShellPropSheetEx: Allocates an interface that enables a property sheet handler to add or replace pages in the property sheet for a file object.
Microsoft Visual C++ 4.1 provides a sample SHELLEXT.
The Distributed Component Object Model (DCOM), which formerly was known as Network OLE, extends the programming model and constructs introduced by OLE 2.0 to work seamlessly across the network.
DCOM includes features such as the following:
Location transparency: An application need not know where objects it is using are located.
Packaging transparency: A client application does not need to know how objects are packaged as in-process objects (in DLL), or as local or remote objects (in executable).
Free-threaded objects: High-performance, scalable object services supporting simultaneous calls can be written for use by remote clients or by clients on the same machine. OLE (through the use of the RPC runtime) maintains a pool of threads to be used for incoming calls. As method calls on objects arrive from clients, they are dispatched to a thread that executes the method. Applications call CoInitializeEx(NULL, COINIT_MULTITHREADED) to establish multi-threaded object concurrency for a threadtypically, during thread initialization.
Launch Security: Launch Security enables only Administrators to launch existing classes from a remote client.
Access Security: Allows only Administrators to access existing, published objects from a remote client.
Call Level Security: Enforces security to operate at the per-call level between an established connection from a client to an object (server).
The free threaded API supports multithreaded concurrent access to objects. The model used to enforce concurrency is often referred as the apartment model. In the apartment model, an object acquires the concurrency model from the thread in which the object was first marshalled, or from registry information as in the case of an in-proc server DLL.
CoInitializeEx: Initializes COM for use by the current thread.
Activation API for Clients
The activation API exposes functions to a locally or remotely created instance of a specific class. The following list of functions and description are commonly used APIs.
CoCreateInstanceEx: Creates an instance of a specific class on a specific machine.
CoGetClassObject: Retrieves the class object of a specific class.
CoGetInstanceFromFile: Creates a new object and initializes it from a file using IPersistFile::Load.
CoGetInstanceFromIStorage: Creates a new object and initializes it from an IStorage using IPersistStorage::Load.
Call Security Interface and APIs
The COM model supports two mechanisms to secure call. The first mechanism is similar to DCE-RPC, where an application can do its own security checking. The second mechanism is done automatically by the COM infrastructure. To use the second mechanism, applications must provide some set of information that will enable COM to make the necessary calls to secure the applications objects. The following list of functions and description are commonly used APIs.
CoInitializeSecurity: Initializes the security layer.
CoQueryAuthenticationServices: Retrieves a list of the authentication services registered when the process invoked CoRegisterAuthenticationServices.
CoRegisterAuthenticationServices: Establishes the list of authentication services that DCOM uses to authenticate incoming calls.
IClientSecurity: Enables the client to control the security on calls to individual interfaces.
IServerSecurity: Enables the server to retrieve security information about a call and to impersonate the call.
A couple DCOM examples are included with Win32 SDK.
OLECNFG is used by the remote activation registry configuration tool. The tool sets and creates all new Registry keys with the default Registry access control list (ACL). An ACL controls access to anything to which it is attached. Almost every entity that has a name can be configured to employ security. The ACLs for security keys can be modified manually using regedt32.
If the tool runs without any parameters, it displays the current value for the global activation fields. The activation fields are EnableNetworkOLE, DefaultLaunchPermission, DefaultAccessPermission, and LegacyAuthenticationLevel.
Writing Custom Server Applications Under Windows NT
Complexity increases as an application is extended to include a customer server component across a network. Win32 API offers full control over process and thread synchronization in either a console or network service capacity. In addition, the Win32API provides application logging and real-time performance monitoring capabilities. Along with the system utilities provided within Windows NT, the Win32 API enables developers to implement robust and supportable as well as complex applications. Furthermore, the Win32 API is a platform-independent API that works on RISC, ALPHA, MIPS, and other platforms.
Because so many resources are available within Windows NT, you need to know a little about each resource type before you can design the application architecture. This section briefly explains the common resources that should be considered, if not used, in your Win32 application. Along with this explanation is a list of the most common functions and sample code using these functions.
The Win32 API provides support for creating, controlling, prioritizing, and synchronizing Windows NT processes. You can control the priority of the child process as well as its child threads. The following functions are the common functions used to control a Windows NT process:
CreateProcess: Creates a new process and its primary thread. The new process executes the specified executable file.
ExitProcess: Ends a process and all its threads.
GetPriorityClass: Returns the priority class for the specified process.
SetPriorityClass: Controls the priority of a class as scheduled by the Windows NT operating system.
In the case of manipulating a process priority, if no priority is specified, Windows NT uses a default priority.
Threads are very similar to processes, but they allow in some architectures more programmatic control than a process. The following functions commonly are used to control a Windows NT thread:
CreateRemoteThread: Creates a thread that runs in the address space of another process.
CreateThread: Creates a thread to execute within the address space of the calling process.
ExitThread: Terminates a thread.
GetThreadPriority: Returns the priority value for the specified thread.
ResumeThread: Decrements a threads suspend count. When the suspend count is decremented to 0, the execution of the thread is resumed.
SetThreadPriority: Sets the priority value for the specified thread.
Sleep: Suspends the execution of the current thread for a specified interval.
SleepEx: Causes the current thread to enter a wait state until the specified interval of time has passed or until an I/O completion callback function is called.
SuspendThread: Suspends the specified thread.
TerminateThread: Terminates a thread.
The Win32 API provides several ways of enforcing mutual exclusion and synchronization. If you are writing a mutithreaded process, you should be familiar with the following functions:
CreateEvent: Creates a named or unnamed event object.
CreateMutex: Creates a named or unnamed mutex object.
CreateSemaphore: Creates a named or unnamed semaphore object.
ReleaseMutex: Releases ownership of the specified mutex object.
ReleaseSemaphore: Increases the count of the specified semaphore object by a specified amount.
ResetEvent: Sets the state of the specified event object to nonsignaled.
SetEvent: Sets the state of the specified event object to signaled.
WaitForMultipleObjects: When anyone or all of the specified objects are in the signaled state or when the time-out interval elapses, this function fires.
WaitForSingleObject: Specifies that the function returns when the specified object is in the signaled state or when the time-out interval elapses.
Several examples of processes, threads, and events are included as sample code within Microsoft Visual C++ 2.x or 4.x.
Any server application that will run as a Windows NT Service will need to make extensive use of the Windows Registry. The Registry functions support accessing the various keys and values located within it.
Server information and data for all Windows NT services are stored in the Registry in the following section:
The following functions are used most frequently to access the Windows Registry:
RegConnectRegistry: Establishes a connection to a predefined Registry handle on another computer.
RegCreateKeyEx: Creates the specified key.
RegOpenKeyEx: Opens the specified key.
RegQueryValueEx: Retrieves the type and data for a specified value name associated with an open Registry key.
RegSetValueEx: Sets the value associated with the specified key.
An example that uses the Registry is located in Microsoft Visual C++ 2.x or 4.x.
Event logging in Windows NT provides a standard, centralized way for applications to record important software and hardware events. Using the Event log and functions removes the need to develop a similar logging mechanism for your Win32 application. Writing this type of mechanism can sometimes become complex in multi-threaded, multiprocess application development.
The Event Viewer provides a standard user interface for viewing the logs and a programming interface for examining the logs. The more commonly used calls follow:
DeregisterEventSource: Closes a handle returned by the RegisterEventSource.
RegisterEventSource: Returns a handle that can be used with the ReportEvent function to log an event.
ReportEvent: Writes an entry at the end of the specified Event log.
Windows NT Services
A service is an executable object installed in a Registry database maintained by the Service Control Manager (SCM) to provide a unified and secure means of controlling services. Each machine running Windows NT has a Service Control Manager process started by the system at startup. The Service Control Manager is an RPC server.
The functions in Win32 API that access a SCM are provided through RPC so that service configuration and service control processes can manipulate services on a remote machine.
These functions are used to register and affect your application as an NT service:
CreateService: Creates a service object and adds it to the specified Service Control Manager database.
RegisterServiceCtrlHandler: Registers a function to handle service control requests for a service.
SetServiceStatus: Updates the Service Control Managers status information for the calling service.
A sample Service is provided in Microsoft Visual C++ 2.x or 4.0.
Windows NT introduces the concepts of performance objects and counters, which enable you to apply performance monitoring to your application. Performance objects are a collection of counters used to measure attributes and activity in a system at a process or even more granular level.
The Windows NT Perfmon utility is a general-purpose monitor tool that is extensible and independent of other counters in the system. This enables developers to expose performance counters in their own applications for viewing locally or remotely. These are called extended objects rather than system objects, which are part of the operating system itself.
Several structures are provided with Win32 to make use of performance counters and object types:
PERF_COUNTER_DEFINITION: Describes a performance counter.
PERF_DATA_BLOCK: Contains the performance data provided by the RegQueryValueEx function.
PERF_INSTANCE_DEFINITION: Contains the instance-specific information for a block of performance data.
PERF_OBJECT_TYPE: Describes the object-specific performance information.
You can find a sample on how to program performance objects in the NT resource kit (MSDN).
Programming for Windows NT can be both exciting and intimidating. Microsoft provides a comprehensive set of products to make the burden inviting.
Windows NT is a powerful operating system. To harness its power, you first need to harness the Win32 API. The Win32 API and its extensions provide a comprehensive set of functions to fully control Windows NT and its resources. These functions enable a developer to implement whatever solution the project requirements might call for. Platform-independent development has never been so extensive and easy.
Microsoft Language products give developers what they need to make application development for Windows NT a controllable and efficient work effort. The Microsoft Development Studio manages the entire development through an extensive project and source management that integrates a debugging environment, help system, and editing environment all into the same user interface.
The utilities provided with the Windows NT complement the development effort with a set of tools to manage application logging and real-time monitoring of system resources.