O codigo usado foi este aqui:
#include <stdio.h> //printf() entre outras. #include <stdlib.h> #include <conio.h> //getch(). #include <windows.h> //Necessário para: LoadLibrary(), GetProcAddress() e HINSTANCE. #include <iostream.h> #include <ctime> //Declaração dos ponteiros para função. typedef short _stdcall (*PtrInp)(short EndPorta); typedef void _stdcall (*PtrOut)(short EndPorta, short valor); HINSTANCE hLib; //Instância para a DLL inpout32.dll. PtrInp inportb; //Instância para a função Imp32(). PtrOut outportb; //Instância para a função Out32(). void delay(float seconds) { clock_t current, end; current = clock(); end = current + CLOCKS_PER_SEC * seconds; while(current < end) { current = clock(); //cout << "\n\n\tCONTANDO => " << (end - current)/1000 << " segundos. "; //system("cls"); } } void movimenta(int steps) { while (steps>0) { //cout << t << "\n\n"; outportb(0x378, 12); delay(0.001); //cout << "\n\nPino 1\n\n"; //system("pause"); outportb(0x378, 6); delay(0.001); //cout << "\n\nPino 2\n\n"; //system("pause"); outportb(0x378, 3); delay(0.001); //cout << "\n\nPino 3\n\n"; //system("pause"); outportb(0x378, 9); delay(0.001); //cout << "\n\nPino 4\n\n"; //system("pause"); //cout << "\n\nPino 5\n\n"; //system("pause"); steps--; } } int main(void) { //Carrega a DLL na memória. hLib = LoadLibrary("inpout32.dll"); if(hLib == NULL) //Verifica se houve erro. { printf("Erro. O arquivo inpout32.dll não foi encontrado.\n"); getch(); return -1; } //Obtém o endereço da função Inp32 contida na DLL. inportb = (PtrInp) GetProcAddress(hLib, "Inp32"); if(inportb == NULL) //Verifica se houve erro. { printf("Erro. A função Inp32 não foi encontrada.\n"); getch(); return -1; } //Obtém o endereço da função Out32 contida na DLL. outportb = (PtrOut) GetProcAddress(hLib, "Out32"); if(outportb == NULL) //Verifica se houve erro. { printf("Erro. A função Out32 não foi encontrada.\n"); getch(); return -1; } //------------------------------------------------------------------------------------------------------------------------- //Uso das funções outportb() e inportb(): unsigned char Valor=128; //Em binário: 10000000**** outportb(0x378, 0); int steps[4][4]={{0,145,270,420},{140,0,140,280},{280,140,0,140},{420,280,140,0}}; //Numero de passos do motor para mudar de posição. int NPos=1,Pos=1; while(! kbhit()) { cout << "\n\nElevador na Vaga " << Pos << " . "; cout << "\n\nDigite o Numero da Nova Vaga Desejada: "; cin >> NPos; if (NPos==Pos) { cout << "\n\nElevador ja se encontra na Vaga Desejada.\n\n"; system("pause"); } else { movimenta(steps[Pos][NPos]); } Pos=NPos; system("cls"); } outportb(0x378, 0); FreeLibrary(hLib); //Libera memória alocada pela DLL. return(0); }
Grato.