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?!