Torna indietro   Hardware Upgrade Forum > Software > Programmazione

Marvel's Wolverine, la recensione: Logan torna protagonista in un'avventura brutale e intensa
Marvel's Wolverine, la recensione: Logan torna protagonista in un'avventura brutale e intensa
Marvel's Wolverine porta Logan in un'avventura inedita, violenta e fortemente narrativa, costruita attorno alla sua natura di combattente e al difficile rapporto con il proprio passato. Insomniac Games punta su combattimenti spettacolari, progressione e personalizzazione, inserendo l'azione in un mondo segnato dalla persecuzione dei mutanti. Un viaggio intenso, che alterna mattanza, esplorazione e momenti sorprendentemente emotivi.
DJI Romo 2: tante novità lo rendono un robot completo
DJI Romo 2: tante novità lo rendono un robot completo
Romo 2 è la seconda generazione di robot lavapavimenti di DJI, un modello che si caratterizza per la precisione nel sistema di navigazione e per il funzionamento particolarmente silenzioso. Con le modifiche introdotte in questa seconda versione, e un posizionamento di prezzo più allineato alla concorrenza, rappresenta una valida alternativa sul mercato delle soluzioni di pulizia domestica
Sony Bravia 9 II: il True RGB alla prova, dove l'LCD sfida l'OLED
Sony Bravia 9 II: il True RGB alla prova, dove l'LCD sfida l'OLED
Il primo Sony con retroilluminazione True RGB alla prova del banco di misura e dei contenuti: luminanza enorme, colori accurati in HDR e un antiriflesso molto efficace. I limiti sono due sole HDMI 2.1 e il blooming fuori asse
Tutti gli articoli Tutte le news

Vai al Forum
Rispondi
 
Strumenti
Old 22-11-2010, 07:12   #1
Sbrocca88
Member
 
Iscritto dal: Nov 2010
Messaggi: 30
[C++] Creazione mia libreria

Ciao a tutti.
Io ho creato una libreria chiamata mialib.h dove ho messo tutte le mie funzioni con i relativi codici.
Eccola:

Codice:
#include <iostream>
#include <stdlib.h>     //Necessaria per utilizzare system
#include <fstream>      // Necessaria per utilizzare apertura e scrittura dei file 
#include <windows.h>   // Necessario per createprocess() e createpipe()
//#include <cstring>
#include <direct.h>    //Necessaria per usare chdir
#define BUFSIZE 4096
#define MAX 50
#define lung 100
HANDLE g_hChildStd_IN_Rd = NULL;
HANDLE g_hChildStd_IN_Wr = NULL;
HANDLE g_hChildStd_OUT_Rd = NULL;
HANDLE g_hChildStd_OUT_Wr = NULL;
void nuovoprofilo(); 
void CreateChildProcess(void); 
void WriteToPipe(void); 
void ReadFromPipe(void); 
int AggiustaCaratteri(char buf[], int length);
char nome_cognome[MAX], nome_file[lung][lung],a,codetrain[lung][lung];
int i=0;

void nuovoprofilo()
{
TCHAR *argv[MAX];
ofstream fout("C:\\cygwin\\home\\DATABASE.txt", ios::app);

for (int i=0; i<strlen(nome_cognome); i++)
{
fout << nome_cognome[i];
}
fout << endl;
fout.close();
chdir("C:\\cygwin\\home\\Profiles");
chdir(nome_cognome);
CopyFile("C:\\cygwin\\home\\Ciucci\\voxforge_2\\auto\\codetrain.scp","codetrain.scp",TRUE);
chdir("C:\\cygwin\\home\\Profiles");
chdir(nome_cognome);
ifstream fin("codetrain.scp");
int j=0;
while(fin.good())
                 {
                 fin.getline(codetrain[j],lung);
                 j++;
                 }
fin.close();
chdir("C:\\cygwin\\home\\Profiles");
chdir(nome_cognome);
MoveFileEx("C:\\cygwin\\home\\Ciucci\\voxforge_2\\auto\\scripts","scripts",TRUE);
chdir("C:\\cygwin\\home\\Profiles");
chdir(nome_cognome);
ofstream fout2("codetrain.scp");
for(int i=1; i<45; i++)
        {
        fout2 << "../../Profiles/" << nome_cognome << "/wav/sample" <<i <<".wav" << " ../../Profiles/"<< nome_cognome << "/mfcc/sample" << i << ".mfc" << endl;  
        }
                 //cartelle con nome profilo
cout << "Registrare i dati leggendo il contenuto del file prompts e salvarli come file wav in C:\\cygwin\\home\\Profiles\\[nome cognome]\\wav Successivamente premere un tasto per continuare" << endl;
PROCESS_INFORMATION piProcInfo; 
STARTUPINFO siStartInfo;
BOOL bSuccess = FALSE; 
 
// Set up members of the PROCESS_INFORMATION structure. 
 
ZeroMemory( &piProcInfo, sizeof(PROCESS_INFORMATION) );
 
// Set up members of the STARTUPINFO structure. 
// This structure specifies the STDIN and STDOUT handles for redirection.
 
ZeroMemory( &siStartInfo, sizeof(STARTUPINFO) );
siStartInfo.cb = sizeof(STARTUPINFO); 
siStartInfo.hStdError = g_hChildStd_OUT_Wr;
siStartInfo.hStdOutput = g_hChildStd_OUT_Wr;
siStartInfo.hStdInput = g_hChildStd_IN_Rd;
siStartInfo.dwFlags |= STARTF_USESTDHANDLES;
 
 // Create the child process. 
    
bSuccess = CreateProcess("C:\\Program Files\\Audacity\\audacity.exe", 
NULL, //"C:\\WINDOWS\\system32\\cmd.exe",    // command line 
NULL,          // process security attributes 
NULL,          // primary thread security attributes 
TRUE,          // handles are inherited 
0,             // creation flags 
NULL,          // use parent's environment 
NULL,          // use parent's current directory 
&siStartInfo,  // STARTUPINFO pointer 
&piProcInfo);  // receives PROCESS_INFORMATION 
system("PAUSE");
cout<<"DEBUG: creo le cartelle utili"<<endl;

                 //system("\"mkdir C:\\cygwin\\home\\Ciucci\\voxforge_2\"");            
                 //system("\"mkdir C:\\cygwin\\home\\Ciucci\\voxforge_2\\HTK_Scripts\"");                                  
                 //system("\"xcopy C:\\cygwin\\home\\Ciucci\\voxforge\\HTK_Scripts C:\\cygwin\\home\\Ciucci\\voxforge_2\\HTK_Scripts\""); 
                 //system("\"mkdir C:\\cygwin\\home\\Ciucci\\voxforge_2\\auto\"");
                 // Registrare voce e verificare se il profilo è già presente   
SECURITY_ATTRIBUTES saAttr; 
printf("\n->Start of parent execution.\n");

                 // Set the bInheritHandle flag so pipe handles are inherited. 
 
saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); 
saAttr.bInheritHandle = TRUE; 
saAttr.lpSecurityDescriptor = NULL; 

                 // Create a pipe for the child process's STDOUT. 
 
if ( ! CreatePipe(&g_hChildStd_OUT_Rd, &g_hChildStd_OUT_Wr, &saAttr, 0) ) {
cout<<"error: Create process\n"; 
return;}

                 // Ensure the read handle to the pipe for STDOUT is not inherited.

if ( ! SetHandleInformation(g_hChildStd_OUT_Rd, HANDLE_FLAG_INHERIT, 0) ){
cout<<"error: Create process\n"; 
return;}

                 // Create a pipe for the child process's STDIN. 
 
if (! CreatePipe(&g_hChildStd_IN_Rd, &g_hChildStd_IN_Wr, &saAttr, 0)) {
cout<<"error: Create pipe\n"; 
return;}

                 // Ensure the write handle to the pipe for STDIN is not inherited. 
 
if ( ! SetHandleInformation(g_hChildStd_IN_Wr, HANDLE_FLAG_INHERIT, 0) ){
cout<<"error: set handle info\n"; 
return;
}
 
                 // Create the child process. 
CreateChildProcess();

                 // Write to the pipe that is the standard input for a child process. 
                 // Data is written to the pipe's buffers, so it is not necessary to wait
                 // until the child process is running before writing data.
 
WriteToPipe(); 
printf( "\n->Contents of %s written to child STDIN pipe.\n", argv[1]);
 
                 // Read from pipe that is the standard output for child process. 
 
printf( "\n->Contents of child process STDOUT:\n\n", argv[1]);
ReadFromPipe(); 

printf("\n->End of parent execution.\n");

}
void CreateChildProcess()
// Create a child process that uses the previously created pipes for STDIN and STDOUT.
{ 
   PROCESS_INFORMATION piProcInfo; 
   STARTUPINFO siStartInfo;
   BOOL bSuccess = FALSE; 
 
// Set up members of the PROCESS_INFORMATION structure. 
 
   ZeroMemory( &piProcInfo, sizeof(PROCESS_INFORMATION) );
 
// Set up members of the STARTUPINFO structure. 
// This structure specifies the STDIN and STDOUT handles for redirection.
 
   ZeroMemory( &siStartInfo, sizeof(STARTUPINFO) );
   siStartInfo.cb = sizeof(STARTUPINFO); 
   siStartInfo.hStdError = g_hChildStd_OUT_Wr;
   siStartInfo.hStdOutput = g_hChildStd_OUT_Wr;
   siStartInfo.hStdInput = g_hChildStd_IN_Rd;
   siStartInfo.dwFlags |= STARTF_USESTDHANDLES;
 
// Create the child process. 
    
   bSuccess = CreateProcess("C:\\cygwin\\Cygwin.bat", 
      NULL, //"C:\\WINDOWS\\system32\\cmd.exe",    // command line 
      NULL,          // process security attributes 
      NULL,          // primary thread security attributes 
      TRUE,          // handles are inherited 
      0,             // creation flags 
      NULL,          // use parent's environment 
      NULL,          // use parent's current directory 
      &siStartInfo,  // STARTUPINFO pointer 
      &piProcInfo);  // receives PROCESS_INFORMATION 
   
   // If an error occurs, exit the application. 
   if ( ! bSuccess ){
       cout<<"error: Create process\n"; 
      return ;
      }
   else 
   {
      // Close handles to the child process and its primary thread.
	  // Some applications might keep these handles to monitor the status
	  // of the child process, for example. 

      //CloseHandle(piProcInfo.hProcess);
      //CloseHandle(piProcInfo.hThread);
   }
}
 
void WriteToPipe(void) 

// Write to the pipe for the child's STDIN. 
{ 
   DWORD dwRead, dwWritten; 
   CHAR chBuf[]="cd voxforge_2\rcd auto\rdos2unix *.*\rmkdfa.pl ita\rtar -xf scripts.gz"/*"export PS1=""\rls"*/;
   BOOL bSuccess = FALSE;
     
   bSuccess = WriteFile(g_hChildStd_IN_Wr, chBuf, sizeof(chBuf), &dwWritten, NULL);
// Close the pipe handle so the child process stops reading. 
 
   if ( ! CloseHandle(g_hChildStd_IN_Wr) ){
       cout<<"error: Close handle\n"; 
      return; 
} 
}
void ReadFromPipe(void) 

// Read output from the child process's pipe for STDOUT
// and write to the parent process's pipe for STDOUT. 
// Stop when there is no more data. 
{ 
   DWORD dwRead, dwWritten; 
   char chBuf[BUFSIZE]; 
   BOOL bSuccess = FALSE;
   HANDLE hParentStdOut = GetStdHandle(STD_OUTPUT_HANDLE);

// Close the write end of the pipe before reading from the 
// read end of the pipe, to control child process execution.
// The pipe is assumed to have enough buffer space to hold the
// data the child process has already written to it.
 
   if (!CloseHandle(g_hChildStd_OUT_Wr)){
       cout<<"error: Close childstdout handle\n"; 
      return; 
}
   for (; 
   { 
      bSuccess = ReadFile( g_hChildStd_OUT_Rd, chBuf, BUFSIZE, &dwRead, NULL);
      if( ! bSuccess || dwRead == 0 ) break; 
      
      //bSuccess = WriteFile(hParentStdOut, chBuf, dwRead, &dwWritten, NULL);
      //if (! bSuccess ) break; 
      //chBuf è più lungo e contiene anche caratteri non stampabili. Perchè?
      int l=0;
      l=AggiustaCaratteri(chBuf, dwRead);
      cout<<chBuf; 
      
   } 
} 
 
int AggiustaCaratteri(char buf[], int length){

char temp[length];
int j=0;

for(int i=0; i<length; i++)
{
 
 if ((buf[i]<14 && buf[i]>7) || buf[i]>31)
 {
  temp[j]=buf[i];
  j++;
 }
}
strcpy(buf,temp);
return j;
}
L'ho messa nella cartella C:\Dev-Cpp\include
Quando chiamo la mia libreria nel mio codice, mettendo all'inizio #include <mialib.h>
Mi da una sfilza di errori.
Dove sbaglio?!
Sbrocca88 è offline   Rispondi citando il messaggio o parte di esso
 Rispondi


Marvel's Wolverine, la recensione: Logan torna protagonista in un'avventura brutale e intensa Marvel's Wolverine, la recensione: Logan torna p...
DJI Romo 2: tante novità lo rendono un robot completo DJI Romo 2: tante novità lo rendono un ro...
Sony Bravia 9 II: il True RGB alla prova, dove l'LCD sfida l'OLED Sony Bravia 9 II: il True RGB alla prova, dove l...
Geely EX5, un mese al volante: il SUV elettrico cinese che ci ha sorpreso (quasi) senza riserve Geely EX5, un mese al volante: il SUV elettrico ...
Mova Z70 Ultra Roller Complete: motore potente, rullo di lavaggio e l'IA a guidare Mova Z70 Ultra Roller Complete: motore potente, ...
Airbus realizzerà altri 229 satel...
Arianespace lancerà altri satelli...
Eutelsat ha annunciato di aver affidato ...
PLD Space ha annunciato il nuovo razzo s...
CMF Clip Pro, tanta autonomia e design u...
Tre leggende del rally sbarcano in Asset...
iPhone 18 Pro Max, il chip A20 Pro mostr...
Samsung porterà il Privacy Displa...
WINDTRE BUSINESS trasforma la rete mobil...
Anthropic ammette un quarto caso di acce...
Mazda CX-6e, il primo test drive: quando...
La serie HONOR Magic 9 arriva a fine set...
Anker MagGo Power Bank 2 Pro arriva in I...
iRobot rilancia con Roomba Duo, il proto...
#linux su IRC è tornato dopo anni di sil...
Chromium
GPU-Z
OCCT
LibreOffice Portable
Opera One Portable
Opera One 106
CCleaner Portable
CCleaner Standard
Cpu-Z
Driver NVIDIA GeForce 546.65 WHQL
SmartFTP
Trillian
Google Chrome Portable
Google Chrome 120
VirtualBox
Tutti gli articoli Tutte le news Tutti i download

Strumenti

Regole
Non Puoi aprire nuove discussioni
Non Puoi rispondere ai messaggi
Non Puoi allegare file
Non Puoi modificare i tuoi messaggi

Il codice vB è On
Le Faccine sono On
Il codice [IMG] è On
Il codice HTML è Off
Vai al Forum


Tutti gli orari sono GMT +1. Ora sono le: 00:17.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Served by www3v