|
The first thing that jumps out at me is the lack of error checking. Try
char buffer[1024] = {0};
DWORD dwError,
dwNeed=0;
HANDLE hPrinter = 0;
PRINTER_INFO_2 ptinfo = {0};
if (OpenPrinter("FinePrint", &hPrinter, NULL) != FALSE)
{
if (GetPrinter(hPrinter, 2, (PBYTE) &ptinfo, 0, &dwNeed) != FALSE)
GetPrinter(hPrinter, 2, (PBYTE) &ptinfo, dwNeed, &dwNeed);
else
dwError = GetLastError();
}
else
dwError = GetLastError(); and then see if the problem persists. If so, at least you'll know the cause.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Thank you for help.
But not soleved.
if (GetPrinter(hPrinter, 2, (PBYTE) &ptinfo, 0, &dwNeed) != FALSE)
above line will evaluate to false(GetPrinter return false)
dwNeed = 1648
then else code will trigger
else dwError = GetLastError();
error code = 122 // The data area pass to system call is too small!
As my first post when i pass enough size (dwNeed) to GetPrinter program will crash !
More help please.
|
|
|
|
|
While the code snippets that I provide are meant to be syntactically correct, they may not always be logically correct. This is intentional. Try:
DWORD dwError,
dwNeed = 0;
HANDLE hPrinter = 0;
PBYTE pBuffer = NULL;
PPRINTER_INFO_2 pPrintInfo = NULL;
if (OpenPrinter("FinePrint", &hPrinter, NULL) != FALSE)
{
GetPrinter(hPrinter, 2, NULL, 0, &dwNeed);
pBuffer = new BYTE[dwNeed];
if (GetPrinter(hPrinter, 2, pBuffer, dwNeed, &dwNeed) != FALSE)
{
pPrintInfo = (PPRINTER_INFO_2) pBuffer;
}
delete [] pBuffer;
}
else
dwError = GetLastError();
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Ohh ,have to contruct the buffer first.
I will read your article alot to grap some of your programming skill.
Thank you very much.
|
|
|
|
|
I am experiencing very slow compilation times in VS C++ .NET vs. version 6.0. Has anybody had this experience?
Steve
|
|
|
|
|
Being a beginner, i am having quite alot problem in changing a size of a dialog box to another specific size..more precisely i wish to make a calculator like the one windows have .i have created a standard one and have added a menu but am having a problem in changing the size when the scientific tab is pressed in the menu.... please help me in this respect and please try to explain a bit....
thankyou
haseeb
|
|
|
|
|
well ..
sizing a dialog is a little bit deferent than other kind of windows, because of its measuring units.
In a dialog when you say that width = 100, it doesn't mean 100 pixels (!!) it means 100 dialog units (depends on the font you are using in the dialog).
open user dialog resource in the visual c++ and look at the status bar (right most), you will find the size of your dialog in dialog units.
so,
1- write down size of your dialog when in the scientific mode (from the status bar), these are in the dialog measuring units.
2-
...
<br />
CRect rect;<br />
rect.left = 0;<br />
rect.top = 0;<br />
rect.right = Width;<br />
rect.bottom = Height;<br />
MapDialogRect(&rect);<br />
now you have the new size in pixel units. you can use it freely.
3- Call the function SetWindowPos() and give it the width and height of the rect.
I suggest you move with the debugger to watch the change in the units after the MapDialogRect() call.
hope it is helpfull
good luck
k_dehairy
|
|
|
|
|
thanx alot ... probably now i would be able to achieve my goal....
thanx...
haseeb
haseeb
|
|
|
|
|
Actualy the Windows calculator probably does not resize at all. It most likely consist of 2 different dialog boxes. When the user decides to switch caculator views, that is what it does.
1) Create 2 dialog boxes: normal and scientific.
Remember to use the same IDs for the buttons, etc... that do the same thing.
2) Create a CDialog based class for the scientific dialog only, since you only need one class to handle all the commands.
3) Now when the user selects a new veiw call EndDialog(some known value).
Example:
if( dialogID == IDD_NORMAL )
EndDialog(IDD_SCIENTIFIC).
else
EndDialog(IDD_NORMAL).
4) Finaly your code calling DoModal() (to show your dialog) needs to look something like this:
...
int result = IDD_NORMAL.
do {
if( result != IDD_NORMAL || result != IDD_SCIENTIFIC )
break;
{
CMyDialog dlg(result);
result = dlg.DoModal
}
} while( result != IDOK && result != IDCANCEL );
Any way that is most likely how I would do it. You ought to be able to figure out the rest.
Good Luck!
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
thank you.... i hope now i would figure out a way to solve the problem...
haseeb
|
|
|
|
|
Hi guys
I'm working in a loop that makes hard calculations at each iteration.
My problem is that I can't show the results of each iteration in a listCtrl because the list control is not redrawn between each calculation (no time to do other things that calculate?)
Do you think a way to make redraw my listctrl between calculations?
Thanks in forwarding.
Doc
|
|
|
|
|
Why CStringArray, does not have the function, like SortInsert() and Find(), Search() blu,blu. That's very common function for manipulate String thing.;P
|
|
|
|
|
|
|
|
You can use qsort() to order the array. And once it has been ordered, you can use bsearch() to find items.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
I'm guessing it's because either:
1) The MFC authors didn't get around to it
2) They couldn't be bothered to deal with all the different collation and case options that would be involved
And while I'm here, a copy constructor would be useful...
P.S. We developed our own CStringArrayEx class, derived from CStringArray, to do all these things.
|
|
|
|
|
Given a character array [char tmpbuf[5];] and integer [int arith = 0;]
I need to perform some math on tmpbuf (refer to code below):
Code:
char tmpbuf[5];
int arith = 0;
int iCount = 0
// Code sets tmpbuf = 0x0012c434 “10” (from watchdog)
// Code sets arith = 2 (from watchdog)
tmpbuf = tmpbuf - arith;
Therefore, tmpbuf = 10, arith = 2; final answer should be tmpbuf = 8 (10 – 2)
Line in BOLD causes following error: error C2106: '=' : left operand must be l-value
Basically I have a character array on which I want to subtract the integer value in arith. I assuming either some casting or conversions are required… Note that the final answers needs to be in the same form as the current tmpbuf.
|
|
|
|
|
did you think about converting tmpbuf into a number before doing the operation ( and back to a string after ) ?
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Shaitan00 wrote:
I assuming either some casting or conversions are required
Thats right. You cannot perform any arithmetic ops on a char array and and integer like that in a meaningful way.
You will first need to convert your array, tmpbuf, to its numeric value. Do the arithmetic using the two numbers, then reconvert back to its string representation.
Shaitan00 wrote:
tmpbuf = tmpbuf - arith;
This will not work as you cannot copy array values like this. You can use the memcpy function for this, but only for array transfer.
Use the atoi() function to convert your string to a number. then you can use the itoa to reconvert.
I Dream of Absolute Zero
|
|
|
|
|
Shaitan00 wrote:
tmpbuf = tmpbuf - arith;
DON'T DO THAT!
You are attempting to change the address of tmpbuff from 0x0012c434 to 0x0012c432. You cann't do that since tmpbuf is an array (not an l-value) and not just a pointer. If it was a memory pointer it would still be wrong (crash city)!
char buf2[5];
strcpy(tmpbuf,_itoa(atoi(tmpbuf)-arith),buf2,10));
This would do it, but there is no error checking. What would happen if the number contained more than 4 digits? I recommend you use a larger buffer, since you are working with intergers, the buffer should be a minimum of 12 (10 digits + 1 for '\0' + 1 for '-') characters. That assumes that the value will be no more than a 32 bit number, in the near future it will be a 64 bit number and the code will break.
Sorry about that, but when I see code like that my heart skips a beat.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Can I force the scrolling in CRichEditView to line scrolling? Do you know
which parameters or events should I change or override? Thanks
Maggie
|
|
|
|
|
Does anyone know if there is a way how to export emails from the Inbox/Outbox into .msg files programmatically?
I tried using the Outlook Object Model, but it asks the user for permission to access the mailboxes and ideally I would like to avoid that (no, i'm *not* writing a virus... - i just would like to do away with user interaction while the program is running ).
I also tried using MAPI, and i managed to read emails individually into the IMessage interface, but I can't see how I can stream its properties to a file without iterating on the properties one by one (and potentially risking modifying one property indadvertedly and ruining the entire message).
My recent attempt has been with CDO but again, the MessagePtr interface in cdo.dll doesn't seem to support any streaming.
Anyone has a better idea?
|
|
|
|
|
I have installed on my PC a PCI card which implements RS422 via an API.
Now this API has calls to install and uninstall an interrupt handler; and use this handler to drive conditions such as data sent.
Now I have used the interrupt handler via a Win32 console application, but it seems not to work when I try and use it in a MFC Dialog application - Dont get any interrupts.
I dont know if the handle should be a class member of the dialog, at present its not as thats the only way I could get it to compile.
Two questions:-
1. How does this scheme work (just a simple overview please)
2. I was hoping to use the interrupt to handle time events that need to take place every 40 msec. Can interrupt handlers be installed (via this API) for a MFC application.
Many thanks,
|
|
|
|
|
Pehaps you should ask the providers of the API these questions.
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Walliams (Little Britain)
|
|
|
|