NGWS SDK Samples

The NGWS SDK samples demonstrate how to write applications and components that use the NGWS SDK technologies.

For more information about the NGWS SDK samples, please see the StartSamples.htm page in the …\Samples folder of the NGWS SDK installation directory.

The following sample documentation is included in this section:

Sample
Chat Sample
Code Access Security Sample
Cross Language Exceptions
Cross Language Inheritance
Custom Attribute Sample
DirectShow Video Player Sample
Find Type Class Browser Utility
Garbage Collector Sample
Hosting Managed NGWS Components in Unmanaged C++
Intermediate Language Sample
Managed and Unmanaged Interoperability Bank Sample
Managed Class Viewer Sample
Metadata Reflection Sample
RothIRA NGWS Component Hosting Sample
Secure Resources Sample
Value Enumerator Sample
WinTalk Sample

© 2000 Microsoft Corporation. All rights reserved.


Chat Sample

The purpose of this sample is to introduce developers to delegates and events. Delegates and events are a type-safe method callback mechanism. The sample declares a “chat” server type that multiple “clients” can connect to. Each client registers a delegate (callback method) with the server. Then, when one client sends a string message to the server, the server forwards the message to all registered clients. This code has two implementations. The first uses delegates showing low-level callback mechanism. The second implementation uses events showing how events hide most of the low-level goo associated with delegates.

Location of the Sample

This sample list located in the Chat directory of the NGWS SDK sample directories.

For Example:

C:\Program Files\NGWSSDK\Samples\Chat

Building the Sample

In order to properly build and run this sample, the following steps need to be performed prior to building and running the sample…

  • Type NMAKE All from the command line.

    For Example:

    C:\Program Files\NGWSSDK\Samples\Chat\:>NMAKE All

Running the Sample

In order to run this sample, follow the instructions listed below.

  • Type Chat from the command line.

    For Example:

    C:\Program Files\NGWSSDK\Samples\Chat\:>Chat


Code Access Security Sample

The purpose of this sample is to introduce developers to the mechanics of code access security. Code access security is a mechanism that grants/denies access to resources within a method call. For example, code written by Microsoft may be allowed to write to the disk while code from another company may be forbidden from accessing the disk. This control is enforced even if the code from both companies is used within a single application. This sample repeatedly attempts to access a disk file and an environment variable. Before each attempt, the code access permissions are changed to see the affect.

Location of the Sample

This sample list located in the Permissions directory of the NGWS SDK sample directories.

For Example:

C:\Program Files\NGWSSDK\Samples\Permissions

Building the Sample

In order to properly build and run this sample, the following steps need to be performed prior to building and running the sample.

  • Type NMAKE All from the command line.

    For Example:

    C:\Program Files\NGWSSDK\Samples\Permissions\:>NMAKE All

Running the Sample

In order to run this sample, follow the instructions listed below.

  • Type Permissions from the command line.

    For Example:

    C:\Program Files\NGWSSDK\Samples\Permissions\:>Permissions


Cross Language Exceptions

The Cross Language Exception sample demonstrates the ability using NGWS to throw and catch exceptions using multiple languages. This sample builds three clients and three servers; to demonstrate VC, VB and assembly languages throwing and catching exceptions. Each server contains the same classes and methods, each of which throws various exceptions.

Location of the Sample

This sample list located in the Exceptions directory of the NGWS SDK sample directories.

For Example:

C:\NGWSSDK\Samples\Exceptions

Building the Sample

In order to properly build and run this sample, the following steps need to be performed prior to building and running the sample.

  • Type NMAKE All from the command line.

    For Example:

    C:\NGWSSDK\Samples\Exceptions\:>NMAKE All

Running the Sample

In order to run this sample, follow the instructions listed below.

  • Copy the desired language exception server MyTestException.dll to the desired client directory.

    For Example:

    C:\NGWSSDK\Samples\AsmClient\:>Copy ..\VCServer\MytestException.dll
  • Type Client from the command line.

    For Example:

    C:\NGWSSDK\Samples\AsmClient\:>Client

    Output:

    =============================================================
VC TestExcept.CustomException
Done...Not Thrown CustomException
Finally called
=============================================================
VC TestExcept.TestDivideByZero
Done...Not Thrown TestDivideByZero
Finally called
=============================================================
VC TestExcept.TestNullReferenceException
Done...Not Thrown TestNullReferenceException
Finally called
=============================================================
VC TestExcept.CustomException
Caught Exception: Exception: MyTestException.MyCustomException: MyCustomException
at MyTestException.TestExcept.CustomException(Boolean)
at ThrowException

Message: MyCustomException
Stack Trace: at MyTestException.TestExcept.CustomException(Boolean)
at ThrowException

Help URL: http://something.com/help.html
Error Code: -2147221503
Finally called
=============================================================
VC TestExcept.TestDivideByZero
Caught Exception: Exception: System.DivideByZeroException
at MyTestException.TestExcept.TestDivideByZero(Boolean)
at ThrowException

Message:
Stack Trace: at MyTestException.TestExcept.TestDivideByZero(Boolean)
at ThrowException

Help URL:
Error Code: -2146233083
Finally called
=============================================================
VC TestExcept.TestNullReferenceException
Caught Exception: Exception: System.NullReferenceException
at MyTestException.TestExcept.TestNullReferenceException(Boolean)
at ThrowException

Message:
Stack Trace: at MyTestException.TestExcept.TestNullReferenceException(Boolean)
at ThrowException

Help URL:
Error Code: -2147467261
Finally called
Pass


Cross Language Inheritance

The Cross language Inheritance sample demonstrates how components targeting the NGWS environment support cross language inheritance.

Location of the Sample

This sample list located in the Crosslang directory of the NGWS SDK sample directories.

For Example:

C:\NGWSSDK\Samples\Crosslang

Building the Sample

In order to properly build and run this sample, the following steps need to be performed prior to building and running the sample.

  • Type NMAKE All from the command line.

    For Example:

    C:\NGWSSDK\Samples\Crosslang\:>NMAKE All

Running the Sample

In order to run this sample, follow the instructions listed below.

  • Load Internet Explorer.
    1. Select Internet Options from the Tools menu.
    2. Select the Advanced tab, and make sure the Browse in new process option is checked.
  • Use Internet Explorer to browse the HTML file named TABLE.HTM in the CROSSLANG directory.

    For Example:

    http://localhost/Crosslang/table.htm


Custom Attribute Sample

The purpose of this sample is to introduce more advanced developers to NGWS custom attributes. This sample demonstrates how to create a custom attribute and associate the attribute with a type and member. Additionally the sample demonstrates how to use reflection to determine if a type/member has a custom attribute associated with it.

Location of the Sample

This sample list located in the CustAttr directory of the NGWS SDK sample directories.

For Example:

C:\Program Files\NGWSSDK\Samples\CustAttr

Building the Sample

In order to properly build and run this sample, the following steps need to be performed prior to building and running the sample.

  • Type NMAKE All from the command line.

    For Example:

    C:\Program Files\NGWSSDK\Samples\CustAttr\:>NMAKE All

Running the Sample

In order to run this sample, follow the instructions listed below.

  • Type CustAttr from the command line.

    For Example:

    C:\Program Files\NGWSSDK\Samples\CustAttr\:>CustAttr


DirectShow Video Player Sample

This sample is a command line program demonstrating the usage of a classic COM object from NGWS. It instantiates the DirectShow FilterGraphManager and instructs it to render a file.

Location of the Sample

This sample list located in the Videoplayer directory of the NGWS SDK sample directories.

For Example:

C:\NGWSSDK\Samples\Videoplayer

Building the Sample

In order to properly build and run this sample, the following steps need to be performed prior to building and running the sample.

  • Type NMAKE All from the command line.

    For Example:

    C:\NGWSSDK\Samples\Videoplayer\:>NMAKE All

Running the Sample

In order to run this sample, follow the instructions listed below.

  • Type Videoplayer from the command line.

    For Example:

    C:\NGWSSDK\Samples\Videplayer\:>Videoplayer C:\Windows\Clock.avi


Find Type Class Browser Utility

This sample utility provides the user with a simple command line interface to provide information about types in their environment. Sometimes locating a specific type can be difficult (what namespace is it in, which DLL?) and once you have located the type - the documentation may be unavailable or it is out of date. This utility provides a simple way for a developer to determine what types are available, what module they are in and what interfaces, methods, fields, properties and events are available on the type.

Location of the Sample

This sample list located in the Findtype directory of the NGWS SDK sample directories.

For Example:

C:\NGWSSDK\Samples\Findtype

Building the Sample

In order to properly build and run this sample, the following steps need to be performed prior to building and running the sample.

  • Type NMAKE All from the command line.

    For Example:

    C:\NGWSSDK\Samples\Findtype\:>NMAKE All

Running the Sample

In order to run this sample, follow the instructions listed below.

  • Type Findtype from the command line.

    For Example:

    C:\NGWSSDK\Samples\Findtype\:>Findtype String

    Output:

    class      System.Runtime.Serialization.Formatters.Binary.BinaryObjectString
class      System.NewIO.StringReader
class      System.String
class      System.Security.Util.SiteString
class      System.Collections.StringTable
class      System.Collections.StringTable$SyncStringTable
class      System.Collections.StringTable$StringTableEnumerator
class      System.IO.StringReader
class      System.IO.StringWriter
class      System.TimeSpan$StringParser
class      System.Security.Util.StrongNameString
class      System.Security.Util.StringPair
class      System.__DTString
class      System.Security.Util.StringExpressionSet
class      System.Text.StringBuilder
class      System.NewIO.StringWriter
class      System.Globalization.StringInfo
class      System.Security.Util.URLString
class      System.Security.Util.DirectoryString
struct     System.Reflection.Emit.StringToken
class      System.Security.SecurityStringPair


Garbage Collector Sample

The purpose of this sample is to introduce developers to the garbage collector in NGWS. The garbage-collected heap manages all class object. This heap monitors the lifetime of objects and frees them only when no part of the program references the objects. This ensures that objects never leak and references to objects are always valid. This sample demonstrates how the garbage collector works. In addition, this sample shows how to properly design classes that work well in a garbage-collected environment. Finally, the sample shows how an application can control some of the garbage collector’s behavior. For example, the sample shows how to force collections, how to promote objects, and how to work with weak references to objects.

Location of the Sample

This sample list located in the GC directory of the NGWS SDK sample directories.

For Example:

C:\Program Files\NGWSSDK\Samples\GC

Building the Sample

In order to properly build and run this sample, the following steps need to be performed prior to building and running the sample.

  • Type NMAKE All from the command line.

    For Example:

    C:\Program Files\NGWSSDK\Samples\GC\:>NMAKE All

Running the Sample

In order to run this sample, follow the instructions listed below.

  • Type GC from the command line.

    For Example:

    C:\Program Files\NGWSSDK\Samples\GC\:>GC


Hosting Managed NGWS Components in Unmanaged C++

This sample demonstrates how to load NGWS assemblies into application domains. The sample can use both assemblies containing explicit manifests and existing dll's that do not contain manifests. However, the level of functionality offered by the sample is different depending on whether the code you are referencing is described by a manifest or not.

Requirements:

This sample requires the installation of Visual C++ 6.0 in order to function properly.

Location of the Sample

This sample list located in the Corhost directory of the NGWS SDK sample directories.

For Example:

C:\NGWSSDK\Samples\Assemblies\Corhost

Building the Sample

In order to properly build and run this sample, the following steps need to be performed prior to building and running the sample.

  1. Type COMREG MSCORLIB.DLL from the command line.

    For Example:

    C:\NGWSSDK\Samples\Assemblies\Corhost\:>COMREG MSCORLIB.DLL
  2. Add the NGWS SDK Include directory to the Visual C++ 6.0 development environment.
  3. Select Options under the Tools Menu.
  4. Select the Directories tab
Click on the first empty text area, and type the path to the NGWS SDK include directory. Or click the browse button and browse to the NGWS SDK include directory
Typically:
C:\NGWSSDK\Include
  1. Open the CorHost development project CORHOST.DSW in the Visual C++ 6.0 development environment.
  2. Press F7 or Choose Build CorHost.exe from the Build Menu

Running the Sample

In order to run this sample, follow the instructions listed below.

  • Type NMAKE MAKEMOUNTAINS from the command line.

    For Example:

    C:\NGWSSDK\Samples\Assemblies\Corhost\:>NMAKE MAKEMOUNTAIN


Intermediate Language Sample

The purpose of this sample is to introduce more advanced developers to the NGWS intermediate language. The program is just the simple number guessing game that tells you higher or lower until you get the correct answer. It was created with the intent of being a sample, so it contains some code that is simply used to illustrate features and may otherwise be considered useless or inefficient. The .il file is just the result of running ILDasm over the original .exe and does not contain any comments.

Location of the Sample

This sample list located in the ASM directory of the NGWS SDK sample directories.

For Example:

C:\NGWSSDK\Samples\Asm

Building the Sample

In order to properly build and run this sample, the following steps need to be performed prior to building and running the sample.

  • Type NMAKE All from the command line.

    For Example:

    C:\NGWSSDK\Samples\Asm\:>NMAKE All

Running the Sample

In order to run this sample, follow the instructions listed below.

  • Type Numguess from the command line.

    For Example:

    C:\NGWSSDK\Samples\Asm\:>Numguess


Managed and Unmanaged Interoperability Bank Sample

This sample demonstrates bi-directional unmanaged NGWS/managed NGWS Interoperability functionality with NGWS servers written in VB and VC and a COM client written in VB. Pressing the load button on the form and loading the included 1234.txt file, will load sample customer information.

Requirements:

This sample requires the installation of Visual Basic 6.0 to function properly.

Architecture:

The following diagram shows the basic architecture of the Bank sample, and how it uses managed and unmanaged code.

Location of the Sample

This sample list located in the Bank directory of the NGWS SDK sample directories.

For Example:

C:\NGWSSDK\Samples\Bank

Building the Sample

In order to properly build and run this sample, the following steps need to be performed prior to building and running the sample.

  • Type NMAKE All from the command line.

    For Example:

    C:\NGWSSDK\Samples\Bank\:>NMAKE All

Running the Sample

In order to run this sample, follow the instructions listed below.

  1. Type NMAKE MAKEFILE from the command line.

    For Example:

    C:\NGWSSDK\Samples\Bank\:>NMAKE MAKEFILE
  2. The sample will be loaded in the Visual Basic 6.0 development environment during the last steps of the build process.
  3. Press F5 to execute the unmanaged Visual Basic 6.0 portion of the sample.


Managed Class Viewer Sample

This sample is an ASP+ based managed class viewer that dynamically generates syntax and description information about NGWS classes. By using reflection to obtain information about classes and interfaces, this tool provides accurate up-to-date class lists, member lists, and syntax.

Location of the Sample

This sample list located in the ClsView directory of the NGWS SDK sample directories.

For Example:

C:\Program Files\NGWSSDK\Samples\ClsView

Building the Sample

In order to properly build and run this sample, the following steps need to be performed prior to building and running the sample.

  • Type NMAKE All from the command line.

    For Example:

    C:\Program Files\NGWSSDK\Samples\ClsView\:>NMAKE All

Running the Sample

In order to run this sample, follow the instructions listed below.

  • Use Internet Explorer to browse the default HTML file in the RothIRA directory.

    For Example:

    http://localhost/ClsView/Default.aspx


Metadata Reflection Sample

This sample demonstrates the usage of the Reflection classes, which are a feature in NGWS. Reflection allows object inspection and dynamic invocation. The reflector program uses NGWS reflection to inspect the methods and properties of the class named on the command line at runtime. You can also invoke the class’s methods at runtime by using the command line switches.

Location of the Sample

This sample list located in the Reflector directory of the NGWS SDK sample directories.

For Example:

C:\NGWSSDK\Samples\Reflector

Building the Sample

In order to properly build and run this sample, the following steps need to be performed prior to building and running the sample.

  • Type NMAKE All from the command line.

    For Example:

    C:\NGWSSDK\Samples\Reflector\VC\:>NMAKE All

Running the Sample

In order to run this sample, follow the instructions listed below.

  • Type Reflector from the command line.

    For Example:

    C:\NGWSSDK\Samples\Reflector\VC\:>Reflector -V -M Factorial

    Output:

    Class: Factorial
Methods (12)
  System.Type GetType ()
  System.String ToString ()
  Boolean Equals (System.Object)
  Int32 GetHashCode ()
  Void Wait ()
  Boolean Wait (Int32)
  Void Notify ()
  Void Notify (Boolean)
  Void NotifyAll ()
  Int32 GetObjectContext ()
  Int32 Value (Int32)
  Int32 calc (Int32)


RothIRA NGWS Component Hosting Sample

This sample demonstrates how to host a NGWS class in a web page using the <OBJECT> tag. An important aspect of this sample is that it shows how NGWS can download and execute code without requiring an registry entries to be made on the machine.

Location of the Sample

This sample list located in the Rothira directory of the NGWS SDK sample directories.

For Example:

C:\NGWSSDK\Samples\Assemblies\Rothira

Building the Sample

In order to properly build and run this sample, the following steps need to be performed prior to building and running the sample.

  • Type NMAKE All from the command line.

    For Example:

    C:\NGWSSDK\Samples\Assemblies\Rothira\:>NMAKE All

Running the Sample

In order to run this sample, follow the instructions listed below.

  • Use Internet Explorer to browse the default HTML file in the RothIRA directory.

    For Example:

    http://localhost/RothIRA/default.htm


Secure Resources Sample

The purpose of this sample is to introduce developers to NGWS secure resources. This sample demonstrates how to create a custom resource and set permissions for it, by deriving a class from the System.Security.CodeAccessPermission class. Your own custom permissions merge seamlessly into the code access security framework using the standard permission mechanisms.

Location of the Sample

This sample list located in the SecureRes directory of the NGWS SDK sample directories.

For Example:

C:\Program Files\NGWSSDK\Samples\SecureRes

Building the Sample

In order to properly build and run this sample, the following steps need to be performed prior to building and running the sample.

  • Type NMAKE All from the command line.

    For Example:

    C:\Program Files\NGWSSDK\Samples\SecureRes\:>NMAKE All

Running the Sample

In order to run this sample, follow the instructions listed below.

  • Type SecureResources from the command line.

    For Example:

    C:\Program Files\NGWSSDK\Samples\SecureRes\:>SecureResource


Value Enumerator Sample

The purpose of this sample is to introduce developers to the NGWS value and enumerated types. This sample demonstrates how to create and work with value and enumerated types. The sample derives the types from the System.ValueType and System.Enum classes. Each of these classes provide features that enables the developer to easily work with them.

Location of the Sample

This sample list located in the ValueEnum directory of the NGWS SDK sample directories.

For Example:

C:\Program Files\NGWSSDK\Samples\ValueEnum

Building the Sample

In order to properly build and run this sample, the following steps need to be performed prior to building and running the sample.

  • Type NMAKE All from the command line.

    For Example:

    C:\Program Files\NGWSSDK\Samples\ValueEnum\:>NMAKE All

Running the Sample

In order to run this sample, follow the instructions listed below.

  • Type ValueEnum from the command line.

    For Example:

    C:\Program Files\NGWSSDK\Samples\ValueEnum\:>ValueEnum


WinTalk Sample

WinTalk is a Windows application that allows you to communicate to another remote WinTalk client using TCP/IP sockets. The application has a Windows user interface, which contains two multi-line edit controls and two buttons ("Connect" and "Disconnect"). The upper edit control will display status messages as well as incoming "talk" messages from a remote running WinTalk. The bottom edit control is where the user types outbound messages.

Location of the Sample

This sample list located in the Wintalk directory of the NGWS SDK sample directories.

For Example:

C:\Program Files\NGWSSDK\Samples\Wintalk

Building the Sample

In order to properly build and run this sample, the following steps need to be performed prior to building and running the sample.

  • Type NMAKE MAKEFILE from the command line.

    For Example:

    C:\Program Files\NGWSSDK\Samples\Wintalk\CS\:>NMAKE MAKEFILE

Running the Sample

In order to run this sample, follow the instructions listed below.

  • Type Wintalk from the command line.

    For Example:

    C:\Program Files\NGWSSDK\Samples\Wintalk\CS\:>Wintalk

    Note: that since the connect dialog defaults to host="localhost" and port="5000", clicking connect and then clicking "OK" on the connect dialog will most likely result in WinTalk attempting to connect to itself. If this happens, WinTalk will initially accept the connection, realize that a connection is in progress, and immediately terminate the connect request


Topic Not Found

No matching topic was found. The link may be out of date, incorrectly authored, or the topic may not be available in this release.

You may be able to find the topic by using the index or search tab instead.


Copyright

NGWS SDK Documentation

This is a preliminary document and may be changed substantially prior to final commercial release. This document is provided for informational purposes only and Microsoft makes no warranties, either express or implied, in this document. Information in this document, including URL and other Internet Web site references, is subject to change without notice. The entire risk of the use or the results of the use of this document remains with the user. Unless otherwise noted, the example companies, organizations, products, people and events depicted herein are fictitious and no association with any real company, organization, product, person or event is intended or should be inferred. Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft Corporation.

Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this document. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property.

Unpublished work. © 1999 - 2000 Microsoft Corporation. All rights reserved.

Microsoft, MS-DOS, Windows, Windows NT, Active Directory, ActiveX, Authenticode, FrontPage, IntelliSense, JScript , Outlook, Visual Basic, Visual Basic Scripting Edition (VBScript), Visual C++, Visual Studio, and Win32 are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries.

The names of actual companies and products mentioned herein may be the trademarks of their respective owners.