2016-11-27 3 views
-2

のVisual Studio C++での割り込みを扱う:C/C++ - 私はコンピュータサイエンスの学生ですし、最近、私はこのコードを思いついたウェブで検索のカップルの後C. で割り込みを使用する方法を学びました

#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); 
    } 
} 

このコードは、Cコンソールアプリケーションでのストップウォッチのようなもので、歴史的なTurbo C++で完璧なものです。 Visual Studio 2013を使用してIDEを変更しましたが、Visual C++ - > win32ConsoleApplicationで新しいプロジェクトを作成し、このコードをメインファイルに貼り付けたときに使用しました。その仕事ではありません。私のファイルの最初に#include "stdafx.h"を追加しなければならないというエラーが表示されます。そうすることの後に、これは私のメインのエラーリストである:

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 

これらのエラーは、これらの行に関連しています

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

との使用:clrscr();

私のオペレーション・システムがWindowsの10-64bit Visual Studioのc/C++での初めてのプログラミングです。私はTurbo C++とdevC++でいくつかをやっていますが、Turbo C++だけがこのサンプルを実行し、devC++は実行しません。 diffrensesは何ですか?これをどのように解決する必要がありますか? ありがとう

+1

MS-DOSが死んでいます。 –

+2

MS-DOSはまだ無効です。そして私たちはそれを殺しました。すべての殺人犯の殺人者である私たちは、どうやって自分を慰めなければなりませんか?世界がまだ所有しているすべてのものの中で、もっとも偉大で力強いものは、私たちのナイフの下で死に至りました。 –

+0

MS-DOSが死んでいた:まずは。それについては間違いありません。その埋葬の記録は、聖職者、書記官、葬儀業者、および長男の署名を受けた。 Windowsはそれに署名しました。そして、Windowsの名前は「変更」には良いものでした。 – user4581301

答えて

0

64ビットロングモードで作業しているため、リアルモードBIOS割り込みまたはMS-DOSサービスにアクセスすることはできません。あなたのコードには他にも多くの問題がありますが、最終的には16ビットコンパイラとエミュレータ(64ビットWindowsにはないNTVDMのようなもの)がなければ動作しません。

+0

あなたはこれをビジュアルスタジオで修正できないのですか、それとも他のプラグインやコンパイラをインストールする必要がありますか?私は今どうすればいい?何の問題もなくターボC++としてできる現代的なIDEはありますか? –

+0

@ mohammadfallah.rasoulnejad DOSBoxやemu8086のような8086エミュレータをインストールし、その中のコンパイラにコードを書く必要があります.16ビットリアルモードは64ビットOSでエミュレートできません。 http://wiki.osdev.org/Real_Modeを参照してください。 –

関連する問題