KeyView 23.2

# hellovapi

`hellovapi` is a simple program that demonstrates how to use Viewing SDK to display documents in your application. The program creates a Windows application window, and then creates a child window that the Viewing SDK uses to display documents. The Viewing SDK is controlled by sending Windows-style messages to the child window. The set of messages that you send to the child window form the Viewing API (VAPI). The child window is known as a VAPI window. The VAPI messages are described in Message Parameters.

## Load kvvapi.dll

Before you can create a VAPI window, you must load the VAPI library (`kvvapi.dll`) by using the `LoadLibrary` function. In `hellovapi`, the library is loaded in the `InitializeVAPI` function which is called during the processing of the `WM_CREATE` message.

The library is loaded in the following way:

1. `InitializeVAPI` calls either the `GetPrivateProfileString` Windows function or `RegQueryValueEx` to get the value of `HOME` in the `General` section of the `kvsdk.ini` file or Windows registry.

   `GetPrivateProfileString` gets the value from `kvsdk.ini`, and `RegQueryValueEx` gets the value from the registry. The `HOME` setting specifies the location of the Viewing SDK `bin` directory. `InitializeVAPI` demonstrates how to get this setting from both the registry and `kvsdk.ini` file. By default, `InitializeVAPI` gets the value from `kvsdk.ini`.

2. `InitializeVAPI` then creates the path to the VAPI library and loads it:

       wsprintf (szDLLPath, TEXT("%s\\%s"), szHome, VAPIDF_VAPI_DLL_NAME);
       hLibVAPI = LoadLibrary (szDLLPath);

## Create the VAPI Window

After the VAPI library is loaded, the program creates the VAPI window by calling `CreateWindow` with a class name of `VAPIDF_VAPI_WINDOW_CLASS_NAME`:

    hWndVAPI = CreateWindow (VAPIDF_VAPI_WINDOW_CLASS_NAME,
                        NULL,
                        WS_CHILD | WS_DISABLED,
                        rc.left, rc.top, rc.right, rc.bottom,
                        hWnd,
                        NULL,
                        hLibVAPI,
                        &CreateParams);

The last parameter passes in a pointer to VAPI creation information. This creation information is in the structure of type `TPVAPICreateParams`, and tells VAPI where to locate the initialization settings, and whether they are in the registry or in `kvsdk.ini`. The `hellovapi` program uses the `bUseRegistry` global variable to specify whether to get the settings from the registry or `kvsdk.ini`.

By default, `hellovapi` tells VAPI to use the `kvsdk.ini` file that was located with the call to `InitializeVAPI`. The path to the `kvsdk.ini` file is stored in the `szIniFileName` global variable.

To specify the registry

1. Set `uProfileType` to `PROFILEDF_USE_REG`.

2. Set `lpszRegistryName` to the registry name of the Viewing SDK key under the main branch `HKEY_LOCAL_MACHINE\SOFTWARE`. The default is `Verity\Viewing SDK`.

To specify an initialization file

1. Set `uProfileType` to `PROFILEDF_USE_INI`.

2. Set `lpszIniFileName` to the location of the initialization file.

   NOTE: The strings that you pass in for initialization information must be ASCII strings. If your application is in Unicode, you must convert the strings to ASCII before you pass them in.

    // Initialize the parameters for the creation of the VAPIwindow.//
    memset (&CreateParams, 0, sizeof(TPVAPICreateParams));
    if (bUseRegistry)
      {
          CreateParams.uProfileType     = PROFILEDF_USE_REG;
          CreateParams.lpszRegistryName = REGISTRY_NAME_ASCII;
      }
    else
      {
          CreateParams.uProfileType    = PROFILEDF_USE_INI;
          CreateParams.lpszIniFileName = szIniFileName;
      }

## Open a Document

To tell VAPI to open a document

1. Create a `TPVAPIOpenDocInfoEx` structure.

2. Send VAPI a `VAPIM_INIT` message with the `wParam` set to `VAPIMWP_INIT_OPENDOCEX`, and the `lParam` set to the address of the `TPVAPIOpenDocInfoEx` structure.

This is demonstrated in the `OpenDoc` function. It uses a Windows Open dialog box to get the name of a file, and sets the `lpszFilePath` parameter of the `TPVAPIOpenDocInfoEx` structure to this file name. If it is successful, the `VAPIM_INIT` message returns `VAPI_RETURN_SUCCESS`.

NOTE: The file name must be an ASCII string. If your application is in Unicode, you must convert the string to ASCII before passing it in.

    // Open the document.//

    memset (&OpenDocInfo, 0, sizeof(TPVAPIOpenDocInfoEx));

    OpenDocInfo.lpszFilePath = szFileName;

    lResult = SendMessage (hWndVAPI, VAPIM_INIT, VAPIMWP_INIT_OPENDOCEX,

                          (LPARAM)&OpenDocInfo);

Copyright 2016-2023 Open Text
Version 23.2 | Last updated March 2023

Send documentation feedback

Close

Send documentation feedback

To send feedback using your default email client, open an email window.

Otherwise, send your feedback and the information below to swpdl.idoldocsfeedback@microfocus.com.

We appreciate your feedback!

Product: IDOL KeyView 23.2

Topic Title: hellovapi