|
It's likely that 'Mystical Powers' own your PC, now.
On the Serious Side of the Moon:
- Check very well if the actual file name matches the file name the compiler complains about.
- Check very well if the folder you entered in VC++ (Include) Directories matches with the one inside your hard disk.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
modified on Tuesday, July 6, 2010 4:33 AM
|
|
|
|
|
Are you sure you actually have that file on your system? Note: i'm not asking if you have installed WDK or not, i am asking if you have the file on your hdd somewhere.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> "It doesn't work, fix it" does not qualify as a bug report. <
> Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <
|
|
|
|
|
yes i have that file on my hdd
|
|
|
|
|
And you say you added the folder that contains the header file to the "additional include directories" in your project settings? Is it possible that you e.g. added it to your release configuration but trying to build debug? You need to add the folder to every configuration you actually want to use it in (unless this has changed since VS2003).
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> "It doesn't work, fix it" does not qualify as a bug report. <
> Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <
|
|
|
|
|
now i have added 3 file hidpi.h, hidsdi.h and hidusage.h to my project folder. Now its giving error:- cannot open file 'hid.lib'
I have given hid.lib in my input section of Linker option
|
|
|
|
|
Someone has already mentioned that you need to add the directories for the include files to your project. It should not come as a surprise to you that you will also need to add the location of your lib files to the linker section.
It's time for a new signature.
|
|
|
|
|
Richard MacCutchan wrote: It should not come as a surprise...
Apparently it does.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
I have this rather naive hope sometimes that people will learn the basics of putting an application together before they start coding. Or more likely, copying and pasting others' code.
It's time for a new signature.
|
|
|
|
|
Hi All,
I am new to this C++ language. I have done the program for writing the documents to printer using Window's API. And it worked perfectly. But when I tried to delete the same document from the printer using DeletePrinter or ResetPrinter API's, it doesn't work.So I need a function body to delete the document from the printer. Can anybody please help me.?
Thanks in advance....
|
|
|
|
|
Try the SetPrinter API with the PRINTER_CONTROL_PURGE flag.
|
|
|
|
|
Hi Santosh,
Thank you so much for your reply. Even I tried using SetPrinter API with the related parameters.It doesn't worked. "SetPrinter(hPrinter,0,0,PRINTER_CONTROL_PURGE);"..This is what I have used in my program. Is it correct..?
|
|
|
|
|
That is perfect.
I have used it and it worked for me.
You must have administrative privileges to use this API.
Maybe that is where the problem is.
|
|
|
|
|
Hi Santosh,
I don't think so that I got some restriction on these API's. Well, is it a OS dependent.?
|
|
|
|
|
If you're running on Vista or higher, try right clicking on the EXE and select Run as administrator .
|
|
|
|
|
Hi Santosh,
I am using windows XP. IF its working fine in your machine and not in mine means there may be some mistake in my program. So I have attached the code below. I have used "Borland C++ builder" for this program. Can you have a look at it.? Let me know if there is any mistake....
#include <vcl.h>
#include <windows.h>
#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
#include <winspool.h>void thebuffer(HANDLE hPrinter)
{
FILE * pFile;
long lSize;
char * buffer;
DWORD dwBytesWritten = 0;
size_t result;
LPPRINTER_DEFAULTS pDefault;
LPPRINTER_DEFAULTS DesiredAccess;
pFile = fopen ( "reafile.txt" , "rb" );
buffer = (char*) malloc (lSize);
WritePrinter(hPrinter,buffer,lSize,&dwBytesWritten);
fclose (pFile);
free (buffer);
EndPagePrinter( hPrinter );
EndDocPrinter( hPrinter );
ClosePrinter( hPrinter );
return ;
}
void dbmain()
{
HANDLE hPrinter;
char name[256]="Canon MF4320-4350";
OpenPrinter(name, &hPrinter,0);
DWORD x;
DOC_INFO_1 DocInfo;
DocInfo.pDocName="reafile.txt";
DocInfo.pOutputFile=NULL;
DocInfo.pDatatype="RAW";
x=StartDocPrinter(hPrinter,1,(LPBYTE)&DocInfo);
cout<<"JobID: "<<x<<endl;
BOOL z=StartPagePrinter(hPrinter);
if(!z)
{
cout<<"it succeds"<<endl;
}
else{}
thebuffer(hPrinter);
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
dbmain();
ShowMessage("Data is sent to printer");
exit( 0);
}
void __fastcall TForm1::Button2Click(TObject *Sender)
{
HANDLE hPrinter;
char name[256]="Canon MF4320-4350";
OpenPrinter(name, &hPrinter,0);
SetPrinter(hPrinter,0,NULL,PRINTER_CONTROL_PURGE);
ShowMessage("Reset is done");
ClosePrinter( hPrinter );
exit( 0);
}
|
|
|
|
|
Put in some error checking.
Check return values of APIs.
This will help you identify where exactly it fails.
|
|
|
|
|
Hi Santosh,
Ok,, let me do that.. Did you find any mistake in the code..?
|
|
|
|
|
Hi Santosh
I tried with all the possibilities. Its working fine for everything. But SetPrinter API is not functioning properly though it compiles without any error or warning. I am confused.....
|
|
|
|
|
Please reread the replies you've already got.
So, the function didn;t do what you want.
Did it return any status?
Did GetLastError give you any useful error codes?
Win32 is hard sometimes, but it does give clues when it doesn't "work".
Iain.
I am one of "those foreigners coming over here and stealing our jobs". Yay me!
|
|
|
|
|
Hi Iain Clarke,
I didn't get any error codes though I used GetLastError. It is compiling fine,but the API is not working properly..
|
|
|
|
|
Hi Iain Clarke,
I tried with GetLastError. In response it gave me the number 6. This invalid Error handler, right..? So this means is there any wrong in Handler which I used.?
|
|
|
|
|
Hi Santosh,
I tried with GetLastError. In response it gave me the number 6. This invalid Error handler, right..? So this means is there any wrong in Handler which I used.?
|
|
|
|
|
I believe the parameter you're passing to OpenPrinter is wrong and so you're getting an invalid handle.
See the documentation of OpenPrinter for the syntax of the printer name to pass.
|
|
|
|
|
Hi Superman,
When you asked me to change some part in the code it gave lot of runtime exception. And I couldn't solve it, so without any option I changed my code. This code is not giving any kind of exception when I tried to compile and it is printing fine. But if I try to delete the job its not doing that. To find that I tried to trace out the error using GetLastError(). It is giving 6. If am not wrong that means handler is invalid or might have closed. But till my knowledge is concerned am doing all the operations before I close the handler. And I don't think it is invalid since I used the same handler to print the job and it is working fine. So thats why I attached entire code here so that you can find the things easily. Speaking about the program, I used Borland C++ builder to build the project where I have used two Buttons in the GUI part. One to print and other is to delete the job. Sorry for taking much of your time but I need this program badly. Please help me........
#include <windows.h>
#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
#include <winspool.h>
#include <vcl.h>
#pragma hdrstop
#include "reset.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
void prinfun(bool val)
{
HANDLE hPrinter = 0;
DWORD dwBytesWritten=0;
string strDocName;
DWORD dwFileLength = 0;
char szData[512];
DWORD dwBufsize=0;
strcpy(szData,"reafile.txt");
OpenPrinter("Canon MF4320-4350", &hPrinter, NULL);
DOC_INFO_1 DocInfo;
DocInfo.pDocName = "reafile.txt";
DocInfo.pOutputFile = NULL;
DocInfo.pDatatype = _T("RAW");
StartDocPrinter(hPrinter, 1, (LPBYTE)&DocInfo);
StartPagePrinter(hPrinter);
if(val == 0)
{
WritePrinter(hPrinter, (void*)szData, strlen(szData) , &dwBytesWritten);
}
else if(val == 1)
{
GetPrinter(hPrinter, 2, NULL, 0, &dwBufsize);
SetPrinter(hPrinter, 0, NULL, PRINTER_CONTROL_PURGE);
}
free(hPrinter);
EndPagePrinter(hPrinter);
EndDocPrinter(hPrinter);
ClosePrinter(hPrinter);
}
void __fastcall TForm1::printButton1Click(TObject *Sender)
{
int temp = GetLastError();
char buf[300];
prinfun(0);
ShowMessage("Everything is done successfully");
sprintf(buf,"%d",temp);
Form1->RichEdit1->Lines->Add(buf);
}
void __fastcall TForm1::deleteButton2Click(TObject *Sender)
{
int temp = GetLastError();
char buf[300];
prinfun(1);
ShowMessage(" printer jobs deleted");
sprintf(buf,"%d",temp);
Form1->RichEdit1->Lines->Add(buf);
}
|
|
|
|
|
Hi Superman,
Please do reply.. Am in very much need of your help. Please help me..........
|
|
|
|