Torna indietro   Hardware Upgrade Forum > Software > Programmazione

Cineca inaugura Pitagora, il supercomputer Lenovo per la ricerca sulla fusione nucleare
Cineca inaugura Pitagora, il supercomputer Lenovo per la ricerca sulla fusione nucleare
Realizzato da Lenovo e installato presso il Cineca di Casalecchio di Reno, Pitagora offre circa 44 PFlop/s di potenza di calcolo ed è dedicato alla simulazione della fisica del plasma e allo studio dei materiali avanzati per la fusione, integrandosi nell’ecosistema del Tecnopolo di Bologna come infrastruttura strategica finanziata da EUROfusion e gestita in collaborazione con ENEA
Mova Z60 Ultra Roller Complete: pulisce bene grazie anche all'IA
Mova Z60 Ultra Roller Complete: pulisce bene grazie anche all'IA
Rullo di lavaggio dei pavimenti abbinato a un potente motore da 28.000 Pa e a bracci esterni che si estendono: queste, e molte altre, le caratteristiche tecniche di Z60 Ultra Roller Complete, l'ultimo robot di Mova che pulisce secondo le nostre preferenze oppure lasciando far tutto alla ricca logica di intelligenza artificiale integrata
Renault Twingo E-Tech Electric: che prezzo!
Renault Twingo E-Tech Electric: che prezzo!
Renault annuncia la nuova vettura compatta del segmento A, che strizza l'occhio alla tradizione del modello abbinandovi una motorizzazione completamente elettrica e caratteristiche ideali per i tragitti urbani. Renault Twingo E-Tech Electric punta su abitabilità, per una lunghezza di meno di 3,8 metri, abbinata a un prezzo di lancio senza incentivi di 20.000€
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


Cineca inaugura Pitagora, il supercomputer Lenovo per la ricerca sulla fusione nucleare Cineca inaugura Pitagora, il supercomputer Lenov...
Mova Z60 Ultra Roller Complete: pulisce bene grazie anche all'IA Mova Z60 Ultra Roller Complete: pulisce bene gra...
Renault Twingo E-Tech Electric: che prezzo! Renault Twingo E-Tech Electric: che prezzo!
Il cuore digitale di F1 a Biggin Hill: l'infrastruttura Lenovo dietro la produzione media Il cuore digitale di F1 a Biggin Hill: l'infrast...
DJI Osmo Mobile 8: lo stabilizzatore per smartphone con tracking multiplo e asta telescopica DJI Osmo Mobile 8: lo stabilizzatore per smartph...
Lo compri una volta, lo giochi dove vuoi...
Qiantinuum annuncia Helios, "il com...
Samsung Galaxy S26 Ultra: una sola novit...
Google prepara Gemini 3 Pro e Nano Banan...
TVS non è solo moto e scooter: ec...
Alexa+ arriva su BMW: gli automobilisti ...
Gemini Deep Research arriva su Google Fi...
Rinvii a catena, Marvel 1943: Rise of Hy...
Xiaomi inaugura uno spazio dedicato ai f...
Rilasciate le specifiche di Bluetooth 6....
L'obiettivo che mette tutto a fuoco: la ...
Meta avrebbe raccolto fino al 10% dei ri...
NVIDIA DGX Spark e videogiochi? Una pess...
Serie Oppo Reno15 confermata: arriva il ...
UPDF 2025: l'editor PDF che fa (quasi) t...
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: 07:12.


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