IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++ Discussion :

Lecture Console ReadConsoleOutputCharacter


Sujet :

C++

  1. #1
    Membre confirmé
    Homme Profil pro
    Developpeur
    Inscrit en
    Mars 2012
    Messages
    146
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Developpeur
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2012
    Messages : 146
    Par défaut Lecture Console ReadConsoleOutputCharacter
    Bonjour a tous,

    Voila j'éssai de lire ce qui est écrit sur la console par la fonction SnmpUtilPrintAsnAny.

    J''essaye d'utiliser la fonction ReadConsoleOutputCharacter, mais je n'arrive pas a la faire marcher. Le buffer est toujours egale à "".

    Je join mon code

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    int main(int argc, char* argv[])
    {
            SnmpVarBindList snmpVarList;
            AsnInteger errorStatus,errorIndex;
            LPSNMP_MGR_SESSION session;
            char resultat[MAX_PATH];
            COORD CordDef,Cord2;
            CHAR_INFO *test;
     
            //Initialisation snmpVarList
            snmpVarList.list = NULL;
            snmpVarList.len = 1;
            snmpVarList.list = (SnmpVarBind *)realloc(snmpVarList.list, sizeof(SnmpVarBind) *snmpVarList.len);
     
            //Ouverture de Session
            session = SnmpMgrOpen("192.168.2.82","public",1000,3);
            if (session!=0)
            {
                    SnmpMgrStrToOid(".1.3.6.1.2.1.17.4.3.1.2.0.20.56.185.112.146",&snmpVarList.list->name);
                    //Envoi de la requete
                    if (SnmpMgrRequest(session,SNMP_PDU_GET,&snmpVarList,&errorStatus,&errorIndex)!=0)
                    {
                            if (errorStatus==SNMP_ERRORSTATUS_NOERROR)
                            {
     
                                   //SnmpUtilPrintAsnAny(&snmpVarList.list->value);
                                   HANDLE hOut;
                                   char* buff="";
                                   unsigned long *i;
                                   SMALL_RECT *point;
                                   INPUT_RECORD *buffbis;
     
                                   hOut = CreateConsoleScreenBuffer(GENERIC_READ,FILE_SHARE_READ,NULL,CONSOLE_TEXTMODE_BUFFER,NULL);
     
                                   SnmpUtilPrintAsnAny(&snmpVarList.list->value);
                                   CordDef.X = 0;
                                   CordDef.Y = 0;
                                   ReadConsoleOutputCharacter(hOut,buff,256,CordDef,i);
     
                                   cout<<buff;
                            }
                    }
                    //Fermeture de la session
                    SnmpMgrClose(session);
                    system("PAUSE");
            }
            return 0;
    }

  2. #2
    Membre confirmé
    Homme Profil pro
    Developpeur
    Inscrit en
    Mars 2012
    Messages
    146
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Developpeur
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2012
    Messages : 146
    Par défaut
    J'ai trouvé, je met le code complet !! =D

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    #include <windows.h>
    #include <Snmp.h>     //+ lib Snmpapi
    #include <Mgmtapi.h> // + lib mgmtapi
     
    #include <iostream>
    #include <string>
    #include <vector>
    #include <vcl>
     
    #include <cstdio>
     
    using namespace std;
     
    #define TRACE printf
     
    /***********************************************************************
    *      SnmpUtilPrintAsnAny     (SNMPAPI.@) -
    *      http://source.winehq.org/source/dlls/snmpapi/main.c
    */
    VOID WINAPI SnmpUtilPrintAsnAny2(AsnAny *any)
    {
        unsigned int i;
     
        TRACE("(%p)\n", any);
     
        switch (any->asnType)
       {
        case ASN_NULL:       TRACE("Null value\n"); return;
        case ASN_INTEGER32:  TRACE("Integer32 %d\n", any->asnValue.number); return;
        case ASN_UNSIGNED32: TRACE("Unsigned32 %u\n", any->asnValue.unsigned32); return;
        case ASN_COUNTER32:  TRACE("Counter32 %u\n", any->asnValue.counter); return;
        case ASN_GAUGE32:    TRACE("Gauge32 %u\n", any->asnValue.gauge); return;
        case ASN_TIMETICKS:  TRACE("Timeticks %u\n", any->asnValue.ticks); return;
        case ASN_COUNTER64:
        {
            TRACE("Counter64 %x%08x\n", (DWORD)(any->asnValue.counter64.QuadPart>>32),(DWORD)any->asnValue.counter64.QuadPart);
            return;
        }
        case ASN_OCTETSTRING:
        {
            TRACE("String ");
            for (i = 0; i < any->asnValue.string.length; i++)
                TRACE("%c", any->asnValue.string.stream[i]);
            TRACE("\n");
            return;
        }
        case ASN_IPADDRESS:
        {
            TRACE("IpAddress ");
            if (any->asnValue.string.length < 4)
            {
                TRACE("Invalid\n");
                return;
            }
            for (i = 0; i < 4; i++)
            {
                TRACE("%u", any->asnValue.string.stream[i]);
                if (i < 3) TRACE(".");
            }
            TRACE("\n");
            return;
        }
        case ASN_BITS:
        {
            TRACE("Bits ");
            for (i = 0; i < any->asnValue.string.length; i++)
            {
                TRACE("0x%02x", any->asnValue.string.stream[i]);
                if (i < any->asnValue.object.idLength - 1) TRACE(" ");
            }
            TRACE("\n");
            return;
        }
        case ASN_OPAQUE:
        {
            TRACE("Opaque ");
            for (i = 0; i < any->asnValue.string.length; i++)
            {
                TRACE("0x%02x", any->asnValue.string.stream[i]);
                if (i < any->asnValue.object.idLength - 1) TRACE(" ");
            }
            TRACE("\n");
            return;
        }
        case ASN_OBJECTIDENTIFIER:
        {
            TRACE("ObjectID ");
            for (i = 0; i < any->asnValue.object.idLength; i++)
            {
                TRACE("%u", any->asnValue.object.ids[i]);
                if (i < any->asnValue.object.idLength - 1) TRACE(".");
            }
            TRACE("\n");
            return;
        }
        default:
        {
            TRACE("Invalid type %d\n", any->asnType);
            return;
        }
        }
    }
     
     
    int main(int argc, char* argv[]){
     
      vector<string> SNMPErrorInfoInCodes;
      //J'avais commencé avec un vector, mais un map est plus indiqué...
      SNMPErrorInfoInCodes.push_back("\
        0 SNMP_ERRORSTATUS_NOERROR:\n\
        The agent reports that no errors occurred during transmission");
      SNMPErrorInfoInCodes.push_back("\
        1 SNMP_ERRORSTATUS_TOOBIG:\n\
        The agent could not place the results of the requested SNMP operation in a \
        single SNMP message.");
      SNMPErrorInfoInCodes.push_back("\
        2 SNMP_ERRORSTATUS_NOSUCHNAME:\n\
        The requested SNMP operation identified an unknown variable.");
      SNMPErrorInfoInCodes.push_back("\
        3 SNMP_ERRORSTATUS_BADVALUE:\n\
        The requested SNMP operation tried to change a variable but it specified \
        either a syntax or value error.");
      SNMPErrorInfoInCodes.push_back("\
        4 SNMP_ERRORSTATUS_READONLY:\n\
        The requested operation tried to change a variable that was not allowed to \
        change according to the community profile of the variable.");
      SNMPErrorInfoInCodes.push_back("\
        5 SNMP_ERRORSTATUS_GENERR:\n\
        An error other than one of those listed here occurred during the requested \
        operation.");
      SNMPErrorInfoInCodes.push_back("\
        UNKNOWNERROR\n");
      SNMPErrorInfoInCodes.push_back("\
        SNMP_MGMTAPI_TIMEOUT:\n\
        The request timed-out.");
      SNMPErrorInfoInCodes.push_back("\
        SNMP_MGMTAPI_SELECT_FDERRORS:\n\
        Unexpected error file descriptors indicated by the Windows Sockets select \
        function.");
     
      SnmpVarBindList snmpVarList;
      AsnInteger errorStatus,errorIndex;
      LPSNMP_MGR_SESSION session;
     
      //Initialisation snmpVarList
      snmpVarList.list= 0;
      snmpVarList.len= 1;
     
      cout<< "realloc"<< endl;
      snmpVarList.list= (SnmpVarBind*) \
        realloc(snmpVarList.list, sizeof(SnmpVarBind) * snmpVarList.len);
     
      int timeOutInmilliseconds= 3000;
      int numberOfRetries= 2;
     
      cout<< "SnmpMgrOpen"<< endl;
      session = SnmpMgrOpen(
                  "192.168.2.82", "public",
                  timeOutInmilliseconds, numberOfRetries
                  );
     
      if (!session){
        cout<< "no_session"<< endl;
        return 1;
      }
     
      cout<< "session_ok"<< endl;
     
      //.1.3.6.1.2.1.1.1.0 for system description
      //.1.3.6.1.2.1.1.4.0 for system contact
      //.1.3.6.1.2.1.1.5.0 for system name
      //1.3.6.1.2.1.17.4.3.1.2 for port
      SnmpMgrStrToOid(".1.3.6.1.2.1.17.4.3.1.2.0.12.110.158.18.57",
        &snmpVarList.list->name);
     
      cout<< "SnmpMgrStrToOid_ok"<< endl;
     
      //Envoi de la requete
      if (!SnmpMgrRequest(session,SNMP_PDU_GET, &snmpVarList, &errorStatus, &errorIndex)){
        cout<< "SnmpMgrRequest function fails"<< endl;
        cout<<"errorStatus: "<< errorStatus<< " - errorIndex: "<<errorIndex<< endl;
        switch(::GetLastError()){
          case SNMP_MGMTAPI_TIMEOUT:
            cout<< SNMPErrorInfoInCodes[7]<< endl;
            break;
          case SNMP_MGMTAPI_SELECT_FDERRORS:
            cout<< SNMPErrorInfoInCodes[8]<< endl;
            break;
          default:
            cout<< SNMPErrorInfoInCodes[6]<< endl;
        }
        SnmpMgrClose(session);
        system("pause");
        return 1;}
     
     /* cout<< "errorStatus: \n"<< SNMPErrorInfoInCodes[errorStatus]<< endl;
      cout<< endl;
     
      AsnAny* any= &snmpVarList.list->value;
     
      cout<< endl;
      cout<< "by string_constructor only if any->asnType==ASN_OCTETSTRING: "<< endl;
       if (any->asnType==ASN_OCTETSTRING)
          cout<< "String "
              << string(reinterpret_cast<char*>(any->asnValue.string.stream),
                        any->asnValue.string.length).c_str()
              << endl;
     
     
      cout<< endl;
      cout<< "balayage (unicode?) only if any->asnType==ASN_OCTETSTRING: "<< endl;
      if (any->asnType==ASN_OCTETSTRING){
       cout<< "String ("<< any->asnValue.string.length<< ") "<< flush;
       for (int i= 0; i < 30; i++)
         cout<< any->asnValue.string.stream[i]<< flush;
      cout<< endl;
      }                                                */
     
      /*cout<< endl;
      cout<< "by SnmpUtilPrintAsnAny2: "<< endl;
      SnmpUtilPrintAsnAny2(&snmpVarList.list->value);*/
       char myBuffer[256];
      cout<< endl;
      cout<< "by SnmpUtilPrintAsnAny: "<< endl;
    //  gets(myBuffer);
      SnmpUtilPrintAsnAny(&snmpVarList.list->value);
    fgets(myBuffer, 10, stdin);
     
     
     // gets(myBuffer);
      printf("\nLa ligne entrée est : %s\n", myBuffer);
     
      cout<< endl;
      cout<< "SnmpMgrClose"<< endl;
      SnmpMgrClose(session);
      system("Pause");
     
      return 0;
    }

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Débutant] Lecture des données à partir d'une console
    Par zdig10 dans le forum C#
    Réponses: 6
    Dernier message: 14/09/2011, 13h01
  2. S.O.S QProcess (console ou lecture des flux)
    Par CPT_Taverne dans le forum Qt
    Réponses: 0
    Dernier message: 17/06/2010, 15h56
  3. jboss - access lecture web-console / jmx-console
    Par Lady-D dans le forum Wildfly/JBoss
    Réponses: 1
    Dernier message: 19/05/2009, 16h45
  4. Réponses: 2
    Dernier message: 01/05/2009, 16h13
  5. Lecture console : gestion d'un hotel
    Par genius_.net dans le forum Entrée/Sortie
    Réponses: 6
    Dernier message: 17/05/2006, 19h02

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo