Question : printing a file given the path in windows API

Hey all I am trying to print off a document but I am receiving an error when i use the ADDJOB function

heres my code,what am i doing wrong?
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
int main(int argc, char **argv)
{ 
	char *filename=argv[1];				//printer namer
	char *pPrinter="mono_simplex_a4";				//printer namer 
	int iIndex = 0;
	DWORD dwNeeded, dwRet, dwPrinterStatus;
	ADDJOB_INFO_1* pJob = NULL;
	HANDLE hPrinter=NULL; 
	
	HANDLE hWait;
	JOB_INFO_2  *pJobs=NULL; 
	int iJobs, iTempIndex;
	int jobid=4;
	int c;
	
	 
	PRINTER_DEFAULTS pd;
	pd.pDatatype = NULL;
	pd.pDevMode = NULL;
	pd.DesiredAccess = PRINTER_ALL_ACCESS; 

	if(!OpenPrinter(pPrinter,&hPrinter,&pd)) 
	{
		DisplayError("OpenPrinter Failed");
		return FALSE;
	}
	 
	GetJobs(hPrinter,       
		&pJobs, /* Pointer to be filled.  */ 
		&iJobs,            /* Count of jobs filled.  */ 
	
		&dwPrinterStatus);         /* Print Queue status.    */  
 
	
	pJob[0].Path="@c:\test\config.txt\n"; 
	AddJob(hPrinter,1,(LPBYTE) pJob,0,&dwNeeded); 
	
	
	return (0);
}

Answer : printing a file given the path in windows API

hmm one second .... Here's some bit of code I used in the specified guerilla project.

        /// numele fisierului
        public static void ConvertPdfToTiff(string Filen)
        {
            //try
            //{
            //    StringCollection printers = GetPrintersCollection();
            //    if (printers.IndexOf("ELOPrinter") == -1)
            //    {
            //        MessageBox.Show("Instalati ELOPrinter si restartati aplicatia");
            //        return;
            //    }
            //}
            //catch
            //{
               
            //}
            System.Diagnostics.Process P = new System.Diagnostics.Process();
            P.StartInfo.FileName = Filen.ToString();
            P.StartInfo.CreateNoWindow = true;
            P.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            P.StartInfo.Verb = "print";
            P.Start();
            P.Dispose();
            bool jobExistent = false;
            while (!jobExistent)
            {
                StringCollection jobs = GetPrintJobsCollection("ELOPrinter");
                if (jobs.Count == 1) jobExistent = true;
            }
            jobExistent = true;
            while (jobExistent)
            {
                StringCollection jobs = GetPrintJobsCollection("ELOPrinter");
                if (jobs.Count == 0) jobExistent = false;
            }

            System.Diagnostics.Process[] myProcesses;
            myProcesses = System.Diagnostics.Process.GetProcessesByName("AcroRd32");
            foreach (System.Diagnostics.Process myProcess in myProcesses)
            {
                myProcess.Kill();
            }
        }


        ///
        /// Aceasta Metoda returneaza lista imprimantelor instalate
        ///

        /// lista imprimantelor instalate
        private static StringCollection GetPrintersCollection()
        {
            StringCollection printerNameCollection = new StringCollection();
            string searchQuery = "SELECT * FROM Win32_Printer";
            ManagementObjectSearcher searchPrinters =
                  new ManagementObjectSearcher(searchQuery);
            ManagementObjectCollection printerCollection = searchPrinters.Get();
            foreach (ManagementObject printer in printerCollection)
            {
                printerNameCollection.Add(printer.Properties["Name"].Value.ToString());
            }
            return printerNameCollection;
        }

        ///
        /// Aceasta metoda returneaza lista job-urilor curente ale unei imprimante
        ///

        /// numele imprimantei
        /// lista job-urilor
        private static StringCollection GetPrintJobsCollection(string printerName)
        {
            StringCollection printJobCollection = new StringCollection();
            string searchQuery = "SELECT * FROM Win32_PrintJob";
            ManagementObjectSearcher searchPrintJobs =
                      new ManagementObjectSearcher(searchQuery);
            ManagementObjectCollection prntJobCollection = searchPrintJobs.Get();
            foreach (ManagementObject prntJob in prntJobCollection)
            {
                System.String jobName = prntJob.Properties["Name"].Value.ToString();
                char[] splitArr = new char[1];
                splitArr[0] = Convert.ToChar(",");
                string prnterName = jobName.Split(splitArr)[0];
                string documentName = prntJob.Properties["Document"].Value.ToString();
                if (String.Compare(prnterName, printerName, true) == 0)
                {
                    printJobCollection.Add(documentName);
                }
            }
            return printJobCollection;
        }
Random Solutions  
 
programming4us programming4us