2016-11-27 3 views
-2

ich ein Informatik-Student bin und vor kurzem gelernt, wie in Web nach ein paar Such Interrupts in C verwenden ich mit diesem Code kam:C/C++ - mit Unterbrechungen in Visual Studio c arbeiten ++

#include <stdio.h> 
#include <dos.h> 
#include <conio.h> 

#ifdef __cplusplus 

    #define __CPPARGS ... 

#else 

    #define __CPPARGS 

#endif 

#define INTR 0x1c 
#define gotoxy(x,y) printf("\033[%d;%dH", (x), (y)) 
//#define clear() printf("\033[H\033[J"); 
/* 
//positioning 
void gotoxy(int x, int y) 
{ 
    printf("%c[%d;%df",0x1B,y,x); 
} 
*/ 

void interrupt handler(__CPPARGS); 
void interrupt (*oldhandler)(__CPPARGS); 

int countS = 0; 
int s = 0; 
int m = 0; 
int ms = 0; 
int l = 0; 
int flag = 0; 

int main(void) 
{ 
    clrscr(); 
    printf("%02d:%02d:%02d",m,s,ms); 
    oldhandler = getvect(INTR); 

    setvect(INTR, handler); 
    char c; 

    while(1) 
    { 
     c = getch(); 

     switch(c){ 

      case 'e': 
       goto exit_loop; 
       break; 

      case ' ': 
       flag = 1-flag; 
       break; 

      case 'r': 
       flag = s = m = ms = l = 0; 
       clrscr(); 
       printf("%02d:%02d:%02d",m,s,ms); 
       break; 

      case 'l': 
       gotoxy(++l,0); 
       printf("%02d:%02d:%02d",m,s,ms); 
       break; 
     } 
    } 

    exit_loop:; 
    setvect(INTR, oldhandler); 
    return 0; 
} 

void interrupt handler(__CPPARGS) 
{ 

    if(flag == 1){ 

     countS++; 
     ms += 55; 

     if(countS == 18) 
     { 
      countS = ms = 0; 
      s++; 

      if(s==60) 
      { 
       m++; 
       s = 0; 
      } 
     } 

     gotoxy(0,0); 
     printf("%02d:%02d:%02d",m,s,ms); 
    } 
} 

Dieser Code ist eine Art Stoppuhr in C-Konsolen-Anwendung und seine Arbeit perfekt in historischen Turbo C++. Ich änderte meine IDE und jetzt mit Visual Studio 2013, wenn ich ein neues Projekt in Visual C++ erstellen -> Win32ConsoleApplication und fügen Sie diesen Code in der Hauptdatei. es funktioniert nicht. dann sagt ein Fehler, dass ich #include "stdafx.h" in der ersten meiner Datei hinzufügen sollte. nach so tun, das ist die Liste mein Hauptfehler:

void interrupt handler(__CPPARGS); 
void interrupt (*oldhandler)(__CPPARGS); 

und Verwendung von:

Error 1 error C2146: syntax error : missing ';' before identifier 'handler' c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 32 1 ConsoleApplication1 
Error 2 error C2182: 'interrupt' : illegal use of type 'void' c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 32 1 ConsoleApplication1 
Error 3 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 32 1 ConsoleApplication1 
Error 4 error C2065: 'oldhandler' : undeclared identifier c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 33 1 ConsoleApplication1 
Error 5 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 33 1 ConsoleApplication1 
Error 6 error C2086: 'int interrupt' : redefinition c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 33 1 ConsoleApplication1 
Error 7 error C2143: syntax error : missing ';' before '(' c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 33 1 ConsoleApplication1 
Error 8 error C2059: syntax error : ')' c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 33 1 ConsoleApplication1 
Error 9 error C2059: syntax error : ';' c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 33 1 ConsoleApplication1 
Error 10 error C3861: 'clrscr': identifier not found c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 44 1 ConsoleApplication1 
Error 11 error C2065: 'oldhandler' : undeclared identifier c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 46 1 ConsoleApplication1 
Error 12 error C3861: 'getvect': identifier not found c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 46 1 ConsoleApplication1 
Error 13 error C3861: 'setvect': identifier not found c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 48 1 ConsoleApplication1 
Error 14 error C3861: 'clrscr': identifier not found c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 67 1 ConsoleApplication1 

diese Fehler zu diesen Leitungen verbunden sind clrscr();

mein Betriebssystem ist Windows 10-64bit und es ist mein erstes Mal in c/C++ im Visual Studio. Ich mache einige in Turbo C++ und DevC++ vor, aber nur Turbo C++ führt dieses Beispiel und nicht einmal devC++. Was sind die Unterschiede und wie soll ich das lösen? danke

+1

MS-DOS ist tot. –

+2

MS-DOS bleibt inaktiv. Und wir haben es getötet. Wie sollen wir uns trösten, die Mörder aller Mörder? Was heilig und mächtig von allem war, was die Welt noch besaß, ist unter unseren Messern verblutet: Wer wird dieses Blut von uns abwischen? –

+0

MS-DOS war tot: zunächst einmal. Daran besteht kein Zweifel. Das Register seiner Bestattung wurde vom Geistlichen, vom Angestellten, vom Bestatter und vom Haupttrauernden unterzeichnet. Windows hat es unterschrieben. Und der Name von Windows war gut auf "Change", für alles, worauf er seine Hand legte. – user4581301

Antwort

0

Sie arbeiten im 64-Bit-Modus, sodass Sie keinen Zugriff auf BIOS-Interrupts im Realmodus oder MS-DOS-Dienste haben. Ihr Code hat eine Reihe anderer Probleme, aber die Quintessenz ist, dass es ohne einen 16-Bit-Compiler und einen Emulator nicht funktioniert (wie NTVDM, der auf 64-Bit-Windows nicht vorhanden ist)

+0

also meinst du, ich kann das nicht im visual studio beheben oder sollte ich ein paar andere plugins oder compiler darin installieren? was sollte ich jetzt tun? Gibt es eine moderne Idee, die als Turbo C++ ohne Probleme tun kann? –

+0

@ mohammadfallah.rasoulnejad Sie müssen einen 8086 Emulator wie DOSBox oder emu8086 installieren und schreiben Sie Ihren Code auf einen Compiler in diesem - 16-Bit-Real-Modus kann nicht in einem 64-Bit-Betriebssystem emuliert werden. Siehe http://wiki.osdev.org/Real_Mode –