We have something like Secure Print.
I go to my control panel >> Printers and Devices >> Printer >> Printer Preference
Here i assign a 4 digit pin code ..
I fire a print from Word or Excel ... go to the printer >> retrieve jobs >> select my print job and enter my pin code.
Only then my job gets printed.
Now Our application has two source codes for printing
While firing print from our Application the print is instantaneously done .... I.e. it doesn't store my job in the queue and wait for pin ... but just prints immediately
Some source code
bResult = OpenPrinter(szDevice, &hPrinter, NULL);
// szDevice contains printer name
startDocPrtInfo.pDocName = msg;
startDocPrtInfo.pOutputFile = NULL;
startDocPrtInfo.pDatatype = "RAW";
bPrntErr = (StartDocPrinter(hPrinter,1,(LPBYTE)&startDocPrtInfo) == 0);
WritePrinter(hPrinter, &buffer[2], i, &cnt);
EndDocPrinter(hPrinter);
ClosePrinter(hPrinter);
~~~~~
The Code is printing the given document however its not waiting for user to enter his pin code
QUESTION
How to make the above code wait just like its doing for other applications ? is there some setting that I am missing here ?
Thanks in Anticipation
CP
I resolved this.
There are NO CODE CHANGES.
In our Printer Settings, we UNCHECKED the "Allow Escape Sequence" and it worked.
Thanks to the forum tho for entertaining the question.
Will visit often with more questions and resolutions to Questions that others raise
Good Luck
A Clueless Programmer :)
Related
I'm trying to write a C++ app, that is able to make some phone calls. For this, I ordered a USB GSM Module, and a SIM Card with a prepaid contract.
I tested the module in PuTTY and everything works as expected. I choose a COM Port and can send/receive messages. See example:
AT
OK
AT+CMEE=2
OK
But when I try sending these commands via my own application, SOME of them fail (e.g. AT+CMEE=2).
AT
OK
AT+CMEE=2
+CMEE ERROR: Syntax Error
Other commands, such as unlocking the SIM Card work fine as well. But e.g "ATD" doesn't work. Here is the code for writing to the serial port. Keep in mind this is just for testing purposes:
DWORD dummy;
// "buffer" is just an std::string
char* string = new char[buffer.length() + 3]; // "+3" because I append '\0' later when printing
strcpy(string, buffer.c_str());
string[buffer.length()] = ' ';
string[buffer.length() + 1] = '\r';
WriteFile(m_hCom,
string,
(buffer.length() + 2) * sizeof(char),
&dummy,
0
);
I tried several variations ('\0' at the end, no space in between, etc) but all of those led to no commands working at all. So this is the solution where at least some commands are working and responding.
Any more ideas what could be wrong here?
It depends on the operating mode, but sometimes you should terminate the AT command with a \r\n when working with GSM modems. See this post. It looks like you are only adding a \r
I'm a newbie to C++ (and to programming in general). I wrote a program that reads and writes staff contact details. This code works well:
// appropriate headers...
int main()
{
char trigger{};
int options = 0;
bool testing{};
fileIps Inptbox; // for entering new data
char ext_title[20]; char ext_intercomNum[4]; char ext_dept[20];
printf("%s", "Enter Officer's Title:\n");
gets_s(ext_title, 20);
printf("%s", "Enter Officer's Intercom Number:\n");
gets_s(ext_intercomNum, 4);
printf("%s", "Enter Officer's Department:\n");
gets_s(ext_dept, 20);
Inptbox.rcv_values(ext_title, ext_intercomNum, ext_dept);
Inptbox.create_string();
testing = Inptbox.validate();
if (testing == true)
return -1;
else if (testing == false)
Inptbox.write_string();
// more code below...
My question is regarding the console output. I had tried to introduce conditional statements to enable selecting a read or write mode. The above code is for writing to file. There are more lines of code below for reading from file and they, too, worked okay.
My challenge is that once I introduce a conditional statement for the above code...
printf("%s", "Enter 1 to WRITE DATA or 2 to READ DATA\n");
cin >> options;
if (options == 1)
{
fileIps Inptbox; // for entering new data
//... rest of code...
}
// more code below...
...the output on the console is flawed, as the prompt for the first entry is displayed but is totally skipped, forcing the user to enter 'Officer's Intercom Number' first. The third prompt worked well.
To elaborate further, when I used cin to assign the value 1 to options (i.e. applying the condition), the console would immediately print...
Enter Officer's Title:
Enter Officer's Intercom Number:
...making it impossible for me to fill in the first entry (i.e. 'Title').
I struggled with this and tried several things to fix it. I used fgets() and even tried it with gets(). I revisited my classes, yet nothing worked. I read widely on things like buffering, studied questions on this site and looked through various resources on cstdio as well as ios_base and its derived classes (which was good because I learned a bunch of other things). However, unless I removed that 'if' statement from my code, nothing I else I tried worked.
So, my question is: "How can this kind of behaviour be explained and how best could I implement my code to enable me toggle between read and write mode?"
I am working with MS Visual Studio 2015.
Using the formatted extraction operator '>>' has its problems. In this case, it reads all values that can convert to an integer. However, you must give an enter to signal that you're ready. The >> operator does not process that newline. When the next time input is read, it sees the previously given newline character. Hence the 'Enter Officer's title' input is immediately set to a newline and continues. Try using something like:
std::string line;
getline(cin, line);
And test the string or convert it.
I'm stuck on problem were I would like to ask for some help:
I have the task to print some files of different types using ShellExecuteEx with the "print" verb and need to guarantee print order of all files. Therefore I use FindFirstPrinterChangeNotification and FindNextPrinterChangeNotification to monitor the events PRINTER_CHANGE_ADD_JOB and PRINTER_CHANGE_DELETE_JOB using two different threads in the background which I start before calling ShellExecuteEx as I don't know anything about the application which will print the files etc. The only thing I know is that I'm the only one printing and which file I print. My solution seems to work well, my program successfully recognizes the event PRINTER_CHANGE_ADD_JOB for my file, I even verify that this event is issued for my file by checking what is give to me as additional info by specifying JOB_NOTIFY_FIELD_DOCUMENT.
The problem now is with the event PRINTER_CHANGE_DELETE_JOB, where I don't get any addition info about the print job, though my logic is exactly the same for both events: I've written one generic thread function which simply gets executed with the event it is used for. My thread is recognizing the PRINTER_CHANGE_DELETE_JOB event, but on each call to FindNextPrinterChangeNotification whenever this event occured I don't get any addition data in ppPrinterNotifyInfo. This works for the start event, though, I verified using my logs and the debugger. But with PRINTER_CHANGE_DELETE_JOB the only thing I get is NULL.
I already searched the web and there are some similar questions, but most of the time related to VB or simply unanswered. I'm using a C++ project and as my code works for the ADD_JOB-event I don't think I'm doing something completely wrong. But even MSDN doesn't mention this behavior and I would really like to make sure that the DELETE_JOB event is the one for my document, which I can't without any information about the print job. After I get the DELETE_JOB event my code doesn't even recognize other events, which is OK because the print job is done afterwards.
The following is what I think is the relevant notification code:
WORD jobNotifyFields[1] = {JOB_NOTIFY_FIELD_DOCUMENT};
PRINTER_NOTIFY_OPTIONS_TYPE pnot[1] = {JOB_NOTIFY_TYPE, 0, 0, 0, 1, jobNotifyFields};
PRINTER_NOTIFY_OPTIONS pno = {2, 0, 1, pnot};
HANDLE defaultPrinter = PrintWaiter::openDefaultPrinter();
HANDLE changeNotification = FindFirstPrinterChangeNotification( defaultPrinter,
threadArgs->event,
0, &pno);
[...]
DWORD waitResult = WAIT_FAILED;
while ((waitResult = WaitForSingleObject(changeNotification, threadArgs->wfsoTimeout)) == WAIT_OBJECT_0)
{
LOG4CXX_DEBUG(logger, L"Irgendein Druckereignis im Thread zum Warten auf Ereignis " << LogStringConv(threadArgs->event) << L" erkannt.");
[...]
PPRINTER_NOTIFY_INFO notifyInfo = NULL;
DWORD events = 0;
FindNextPrinterChangeNotification(changeNotification, &events, NULL, (LPVOID*) ¬ifyInfo);
if (!(events & threadArgs->event) || !notifyInfo || !notifyInfo->Count)
{
LOG4CXX_DEBUG(logger, L"unpassendes Ereignis " << LogStringConv(events) << L" ignoriert");
FreePrinterNotifyInfo(notifyInfo);
continue;
}
[...]
I would really appreciate if anyone could give some hints on why I don't get any data regarding the print job. Thanks!
https://forums.embarcadero.com/thread.jspa?threadID=86657&stqc=true
Here's what I think is going on:
I observe two events in two different threads for the start and end of each print job. With some debugging and logging I recognized that FindNextPrinterChangeNotification doesn't always return only the two distinct events I've notified for, but some 0-events in general. In those cases FindNextPrinterChangeNotification returns 0 as the events in pdwChange. If I print a simple text file using notepad.exe I only get one event for creation of the print job with value 256 for pdwChange and the data I need in notifyInfo to compare my printed file name against and comparing both succeeds. If I print a pdf file using current Acrobat Reader 11 I get two events, one has pdwChange as 256, but gives something like "local printdatafile" as the name of the print job started, which is obviously not the file I printed. The second event has a pdwChange of 0, but the name of the print job provided in notifyInfo is the file name I used to print. As I use FreePDF for testing pruproses, I think the first printer event is something internal to my special setup.
The notifications for the deletion of a print job create 0 events, too. This time those are sent before FindNextPrinterChangeNotification returns 1024 in pdwChange, and timely very close after the start of the print job. In this case the exactly one generated 0 event contains notifyInfo with a document name which equals the file name I started printing. After the 0 event there's exactly one additional event with pdwChange of 1024, but without any data for notifyInfo.
I think Windows is using some mechanism which provides additional notifications for the same event as 0 events after the initial event has been fired with it's real value the user notified with, e.g. 256 for PRINTER_CHANGE_ADD_JOB. On the other hand it seems that some 0 events are simply fired to provide data for an upcoming event which then gets the real value of e.g. 1024 for PRINTER_CHANGE_DELETE_JOB, but without anymore data because that has already been delivered to the event consumer with a very early 0 event. Something like "Look, there's more for the last events." and "Look, something is going to happen with the data I already provide now." Implementing such an approach my prints now seem to work as expected.
Of course what I wrote doesn't fit to what is documented for FindNextPrinterChangeNotification, but it makes a bit of sense to me. ;-)
You're not checking for overflows or errors.
The documentation for FindNextPrinterChangeNotification says this:
If the PRINTER_NOTIFY_INFO_DISCARDED bit is set in the Flags member of
the PRINTER_NOTIFY_INFO structure, an overflow or error occurred, and
notifications may have been lost. In this case, no additional
notifications will be sent until you make a second
FindNextPrinterChangeNotification call that specifies
PRINTER_NOTIFY_OPTIONS_REFRESH.
You need to check for that flag and do as described above, and you should also be checking the return code from FindNextPrinterChangeNotification.
We have something like Secure Print.
I go to my control panel >> Printers and Devices >> Printer >> Printer Preference Here i assign a 4 digit pin code ..
I fire a print from Word or Excel ... go to the printer >> retrieve jobs >> select my print job and enter my pin code.
Only then my job gets printed.
Now Our application has two source codes for printing
While firing print from our Application the print is instantaneously done .... I.e. it doesn't store my job in the queue and wait for pin ... but just prints immediately
Some source code
bResult = OpenPrinter(szDevice, &hPrinter, NULL);
// szDevice contains printer name
startDocPrtInfo.pDocName = msg;
startDocPrtInfo.pOutputFile = NULL;
startDocPrtInfo.pDatatype = "RAW";
bPrntErr = (StartDocPrinter(hPrinter,1,(LPBYTE)&startDocPrtInfo) == 0);
WritePrinter(hPrinter, &buffer[2], i, &cnt);
EndDocPrinter(hPrinter);
ClosePrinter(hPrinter);
The Code is printing the given document however its not waiting for user to enter his pin code
QUESTION How to make the above code wait just like its doing for other applications ? is there some setting that I am missing here ?
To give you more details .
We have another Print subroutine in the same application that works as desierd .. I.e. waits for User to enter his PIN
However the subroutine uses TextOut method instead of WritePrinter
Any idea why print is not waiting when i use the WritePrinter methods of printing?
Thanks in Anticipation CP
I resolved this.
There is NO CODE CHANGES.
In our Printer Settings, we need to UNCHECK the "Allow Escape Sequence"
Thanks to the forum tho for entertaining the question.
Will visit often with more questions and resolutions to Questions that others raise
Good Luck
A Clueless Programmer :)
Working on a project. Professor gave us a .zip file with some tests, so we can see if our project is working correctly. We are building a small kernel in c++.
Anyhow, there is a thread that waits for a keyboard interrupt (event9.wait()) and after that it should put characters in a buffer or end the program (if you press "esc").
while (!theEnd) {
event9.wait();
status = inportb(0x64); // reading status reg. from 64h
while (status & 0x01){ //while status indicates that keys are pressed
....
I checked and I am certain that it waits for the interrupt regularly. The problem occurs because status&0x01 is 0.
Then I got the part of code that gets the characters from 0x60 and it worked just fine.
Is there something wrong with the code of test files? And if yes, what? If the code is correct what could cause the problem?
I could change the test files, but I need a good reason to do so. And so far the only reason I have is that it doesn't work.
*note: comments are translated from Serbian, but I am almost certain they are translated correctly.
I think status & 0x01 is perfectly fine. However, you would need to read the port again after reading port 0x60 - it may well be that you do that later on in the code, but I personally would just re-write the code to:
while ((status = inportb(0x64)) & 0x01){ //while status indicates that keys are pressed
....
Note that you shouldn't read port 0x64 again inside the loop in this case.