Torna indietro   Hardware Upgrade Forum > Software > Programmazione

Recensione HUAWEI Mate X7: un foldable ottimo, ma restano i soliti problemi
Recensione HUAWEI Mate X7: un foldable ottimo, ma restano i soliti problemi
Mate X7 rinnova la sfida nel segmento dei pieghevoli premium puntando su un design ancora più sottile e resistente, unito al ritorno dei processori proprietari della serie Kirin. L'assenza dei servizi Google e del 5G pesa ancora sull'esperienza utente, ma il comparto fotografico e la qualità costruttiva cercano di compensare queste mancanze strutturali con soluzioni ingegneristiche di altissimo livello
Nioh 3: souls-like punitivo e Action RPG
Nioh 3: souls-like punitivo e Action RPG
Nioh 3 aggiorna la formula Team NINJA con aree esplorabili più grandi, due stili di combattimento intercambiabili al volo (Samurai e Ninja) e un sistema di progressione pieno di attività, basi nemiche e sfide legate al Crogiolo. La recensione entra nel dettaglio su combattimento, build, progressione e requisiti PC
Test in super anteprima di Navimow i220 LiDAR: il robot tagliaerba per tutti
Test in super anteprima di Navimow i220 LiDAR: il robot tagliaerba per tutti
La facilità di installazione e la completa automazione di tutte le fasi di utilizzo, rendono questo prodotto l'ideale per molti clienti. Ecco com'è andata la nostra prova in anteprima
Tutti gli articoli Tutte le news

Vai al Forum
Rispondi
 
Strumenti
Old 22-11-2010, 08: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


Recensione HUAWEI Mate X7: un foldable ottimo, ma restano i soliti problemi Recensione HUAWEI Mate X7: un foldable ottimo, m...
Nioh 3: souls-like punitivo e Action RPG Nioh 3: souls-like punitivo e Action RPG
Test in super anteprima di Navimow i220 LiDAR: il robot tagliaerba per tutti Test in super anteprima di Navimow i220 LiDAR: i...
Dark Perk Ergo e Sym provati tra wireless, software via browser e peso ridotto Dark Perk Ergo e Sym provati tra wireless, softw...
DJI RS 5: stabilizzazione e tracking intelligente per ogni videomaker DJI RS 5: stabilizzazione e tracking intelligent...
Qualcomm potrebbe utilizzare una tecnolo...
Starfield per Nintendo Switch 2 potrebbe...
Un MacBook Pro a -300€, i MacBook Air M4...
Amazon abbassa i prezzi sugli iPhone: sc...
Amazon, ancora sconti sugli smartphone A...
iPhone Air 2 'riciclerà' alcuni c...
Offerta Amazon da non perdere: lo speake...
Nioh 3 debutta alla grande su Steam: pri...
Al centro della Via Lattea ci potrebbe e...
Elon Musk ora guarda alla Luna: SpaceX p...
La Cina ha lanciato nuovamente lo spazio...
Blue Origin potrebbe realizzare il lande...
Artemis II: il prossimo Wet Dress Rehear...
Il nuovo HONOR 600 sta arrivando e avr&a...
La crisi delle memorie non coinvolger&ag...
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: 11:48.


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