Visualizzazione dei risultati da 1 a 10 su 10
  1. #1
    Utente di HTML.it
    Registrato dal
    Sep 2009
    Messaggi
    487

    [C++] Crash nella chiamata di Sleep()

    Ciao ragazzi... ecco il seguente codice compilato con Dec-C++ 4992.
    Prima di controllarlo vi consiglio di eseguirlo e capire l'assurdità del problema.
    Ecco il codice.

    Questo è VKM.h dove ci sono le funzioni necessarie per il codice
    Codice PHP:
    #include <windows.h>
    #include <winable.h>
    #include <cstdio>
    #include <Winuser.h>
    #include <string.h>
    #include <sstream> //Per stampare le variabili sui box

    #define VKM_0 0x30
    #define VKM_1 0x31
    #define VKM_2 0x32
    #define VKM_3 0x33
    #define VKM_4 0x34
    #define VKM_5 0x35
    #define VKM_6 0x36
    #define VKM_7 0x37
    #define VKM_8 0x37
    #define VKM_9 0x39

    #define VKM_A 0x41
    #define VKM_B 0x42
    #define VKM_C 0x43
    #define VKM_D 0x44
    #define VKM_E 0x45
    #define VKM_F 0x46
    #define VKM_G 0x47
    #define VKM_H 0x48
    #define VKM_I 0x49
    #define VKM_J 0x4a
    #define VKM_K 0x4b
    #define VKM_L 0x4c
    #define VKM_M 0x4d
    #define VKM_N 0x4e
    #define VKM_O 0x4f
    #define VKM_P 0x50
    #define VKM_Q 0x51
    #define VKM_R 0x52
    #define VKM_S 0x53
    #define VKM_T 0x54
    #define VKM_U 0x55
    #define VKM_V 0x56
    #define VKM_W 0x57
    #define VKM_X 0x58
    #define VKM_Y 0x59
    #define VKM_Z 0x5a

    #define VKM_NUMPAD0 0x60
    #define VKM_NUMPAD1 0x61
    #define VKM_NUMPAD2 0x62
    #define VKM_NUMPAD3 0x63
    #define VKM_NUMPAD4 0x64
    #define VKM_NUMPAD5 0x65
    #define VKM_NUMPAD6 0x66
    #define VKM_NUMPAD7 0x67
    #define VKM_NUMPAD8 0x68
    #define VKM_NUMPAD9 0x69

    #define VKM_F1 0x70
    #define VKM_F2 0x71
    #define VKM_F3 0x72
    #define VKM_F4 0x73
    #define VKM_F5 0x74
    #define VKM_F6 0x75
    #define VKM_F7 0x76
    #define VKM_F8 0x77
    #define VKM_F9 0x78
    #define VKM_F10 0x79
    #define VKM_F11 0x80
    #define VKM_F12 0x81

    #define VKM_MOUSE1 0x05
    #define VKM_MOUSE2 0x04
    #define VKM_MOUSE3 0x06

    #define VKM_TAB 0x09
    #define VKM_ENTER 0x0d
    #define VKM_SHIFT 0x10
    #define VKM_CTRL 0x11
    #define VKM_ALT 0x12
    #define VKM_DEL 0x2e
    #define VKM_ESC 0x1b
    #define VKM_PRINT 0x2a
    #define VKM_SPACE 0x20
    #define VKM_CANCEL 0x03
    #define VKM_CLEAR 0x0c
    #define VKM_BACK 0x08

    #define VKM_LEFT 0x25
    #define VKM_UP 0x26
    #define VKM_RIGHT 0x27
    #define VKM_DOWN 0x28

    #define VKM_CAPITAL 0x14
    #define VKM_DECIMAL 0x6e
    #define VKM_COMMA 0xbc
    #define VKM_ESCLAMATIVE 0//valore da inserire
    #define VKM_QUESTION 0//valore da inserire


    #define VKM_OTHER 6a //nulla

    #include <VKM2.h>

    ////////////////////////////////////////////////////////////////////////////////

    using namespace std;

    #define VKM_MAX_SIZE_OF_INT_POINTER 1999



    int VKM_Size_of_Int_Pointer;
    int VKM_Value_for_capital 1000;

    int VKM_String(char *, int);
    int VKM_Edit(int *, int);
    int VKM_Normal(int);
    int OutputDaFileaop(char path);
    int CentoPerCento();

    int VKM_Int_for_capital_cheecking;
    //int CheekLetto(char *);

    /*
    int CheekLetto(char *Cheek)
    {
    int LungCheek = strlen(Cheek);
    for(int FOR1 = 0;FOR1 < LungCheek;FOR1++)
    {
    if(Cheek[FOR1]=='~')
    return Cheek;   
    }


    }*/


    int CentoPerCento() 
    {
    string s;
    stringstream out;
     
    char numero;
    char Numero1;
    char Numero2;
    numero = new char[1];
    Numero1 = new char[0];
    Numero2 = new char[0];
    string Numero1sNumero2s;


    for(
    int FOR1 0FOR1 100FOR1++)
    {



    out.str("");

    out << FOR1;
    out.str();


    numero = (char *)s.c_str();    
        
    char PrimaCifra numero[0];
    char SecondaCifra numero[1];
    Numero1s PrimaCifra;
    Numero2s SecondaCifra;


    Numero1 = (char *)Numero1s.c_str();    
    Numero2 = (char *)Numero2s.c_str();    

    if(
    FOR1 10)VKM_Normal(VKM_SPACE);
    VKM2_String(Numero1,1);
    VKM2_String(Numero2,1);
    VKM2_String("%",1);

    Sleep(40);


        {
        
    VKM_Normal(VKM_BACK);
        
    VKM_Normal(VKM_BACK);
        
    VKM_Normal(VKM_BACK);
        }
        
    if (
    FOR1 == 99)
        {
        
    VKM2_String("100%",1);    
             
        }
    }

    }
    /*

    */



    int OutputDaFileaop(char path
    {
    Sleep(1);

    FILE file;
    char letto;
    int caratteri 1000;
    char bufferFile[1000];
    int RigheDaLeggere;
    int speed;
    char speedAtoi;
    char righeAtoi;
    letto = new char[1000];
    //char * path = "C:\\file.aop";

    file fopen(path"r");


    righeAtoi fgetc(file);
    RigheDaLeggere atoi(&righeAtoi)*10;
    righeAtoi fgetc(file);
    RigheDaLeggere RigheDaLeggere atoi(&righeAtoi);

    for(
    int FOR1 0;FOR1 RigheDaLeggereFOR1++)
        {
        
    speedAtoi fgetc(file);
        
    speed atoi(&speedAtoi) * 10;
        
    speedAtoi fgetc(file);
        
    speed speed atoi(&speedAtoi);   
       
        
    letto fgets(bufferFilecaratterifile);
        
    VKM2_String(letto,speed);
        }

    fclose(file);
    return 
    1;

    }

    int VKM_Normal(int VKM_Normal)
    {
             
    KEYBDINPUT VKM_pression = {0};
             
    INPUT VKM_input = {0};
             
    int returnVKM;
             
             
             
             
    //VKM_Button pressed
             
    VKM_pression.wVk VKM_Normal;
             
    VKM_input.type INPUT_KEYBOARD
             
    VKM_input.ki VKM_pression;
             
    returnVKM SendInput(1,&VKM_input,sizeof(VKM_input));
             
                
             
             
    //delete VKM_ values
             
    ZeroMemory(&VKM_pressionsizeof(KEYBDINPUT));
             
    ZeroMemory(&VKM_inputsizeof(INPUT));
             
             
    //VKM_Button relased
             
    VKM_pression.wVk VKM_Normal;
             
    VKM_pression.dwFlags KEYEVENTF_KEYUP;
             
    VKM_input.type INPUT_KEYBOARD;
             
    VKM_input.ki VKM_pression;
             
    returnVKM SendInput(1,&VKM_input,sizeof(VKM_input));
             
             
             if(!
    returnVKM
             return 
    0;
             else return 
    1;
             
             
             
    //delete VKM_ values
             
    ZeroMemory(&VKM_pressionsizeof(KEYBDINPUT));
             
    ZeroMemory(&VKM_inputsizeof(INPUT));    
    }

    int VKM_Edit(int VKM_Buttonint VKM_Sleep)
    {        
             for (
    int VKM_Edit_FOR 0
                  
    VKM_Edit_FOR <= VKM_Size_of_Int_Pointer 1;
                  
    VKM_Edit_FOR++)
             
             {
             
    Sleep(VKM_Sleep);
             
    VKM_Int_for_capital_cheecking VKM_ButtonVKM_Edit_FOR ];
             if (
    VKM_Int_for_capital_cheecking 0xffVKM_ButtonVKM_Edit_FOR ] -= VKM_Value_for_capital;
                  
             
    KEYBDINPUT VKM_pression = {0};
             
    INPUT VKM_input = {0};
             
    int returnVKM;
             
             if (
    VKM_Int_for_capital_cheecking 0xffVKM_Normal(VKM_CAPITAL);
             
             
    //VKM_Button pressed
             
    VKM_pression.wVk VKM_ButtonVKM_Edit_FOR ];
             
    VKM_input.type INPUT_KEYBOARD
             
    VKM_input.ki VKM_pression;
             
    returnVKM SendInput(1,&VKM_input,sizeof(VKM_input));
             
                
             
             
    //delete VKM_ values
             
    ZeroMemory(&VKM_pressionsizeof(KEYBDINPUT));
             
    ZeroMemory(&VKM_inputsizeof(INPUT));
             
             
    //VKM_Button relased
             
    VKM_pression.wVk VKM_ButtonVKM_Edit_FOR ];
             
    VKM_pression.dwFlags KEYEVENTF_KEYUP;
             
    VKM_input.type INPUT_KEYBOARD;
             
    VKM_input.ki VKM_pression;
             
    returnVKM SendInput(1,&VKM_input,sizeof(VKM_input));
             
             if (
    VKM_Int_for_capital_cheecking 0xffVKM_Normal(VKM_CAPITAL);
             
             
             
             
    //delete VKM_ values
             
    ZeroMemory(&VKM_pressionsizeof(KEYBDINPUT));
             
    ZeroMemory(&VKM_inputsizeof(INPUT));
             
             }
             
    return 
    0;
    }

    ////////////////////////////////////////////////////////////////////////////////

    int VKM_String(char VKM_Stringint VKM_Sleep)
    {
    //MessageBox(NULL, "()", "", 0);
    int VKM_Int_Pointer[VKM_MAX_SIZE_OF_INT_POINTER];
    if (
    VKM_String] == '\0')MessageBox(NULL"Hard error of the code"""0);
    for (
    int FOR_VKM_String 0
         
    VKM_StringFOR_VKM_String ] != '\0' &&
         
    FOR_VKM_String <= VKM_MAX_SIZE_OF_INT_POINTER;
         
    FOR_VKM_String++)
        {
    //MessageBox(NULL, "switch", "", 0);
        
    switch(VKM_StringFOR_VKM_String ])
            {
            case 
    'a': {VKM_Int_PointerFOR_VKM_String ] = VKM_A; } break;
            case 
    'b': {VKM_Int_PointerFOR_VKM_String ] = VKM_B; } break;
            case 
    'c': {VKM_Int_PointerFOR_VKM_String ] = VKM_C; } break;
            case 
    'd': {VKM_Int_PointerFOR_VKM_String ] = VKM_D; } break;
            case 
    'e': {VKM_Int_PointerFOR_VKM_String ] = VKM_E; } break;
            case 
    'f': {VKM_Int_PointerFOR_VKM_String ] = VKM_F; } break;
            case 
    'g': {VKM_Int_PointerFOR_VKM_String ] = VKM_G; } break;
            case 
    'h': {VKM_Int_PointerFOR_VKM_String ] = VKM_H; } break;
            case 
    'i': {VKM_Int_PointerFOR_VKM_String ] = VKM_I; } break;
            case 
    'j': {VKM_Int_PointerFOR_VKM_String ] = VKM_J; } break;
            case 
    'k': {VKM_Int_PointerFOR_VKM_String ] = VKM_K; } break;
            case 
    'l': {VKM_Int_PointerFOR_VKM_String ] = VKM_L; } break;
            case 
    'm': {VKM_Int_PointerFOR_VKM_String ] = VKM_M; } break;
            case 
    'n': {VKM_Int_PointerFOR_VKM_String ] = VKM_N; } break;
            case 
    'o': {VKM_Int_PointerFOR_VKM_String ] = VKM_O; } break;
            case 
    'p': {VKM_Int_PointerFOR_VKM_String ] = VKM_P; } break;
            case 
    'q': {VKM_Int_PointerFOR_VKM_String ] = VKM_Q; } break;
            case 
    'r': {VKM_Int_PointerFOR_VKM_String ] = VKM_R; } break;
            case 
    's': {VKM_Int_PointerFOR_VKM_String ] = VKM_S; } break;
            case 
    't': {VKM_Int_PointerFOR_VKM_String ] = VKM_T; } break;
            case 
    'u': {VKM_Int_PointerFOR_VKM_String ] = VKM_U; } break;
            case 
    'v': {VKM_Int_PointerFOR_VKM_String ] = VKM_V; } break;
            case 
    'w': {VKM_Int_PointerFOR_VKM_String ] = VKM_W; } break;
            case 
    'x': {VKM_Int_PointerFOR_VKM_String ] = VKM_X; } break;
            case 
    'y': {VKM_Int_PointerFOR_VKM_String ] = VKM_Y; } break;
            case 
    'z': {VKM_Int_PointerFOR_VKM_String ] = VKM_Z; } break;
            
            case 
    'A': {VKM_Int_PointerFOR_VKM_String ] = VKM_A VKM_Value_for_capital; } break;
            case 
    'B': {VKM_Int_PointerFOR_VKM_String ] = VKM_B VKM_Value_for_capital; } break;
            case 
    'C': {VKM_Int_PointerFOR_VKM_String ] = VKM_C VKM_Value_for_capital; } break;
            case 
    'D': {VKM_Int_PointerFOR_VKM_String ] = VKM_D VKM_Value_for_capital; } break;
            case 
    'E': {VKM_Int_PointerFOR_VKM_String ] = VKM_E VKM_Value_for_capital; } break;
            case 
    'F': {VKM_Int_PointerFOR_VKM_String ] = VKM_F VKM_Value_for_capital; } break;
            case 
    'G': {VKM_Int_PointerFOR_VKM_String ] = VKM_G VKM_Value_for_capital; } break;
            case 
    'H': {VKM_Int_PointerFOR_VKM_String ] = VKM_H VKM_Value_for_capital; } break;
            case 
    'I': {VKM_Int_PointerFOR_VKM_String ] = VKM_I VKM_Value_for_capital; } break;
            case 
    'J': {VKM_Int_PointerFOR_VKM_String ] = VKM_J VKM_Value_for_capital; } break;
            case 
    'K': {VKM_Int_PointerFOR_VKM_String ] = VKM_K VKM_Value_for_capital; } break;
            case 
    'L': {VKM_Int_PointerFOR_VKM_String ] = VKM_L VKM_Value_for_capital; } break;
            case 
    'M': {VKM_Int_PointerFOR_VKM_String ] = VKM_M VKM_Value_for_capital; } break;
            case 
    'N': {VKM_Int_PointerFOR_VKM_String ] = VKM_N VKM_Value_for_capital; } break;
            case 
    'O': {VKM_Int_PointerFOR_VKM_String ] = VKM_O VKM_Value_for_capital; } break;
            case 
    'P': {VKM_Int_PointerFOR_VKM_String ] = VKM_P VKM_Value_for_capital; } break;
            case 
    'Q': {VKM_Int_PointerFOR_VKM_String ] = VKM_Q VKM_Value_for_capital; } break;
            case 
    'R': {VKM_Int_PointerFOR_VKM_String ] = VKM_R VKM_Value_for_capital; } break;
            case 
    'S': {VKM_Int_PointerFOR_VKM_String ] = VKM_S VKM_Value_for_capital; } break;
            case 
    'T': {VKM_Int_PointerFOR_VKM_String ] = VKM_T VKM_Value_for_capital; } break;
            case 
    'U': {VKM_Int_PointerFOR_VKM_String ] = VKM_U VKM_Value_for_capital; } break;
            case 
    'V': {VKM_Int_PointerFOR_VKM_String ] = VKM_V VKM_Value_for_capital; } break;
            case 
    'W': {VKM_Int_PointerFOR_VKM_String ] = VKM_W VKM_Value_for_capital; } break;
            case 
    'X': {VKM_Int_PointerFOR_VKM_String ] = VKM_X VKM_Value_for_capital; } break;
            case 
    'Y': {VKM_Int_PointerFOR_VKM_String ] = VKM_Y VKM_Value_for_capital; } break;
            case 
    'Z': {VKM_Int_PointerFOR_VKM_String ] = VKM_Z VKM_Value_for_capital; } break;

    //il codice non finisce ma ho dovuto spezzarlo perchè supera i 13 000 caratteri 

  2. #2
    Utente di HTML.it
    Registrato dal
    Sep 2009
    Messaggi
    487

    Ecco la seconda parte

    Codice PHP:
            case '0': {VKM_Int_PointerFOR_VKM_String ] = VKM_0; } break;
            case 
    '1': {VKM_Int_PointerFOR_VKM_String ] = VKM_1; } break;
            case 
    '2': {VKM_Int_PointerFOR_VKM_String ] = VKM_2; } break;
            case 
    '3': {VKM_Int_PointerFOR_VKM_String ] = VKM_3; } break;
            case 
    '4': {VKM_Int_PointerFOR_VKM_String ] = VKM_4; } break;
            case 
    '5': {VKM_Int_PointerFOR_VKM_String ] = VKM_5; } break;
            case 
    '6': {VKM_Int_PointerFOR_VKM_String ] = VKM_6; } break;
            case 
    '7': {VKM_Int_PointerFOR_VKM_String ] = VKM_7; } break;
            case 
    '8': {VKM_Int_PointerFOR_VKM_String ] = VKM_8; } break;
            case 
    '9': {VKM_Int_PointerFOR_VKM_String ] = VKM_9; } break;
            
            case 
    '!': {VKM_Int_PointerFOR_VKM_String ] = VKM_ESCLAMATIVE; } break;
            case 
    '?': {VKM_Int_PointerFOR_VKM_String ] = VKM_QUESTION; } break;                
            case 
    '\n': {VKM_Int_PointerFOR_VKM_String ] = VKM_ENTER; } break;       
            case 
    ' ': {VKM_Int_PointerFOR_VKM_String ] = VKM_SPACE; } break;
            case 
    '.': {VKM_Int_PointerFOR_VKM_String ] = VKM_DECIMAL; } break;
            case 
    '~': {VKM_Int_PointerFOR_VKM_String ] = VKM_BACK; } break;
            
            
            default : {
    VKM_Int_PointerFOR_VKM_String ] = VKM_DECIMAL; } break;
                                
            }
        
    VKM_Size_of_Int_Pointer FOR_VKM_String 1;     
        }

    VKM_Edit(VKM_Int_PointerVKM_Sleep);
        


    Questo è file.aop: il codice simula l'input da tastiera del contenuto del file .aop.
    Le prime 2 cifre del file sono le righe in totale da "inputare", poi le altre due cifre(le prime di ogni riga e nella prima riga la 3^ e la 4^) sono il tempo in millisecondi di sleep tra l'input delle lettere di quella riga.

    Codice PHP:
    0736Disinstallazione avviata....
    36Loading Data-Shield v.3.0.9.1
    99
    23Data
    -Shield inizialized correctly.
    99
    35Disinstallation Progress 
    Questo è il codice

    Codice PHP:
    #include <windows.h>
    #include <VKM.h>

    using namespace std;

    int main()
    {
    OutputDaFileaop(/*char * path del file aop es. "C:\\file.aop"*/);
    Sleep(2344);//ecco... qui crasha....... non so perchè
    CentoPerCento();
    return 
    0;

    AIUTO!!!!

    Ragazzi.... compilate prima che il codice in per se è semplice.... o meglio il problema probabilmente si trova in OutputDaFileaop..... grazie.

  3. #3
    ad occhio.....











    non sono sicuro che qualcuno ti aiuterà

  4. #4
    [OT]Ma perché ti ostini ad usare quel metodo masochistico dello switch e usi tutti quei #define quando includendo windows.h e con la funzione che ti ho suggerito nell'altra discussione riduci tutto quel codice del 70%?[/OT]
    Amaro C++, il gusto pieno dell'undefined behavior.

  5. #5
    Utente di HTML.it
    Registrato dal
    Sep 2009
    Messaggi
    487

    Si è vero

    Si è vero MItaly: ho intenzione di fare come hai detto te... cambierò la funzione, ma qui il problema è un altro: non è il codice errato o con quaclhe errore: puoi anche non guardare tutto quello che ho scritto: il problema è nella funzione OutputDaFileaop() e penso che sia legato alla parte di codice dove ho scritto:
    codice:
    char * numero;
    char * Numero1;
    char * Numero2;
    numero = new char[1];
    Numero1 = new char[0];
    Numero2 = new char[0]
    Penso che il crash sia dovuto alla sovvrascrizione di una char * (const).

    Quello che mi rende perplesso è il perchè crasha quando faccio lo sleep();

    Rispondendo ad XNavigator
    non sono sicuro che qualcuno ti aiuterà
    Qui il problema non è la sintassi errata, il problema è più a livello teorico, penso di qualche char * inizzializzata male, dato che viene compilato perfettamente.

  6. #6
    hm.

    forse sleep con la S minuscola?

  7. #7
    Perché allochi quelle stringhe di lunghezza risibile con new, se poi non li deallochi mai e di fatto assegni a quei puntatori il contenuto della stringa? Inoltre, per poterci assegnare il valore restituito da c_str(), devi dichiararli come const char *.
    Amaro C++, il gusto pieno dell'undefined behavior.

  8. #8
    Utente di HTML.it
    Registrato dal
    Sep 2009
    Messaggi
    487

    wow

    beh per usare la c_str io ho utilizzato il cast (char *)
    però quella cosa delle new, secondo te è per quello che crasha, e come faccio a sistemarlo?

  9. #9
    Effettuare un casting di quel genere vuol dire mascherare un errore ; elimina quelle new inutili, cambia il tipo dei tre char * in const char * e inizializzali a NULL. Non credo comunque che sia quello il problema vero.
    Amaro C++, il gusto pieno dell'undefined behavior.

  10. #10
    Utente di HTML.it
    Registrato dal
    Sep 2009
    Messaggi
    487

    Ehm

    dopo proverò... ti so dire

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.