IBM Support

Using a dynamic link library (DLL) from within a Rose RealTime model

Troubleshooting


Problem

It is possible for an IBM Rational Rose RealTime application to make use of Windows DLLs, but the online documentation does not explain how to do it.

Resolving The Problem

This technote is written for expert users who would like to model the usage of a dynamic link library within their Rose RealTime model.

Overview

In the component view, the DLL should be modelled as a << C++ External Library >> component with a dependency to it from any components that use it in the model.

In the logical view, the interface to the DLL should be expressed as one or more classes with the GenerateClass (C++, Class) property turned off. This makes the DLL operations visible to other model elements and tells Rose RealTime not to implement the class in the model.


This technical application note assumes that a DLL exists and can be found in the executable path of the target Windows machine, the .lib file exists for linking, and the .h files exist to provide definitions for the resources within the DLL.

  1. Create new classes in the model with the same name as the classes in the dynamic link library. Clear the GenerateClass (C++, Class) property on each class. Model as much or as little detail as desired. Use the class in the model as you would use any class.
  2. Create a new component in the Component View,
    1. Change the type of the component to "C++ External Library"
    2. Drag and drop the classes created in the logical view associated with this dynamic link library to the component, which adds the required references to the component.
    3. Hit apply to accept your changes.
    4. On the C++ External Library tab, edit the InclusionPaths property and specify the path to the .h files required.
    5. Edit the Libraries property and specify the .lib file created by Visual C++ or supplied by the third party vendor.
  3. Draw a dependency from your application component to this external library component.

This component does not need to be built by Rose RealTime. Attempting a build on this component will generate errors.

When Microsoft Visual Studio for C++ creates a DLL, it also creates a file with a .lib extension.

This .lib file is meant to be used to provide the linker with the information it needs to resolve the exported symbols. The header file used to create the DLL is slightly different than the header file used by the application.

The sample header file provided for this example follows:

  #ifndef BUILDDLL  class RandomNumberGeneratorUtility  #else   class __declspec(dllexport) RandomNumberGeneratorUtility  #endif   {  private:  	double dFraction;  	double dRandVal;  public:  	RandomNumberGeneratorUtility();  	double requestRandom();  };  

The __declspec(dllexport) directive tells Microsoft to export the RandomNumberGeneratorUtility class within the DLL. So BUILDDLL should be defined in the makefile when building the DLL.

For a full listing of the DLL source code:

  /* RandomNumberGeneratorUtility.cpp */  #include <stdlib.h>  #include <time.h>  #include "RandomNumberGeneratorUtility.h"      // Constructor  RandomNumberGeneratorUtility::RandomNumberGeneratorUtility() {  	int i, n = 20;  	time_t t;  	time(&t);  	srand(t);  	for ( i = 0; i < n; i++ )  dRandVal = rand();  	dFraction = dRandVal / RAND_MAX;  }    double RandomNumberGeneratorUtility::requestRandom() {  	// printf("I have received a request for a random number fraction.\n");  	// rtport->RandNum(dFraction).reply();  	dRandVal = rand();  	return ( dFraction = dRandVal / RAND_MAX );  }  

To be sure the DLL was created correctly. Write a small application which tests the DLL.

For example as:

  /* Test dll app 'this.cpp' */  #include "../RandomNumberGeneratorUtility.h"  #include <stdio.h>    int main(void) {  RandomNumberGeneratorUtility * myown = new RandomNumberGeneratorUtility();  fprintf(stdout,"Requested number %d\n",myown->requestRandom());  delete myown;  return 0;  }  

An excerpt from the makefile for the test app shows the /link command referring to the .lib file. The full makefile can be found in the Debug directory of the example.

  this.exe:this.cpp ..\RandomNumberGeneratorUtility.h  cl this.cpp /link cppdlllibrary.lib  

For more information please see the example related to this application note.

cppdlllibrary.zip







[{"Product":{"code":"SSSHKL","label":"Rational Rose RealTime"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"--","Platform":[{"code":"PF033","label":"Windows"}],"Version":"2002;2003","Edition":"All Editions","Line of Business":{"code":"LOB45","label":"Automation"}}]

Historical Number

24717

Document Information

Modified date:
16 June 2018

UID

swg21126015