RTDLL Sample
This example program demonstrates how to use an RTDLL in an RTSS Process. It uses library functionality to provide an application similar to the DLL sample.
This sample includes three components:
- A shared RTDLL (SampleRtdll.Rtdll) that defines the exported function.
- An application that explicitly loads the RTDLL at runtime.
- An application that implicitly links against the RTDLL at build time.
Source Files
The Rtdll example includes three projects, available from the VS<Visual Studio Version> folder:
| File | Description |
|---|---|
SampleRtDll_<Visual Studio version>.vcxproj
|
Builds SampleRtdll.Rtdll. This is an RTDLL that contains
the function Toggle which toggles the state of the speaker.
|
|
|
Builds |
|
|
Builds |
The Source folder contains three source files:
| File | Description |
|---|---|
explicitlyUsingRtdll.c
|
Source file that loads an RTDLL, calls an RTDLL function, and then frees the RTDLL. It can be built as either a Win32 .exe binary, or an .rtss binary. |
implicitlyUsingRtdll.c
|
Source file that is compiled with the project settings the .rtdll is linked in, then through an import command we define the toggle function and run the toggle through the RTSS we just called. |
sampleRtdll.c
|
Source file for an RTDLL that contains the function "Toggle" which toggles the state of the speaker. |
Building the Sample
Build the three samples using any of the four available configurations: Debug, Release, RTSSDebug, or RTSSRelease.
- SampleRtdll.Rtdll is placed in the same directory as ExplicitLoadRTDLL.rtss and ImplicitLinkRTDLL.rtss
- The .lib file generated by the RTDLL project is linked in the implicit loader's project settings.
Running the Sample
Run the explicit loader binary:
RTSSrun explicitLoadRTDLL.rtss
Alternatively, you can run the implicit loader binary:
RTSSrun ImplicitLinkRTDLL.rtss
The shared library function Toggle is called repeatedly through a periodic RTAPI timer for 10 seconds in both versions.
Expected Results
- Logs are generated from the DLL lifecycle (DllMain) such as PROCESS_ATTACH and PROCESS_DETACH.
- Console messages confirm success or failure when loading or unloading the RTDLL.
- The explicitly loaded version reports any failure to locate the DLL or the Toggle function.
Unexpected Results
The sample fails to find or load the required RTDLL library (it must be in the same directory as the executable).
Remarks
- The Toggle function manipulates the PC speaker’s state by directly toggling the GATE_BIT on I/O port 0x61.
- In the explicit version:
- The RTDLL is loaded at runtime with LoadLibrary, and the function is called via GetProcAddress.
- The DLL is released afterward using FreeLibrary.
- In the implicit version:
- The RTDLL is linked at build time.
- The Toggle function is declared with __declspec(dllimport) and called directly.
- Both use an RTAPI timer to invoke Toggle repeatedly every 1 ms for 10 seconds.
APIs Referenced
|
RTAPI |
Windows Supported |
|---|---|