Next Previous Up Top Contents Index

A.2 An example COM server and client

A.2.4 Creating the client

Now we create the actual client application.

1. Choose File > New... from the main window.
2. Select Project and click OK.
The New Project wizard appears.
3. In the Project Type section, select "Console Application (EXE)" and click Next to continue to the next wizard page.
4. Name the project RotNExample-client.
5. Choose a suitable Location for the project.
6. Make sure the "Include any available templates" option is not chosen.
7. Click Next.
8. Choose the Simple libraries option, and choose the "Standard IO streams and string formatting" and "OLE Automation" options.
9. Proceed to the last page of the wizard and click Finish.
10. In the new project, edit library.dylan, and add to the define library declaration the following line:
use RotNExample-client-stubs;

11. Add the same line to the define module declaration in module.dylan.

We now add code to make the client encrypt and decrypt a simple string with the default key of 13 and with the key set to 3.

Note: The remainder of this section of the example involves adding code to RotNExample-client.dylan. A version of this file with all the code we add in this section is available in the Functional Developer installation folder, under Examples\Documentation\RotNExample\RotNExample-client.dylan. You may want to copy that file into place in your project folder rather than typing code in.

12. Modify the main method in RotNExample-client.dylan to look like the following.
define method main () => ()
  with-ole
    format-out("Client connecting to server.\n");
    let server = make-RotNExample();
    local method encrypt-and-decrypt () => ()
      let plaintext = "And he was going ooo-la, oooooo-la...";
      format-out("Plaintext is %=, encrypting.\n", plaintext);
      let ciphertext = IRotNExample/encrypt(server, plaintext);
      format-out("Ciphertext is %=, decrypting.\n", ciphertext);
      let decrypted = IRotNExample/decrypt(server, ciphertext);
      format-out("Decrypted text is %=.\n", decrypted);
    end method;

encrypt-and-decrypt(); server.IRotNExample/key := 3; format-out("Set key to %d.\n", server.IRotNExample/key); encrypt-and-decrypt(); format-out("Client releasing server.\n"); release(server); end with-ole; end method main;

The with-ole macro initializes OLE at entry and uninitializes it at exit.

13. Build the project with Project > Build.
During the build, you will be prompted for the location of the project file RotNExample-client-stubs.hdp.

Getting Started with Functional Developer - 31 MAR 2000

Next Previous Up Top Contents Index