CSCI E-143 CertPrep:   Legacy Code   (Kalani,  chapter 9)

Saturday,  Nov. 20,  2004

This Saturday,  we (also) cover Kalani's chapter 9,  "Working with Legacy Code".   I think the sample questions will give you a pretty good idea of what you need to know.

The  (parenthesized references)  in this list are explained  here.  

ActiveX Controls

You import these two ways:

Advantages of using ActiveX controls through a wrapper in .NET: Disadvantages of using ActiveX controls through a wrapper in .NET:

Using COM Components

You need to get a proxy,  specifically,  the Runtime Callable Wrapper  (RCW),  so that COM objects will appear to .NET as if they are running in managed code.   Fortunately,  COM has metadata that can be accessed.

There are two ways to create this RCW:

First,  with a command-line tool,  tlbimp.exe,  the Type Library Importer.

Second,  you can addess COM components directly. Advantages and Disadvantages,  tlbimp.exe  vs.  direct reference

Using COM+ Components

These are "serviced" components.   They are handled by .NET exactly the same as COM components.

Platform Invoke  ("PInvoke")

This is a way of calling routines in  unmanaged  libraries,  such as the Windows API.   There are a couple of aspects to this:   (Kalani, page 663)

Yes,  I know: there's no  PInvoke  command.   You can't have everything.
Summary

For ActiveX controls,  import with command-line  amimp.exe  (in the AxHost  "wrapper"  class),  or use  Customize Toolbox  to add directly to the IDE toolbox.

For COM and COM+ components,  provide a Runtime Callable Wrapper (RCW) either with the command-line  tlbimp.exe  tool,  or with a  direct reference added through the Solution Explorer.

For unmanaged libraries,  such as Windows APIs,  use Platform Invoke  ("PInvoke"),  which uses attributes placed before declarations of external methods,  e.g., 

    [DllImport("kernel32.dll",  CharSet=CharSet.Auto)]
    public static extern int GetComputerName(
      StringBuilder buffer,  ref uint size);

The  (parenthesized references)  in this list are explained  here.  
Here are the relevant questions from the two tests at the end of the "short Kalani"  book:  

    Test 1:  questions  39  (page 374;  answer:  page 396),  46.

    Test 2:  questions  6  (page 406;  answer:  page 439),  32,  33.

(Some of these questions may duplicate those in long Kalani.   Both texts are listed here.)


Last revised Nov. 21,  2004