Click or drag to resize

Using Code from External DLLs

Since a Nimbus driver is a standard Visual C++ project, it can use code from an external DLL in very much the same fashion as any other Visual C++ project. It may be that an external DLL includes logic for performing register-based I/O or a previous-generation VXI Plug-n-Play driver may exist and the developer wishes to use it directly rather than replicating the logic from scratch in the Nimbus driver code.

The procedure for accessing an external DLL from a Nimbus driver project is essentially the same as for any other Visual C++ project. One item that must be considered is how the external DLL is initialized and closed down, and how it uses instrument I/O. The section below gives a brief example of how the initialization and shutdown of a external DLL may be incorporated into a Nimbus driver.

Initializing and Closing the External DLL

There are several possibilities on where to place the initialization code, but the best place is to override the InitializeIO and CloseIO functions. A simple example of this is shown in the code below.

C++
HRESULT Acme4321::InitializeIO()
{
  HRESULT hr = __super::InitializeIO();
  if (SUCCEEDED(hr))
  {
    // Initialize the session
    ViStatus status = mydll_initWithOptions(GetResourceDescriptor(), ..., &m_session);
    if (status != VI_SUCCESS)
    {
      // TODO: Report appropriate error based on status code
    }
  }
  return hr;
}

HRESULT Acme4321::CloseIO()
{
  HRESULT hr = __super::CloseIO();
  if (SUCCEEDED(hr))
  {
    // Close the session
    ViStatus status = mydll_close(m_session);
    m_session = VI_NULL;
  }
  return hr;
}
See Also

Download a complete CHM version of this documentation here.