tstio.cpp

来自「这是一本学习 window编程的很好的参考教材」· C++ 代码 · 共 59 行

CPP
59
字号
#include <stdio.h>
#include <windows.h>
#include <math.h>
#include <conio.h>

typedef bool ( *PFNENABLEPORTS)( WORD port,WORD nPortNum);
typedef bool (*PFNDISABLEPORTS)( WORD port,WORD nPortNum);
typedef bool ( *PFNTEST)();
PFNTEST pFnTest=NULL;
PFNENABLEPORTS pEnablePorts=NULL;
PFNDISABLEPORTS pDisablePorts=NULL;

int main()
{

	HINSTANCE hInst=LoadLibrary("NTPORT.DLL");
	if(hInst==NULL)return FALSE;
	pFnTest=(PFNTEST)GetProcAddress(hInst,TEXT("Test"));
	if(!(pFnTest)())printf("\n Test ports failed!");

	pEnablePorts=(PFNENABLEPORTS)GetProcAddress(hInst,TEXT("EnablePorts"));
	if(pEnablePorts==NULL){
		FreeLibrary(hInst);
		return   FALSE;
	}
	pDisablePorts=(PFNDISABLEPORTS)GetProcAddress(hInst,TEXT("DisablePorts"));
	if(pDisablePorts==NULL){
		FreeLibrary(hInst);
		return   FALSE;
	}
	if((pEnablePorts)(0x40,1)==false)printf("\n Enable ports 40 failed!");
	if((pEnablePorts)(0x43,1)==false)printf("\n Enable ports 43 failed!");;
//Speed your Timer
	printf("现在,你的时钟飞快地闪烁!\n");
	printf("按回车恢复原状!\n");
	__asm {
		mov al,34h
		out 43h,al
		mov ax,0046h
		out 40h,al
		mov al,ah
		out 40h,al
	}
getchar();
//restore your timer
	__asm {
		mov al,34h
		out 43h,al
		mov ax,1770h
		out 40h,al
		mov al,ah
		out 40h,al
	}

	if((pDisablePorts)(0x40,1)==false||(pDisablePorts)(0x43,1)==false)printf("\n Enable ports failed!");
	FreeLibrary(hInst);
	return TRUE;
}

⌨️ 快捷键说明

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