⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testrtdll.c

📁 windows系统下实时代码,可以进行底层硬件的实时操作
💻 C
字号:
/*++
 *
 * Copyright (c) 1998-2005, Ardence, Inc.  All rights reserved.
 *
 * Module Name:
 *
 *      TestRtdll.c
 *
 * Abstract:
 *
 *      The test uses a counter that belongs to the per-process private data in rtdll.
 *      The rtdllexample.rtdll must be loaded first.
 *      This is done in two steps:
 *         rtssrun /d /s rtdllexample
 *         rtssrun rtssrun loadrtdll
 *      The first step just registered rtdll, the second step loads it,
 *      An user starts the test with "rtssrun testrtdll", and starts it again after few seconds.
 *      So two rtss processes run simultaneously.
 *      The test runs for 30 seconds, and prints incrementing counter for each process.
 *      NOTE: the best idea is to start batch file "testrtdll.bat".
 *
 * Author:
 *
 *      Lev Zaltsman
 *
 * Environment:
 *
 *      RTX application (RTSS). 
 *
 * Revision History:
 *
 *     Initial revision (LDZ)
--*/
#include <windows.h>
#include <stdio.h>
#include <rtapi.h>

#define NO_ERRORS		0
#define ERROR_OCCURED	-1

// declare rtdll import functions
__declspec ( dllimport )
void _stdcall SetCount(int count);

__declspec ( dllimport )
int _stdcall GetCount(void);

__declspec ( dllimport )
void _stdcall IncrementCount(void);

/*** MAIN ****/
int main(int argc, char* argv[])
{
   int i;
	HANDLE hLibModule = NULL;
	LPCSTR lpLibFileName = "rtdllexample.dll";
	ULONG	sleepTime = 1000;

	//*********** Sample Code: TestRtdll ***********\\

	//load Library RtdllGlobals
	hLibModule = LoadLibrary(lpLibFileName);

	//check if loadLibrary returned correctly 
	if(hLibModule==NULL)
	{
		//error caused by loading a corrupt or unregistered Rtdll
		RtPrintf("TestRtdll: ERROR: LoadLibrary() failed.  Get last Error = %d\n", GetLastError());
		RtPrintf("%s maybe corrupt or not registered with RTSS\n", lpLibFileName);
		return (ERROR_OCCURED);
	}

	// test begins
	RtPrintf("\n ***************Test Started*************** \n");
	RtPrintf("\n  Each process must increment its own count \n");

   // clear the count   
   SetCount(0);

   // the test runs 30 seconds
   for(i = 0; i < 30; i++)
   {
       // increment the counter   
       IncrementCount();
 
       // print  the counter
       RtPrintf("\n ProcessId = %d, Count = %d", GetCurrentProcessId(), GetCount());
  
       // Wait for 1 second.
       Sleep(sleepTime);      
    }
    
	 //free the Library before exiting Process
	 if(!FreeLibrary(hLibModule))
	 {
		//error caused by an invalid Library handle
		RtPrintf("TestRtdll: Error: FreeLibrary() failed.  Get Last Error = %d\n", GetLastError());
		return (ERROR_OCCURED);
	 }
    
	//the end
	return (NO_ERRORS);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -