|
Good answer!
Minor detail:
char number[2] = "32"; // Outch: char number[2] = {'3','2','\0'}
Should be
char number[3] = "32"; // Ok
even in our sleep.
Sorry automatic reaction when I see a line of code (even example code) that makes my heart skip a beat.
INTP
|
|
|
|
|
In an anonymous Citrix session authenticate to a printer (net use <printer> at a command prompt). Then execute code that calls
HDC hDC = CreateDC(NULL, <device name of printer>, NULL, NULL)
If the Citrix box is running Win2000 this works. A valid device context is returned and you can print to it.
If the Citrix box is running Win2003 the returned HDC is NULL, but GetLastError() also returns zero.
Does anyone know if this is a defect in the OS or how to get around it?
fred.
|
|
|
|
|
Hello,
I'm having trouble porting data. Here's the situation. An app written in VC++ has a data structure which uses MS data types (DWORD etc.) and standard tpyes. It defined a variable to be of this structure and wrote the data to a file. Now, I write an app in UNIX to read the original data back and load it into a local variable defined to be the same structure as before. Of course, UNIX does not contain types such as HANDLE. I tried my best to re-define the structure with equivalent data types. However, I run into a problem. I used sizeof to get the size of the structure in both app's. It is larger on windows. I assume it's due to the byte boundry issue when windows goes to allocate memory. The offending data type I think is __int64, but it's defined under both platforms (a long long I think). Any work around?? Thanks.
|
|
|
|
|
Humm..
I've created very little software for *nix platforms, but I'd consider that this problem is, like you stated, related to the new 64-bit architecture-compatible values. Following is an extract from MSDN:
"The Microsoft specific types __int8, __int16, and __int32 are synonyms for the ANSI types that have the same size, and are useful for writing portable code that behaves identically across multiple platforms. The __int8 data type is synonymous with type char, __int16 is synonymous with type short, and __int32 is synonymous with type int. The __int64 type has no ANSI equivalent."
As you see, there is no equivalence for __int64 in ANSI standard, so I doubt that the *nix compiler you are using supports the completely similar __int64 as MSVC++ uses. There is no existing standard here yet.. The 'long long' is at best a vague
My suggestion is that you go back to the original code and see if there are any values that you can redefine to 32-bit types. Other option would be to fetch a compiler that supports ILP64 data model standard. In there, 'int' and 'long' are 64-bit values, and 'int32' is a 32-bit value.
Alternatively, see if you compiler supports the "System Interfaces and Headers, Issue 5 (XSH)" definition. In here, a header 'inttypes.h' contains a type 'int64_t' for 64-bit integers.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
There is also the problem of endianness. If you are dealing with binary data you might also actually have to reverse the byte order. This depends on the micro-processor not necessarily the operating system - but it is a problem you must look out for.
J.
----------------------------
|
|
|
|
|
If suitable, try and split the structure up into units that are common. For example, rather than an int64, have two 32bit integers. Depending on what you use it for, you'll then need to convert this into the appropriate value at the other end. This could be handled by a conditional statement:
#ifdef WIN32
convert for windows
#else
convert for unix
#endif
Not the nicest solution, but sometimes you have no choice but to get dirty!
|
|
|
|
|
I created a structure whose members are __int64 and DWORD. I used sizeof to find that __int64 is 8 while DWORD is 4. However, I get 16 when I do sizeof(my_structur_t). Shouldn't I get 12 (4 + 8)?? Thanks in advance.
|
|
|
|
|
Probably due to alignment. I guess the first member is DWORD, and _int64 is aligned on 8-byte boundary. Try it with _int64 first.
|
|
|
|
|
This might be a word alignment issue. You can include a #pragma statement to force it to 1 byte alignment, and there is something in the compiler options that lets you do this as well.
J.
----------------------------
|
|
|
|
|
The whole may be greater than the sum of its parts.
The compiler is trying to optimize the size and alignment of the structure as a whole, as well as the members within. In your case the compiler is taking the larget member (__int64), making the structure size a multiple if it (8) and making sure the members are memory aligned for thier respective type.
To get around this 'pack' your structure :
e.g.
#pragma pack(push, 1)
typedef struct {
__int64 pa;
DWORD pb;
} SA;
#pragma pack(pop)
However, remember there is a reason that the compiler is aligning the structure and its members (not going to get into it here). You will generally only pack structures (or classes) that mirror data on disk or in a stream (where the reader and writer may use different alignment/packing rules), or if you are creating massive instances of the structure and you want to save the memory (have yet to see a case where this reason is justified though).
...cmk
Save the whales - collect the whole set
|
|
|
|
|
I was wrong with my suggestion to change the sequence of the two definitions; the size is 16 in both cases.
I guess the reason is to ensure that the structure starts on the appropriate boundary even in an array of structures.
|
|
|
|
|
I have OnCtlColor for coloring controls. It works with all but the buttons. Additionally I have OnDrawItem; even if it does not do anything, the coloring made in OnCtlControl appears.
Can one explain it to me, why the coloring suddenly appears - only by virtue of declaring OnDrawItem?
But the more important issue is: text does not appear on the button - neither the originally defined text (via the button declaration), nor the text passed in OnDrawItem via DrawText.
DrawText returns the font size, i.e. apparently it runs properly - only, that the text does not appear.
|
|
|
|
|
To anyone interested:
the rectangle in the DrawText function has to be taken from DRAWITEMSTRUCT, because the position is relative to the button, i.e. the top left position is (0,0). First I passed the button position in the dialog window.
|
|
|
|
|
I ran into the same thing (kinda) a couple days ago.
If we think of there being 3 coordinate systems : screen, window, client then we see that most drawing functions are in client with the remainder in screen.
But both ExtTextOut() and DrawText() seem to use window coordinates (and of course the MS docs don't mention this).
A general solution is to get the client coord then adjust for any border. I whipped up a small function to get the border :
bool GetBorderRect( HWND H, RECT &R )
{
if( !H || !::IsWindow(H) ) return(false);
CkRECT rw(1000,1000,1000,1000);
::AdjustWindowRectEx(&rw,
::GetWindowLongPtrW(H, GWL_STYLE),
FALSE,
::GetWindowLongPtrW(H, GWL_EXSTYLE)
);
R.left = 1000 - rw.left;
R.top = 1000 - rw.top;
R.right = rw.right - 1000;
R.bottom = rw.bottom - 1000;
return(true);
}
I can then do something like (for custom static painting) :
CkRECT rc; ::GetClientRect(wndHnd, rc);
CkRECT rb; ::GetBorderRect(wndHnd, rb);
rc.MoveBy(rb.left, rb.top);
::ExtTextOutW(DC, rc.left,rc.top, ETO_OPAQUE, &rc, NULL, 0, NULL);
...
::DrawTextW(DC, s, -1, &rc, TxtStyle);
...cmk
Save the whales - collect the whole set
|
|
|
|
|
Thanks. Somewhere I calculated the recangle the same way you suggest; however in OnDrawItem it is not necessary, because the rectangle is part of the parameter.
The reason I'm writing this is another issue. You mentioned the different coordinate systems (it's a real joy, isn't it).
If you are working on products, which have to run on all 32-bit Windows, you may find following information useful.
I just wrote a program, which stretches respectively shrinks a dialog window (every control, fonts, etc.) on special user key actions, in order to adjust it to monitor resolution and magnification.
Anyway, I needed the size of the desktop to maximize the window size.
deskwnd = GetDesktopWindow();
(*deskwnd).GetWindowPlacement(&desktop);
Now, this works well on XP and Win98 (I have not tested it on Win2000), but on Win95 it returns a negative number for the width of the desktop (but the height is ok .
I tested it with different resolutions: the returned value is always the correct value - 5428.
I thought you might use this info.
|
|
|
|
|
Vancouver wrote:
however in OnDrawItem it is not necessary, because the rectangle is part of the parameter.
I don't use MFC anymore, i've got my own Win32 class framework. It is in my static window control, that does custom painting, where i needed this.
Vancouver wrote:
I just wrote a program, which stretches respectively shrinks a dialog window (every control, fonts, etc.) on special user key actions, in order to adjust it to monitor resolution and magnification.
Ouch, and i thought i was a sadist. Cool, but it must have been a pain to write.
Vancouver wrote:
Anyway, I needed the size of the desktop to maximize the window size.
Have you looked at :
GetSystemMetrics() with SM_CXSCREEN, SM_CYSCREEN, or GetDeviceCaps() with HORZRES, VERTRES (one calls the other) ?
... also when reading the doc's for GetSystemMetrics() check out SM_CXFULLSCREEN.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
I have a movie clip playing with directshow in a picture control (created with the resource editor) inside a dialog. Although it plays well and functions fine, there is one problem I can't seem to get around. When the video clip is paused and I minimize the program, everything gets repainted except for the picture control showing the paused scene (this happens 9/10 times; the other 10% it gets repainted). Is there a workaround for this or should I scrap the picture control and create my own child window with WS_CLIPCHILDREN to correct this, amd will this even correct the problem?
I mention WS_CLIPCHILDREN because the sample PlayWnd that comes w/ DirectX states the they window needs WS_CLIPCHILDREN style.
|
|
|
|
|
Hi all
im being a bit thick at the moment and my if statement does not seem
to be working as it should.
i have a CString variable called str_Status
this holds the valued "Cancelled by User"
when i step through my program and come to the below if statement
if ((str_Status != "Sent") || (str_Status != "Cancelled by User"))
i expect it not to go into the if, but it does and i dont know why
can any see whats wrong here, it seems to be with the "or", but i just cant
get it to work
thanks in advance
si
|
|
|
|
|
Hi,
As far as I can see in your example any string will go into the if code.
ie
"Cancelled by User" != "Sent" .... therefore it goes into if (the first test)
"Sent" != "Cancelled by User" .... therefore it goes into if (the second test)
"Anything else" != "Sent" ........ therefore it goes into if (the first test)
I think you may need to brush up on your or and ands, then try again!
Happy coding,
Ali
|
|
|
|
|
thanks for that, but that makes no sense at all.
|
|
|
|
|
It might be better to treat it as a truth table - Alison is right.
treat a as your first string check, eg:
bool a = (str != "Whatever");
treat b as your second one:
bool b = (str != "Something else");
then you have (effectively):
if(a || b)<br />
{<br />
}
So if str is "Whatever", then a == false, but b == true, so (a || b) == true as well, and so it goes into the if
If str is "Something else", then a == true, b == false, so (a || b) == true again, so it goes into the if
If str is any other string, then a == true, b == true, so (a || b) == true, and so it goes into the if.
What you probably want is:
if( (str != "Whatever) && (str != "Something else") )<br />
{<br />
// do stuff.<br />
}
--
Ian Darling
"The moral of the story is that with a contrived example, you can prove anything." - Joel Spolsky
|
|
|
|
|
The statement:
if((str_Status != "Sent" || (...))
is always true because you said you set str_Status to "Cancelled by User".
Art
|
|
|
|
|
If I understand it correctly, you don't want it to run the block of code if status = "sent" or "cancelled by user". Try doing the following if statement:
if (!((str_Status == "Sent") || (str_Status == "Cancelled by User")))
If it's equal to "Sent", then it returns false
If it's equal to "Cancelled by User", then it returns false
If it's equal to "Anything else", then it returns true.
Hope this helps,
Tim
|
|
|
|
|
Step through the != operator code (F11 in the debugger) to see the logic flow. First it tests str_status != "Sent" . Since str_status is, in fact, not equal to "Sent" , the left side of the || is true. Since || short-circuits in C, the || evaluation immediately stops and returns true . Since the if test is true , the block of code following the if runs.
What you want is
if ( str_Status != "Sent" <font color=red>&&</font> str_Status != "Cancelled by User") && not ||
--Mike--
Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber
Kosh reminded me of some of the prima-donna programmers I've worked with. Knew everything but when you asked them a question; never gave you a straight answer.
-- Michael P. Butler in the Lounge
|
|
|
|
|
In an or test || if the first condition is true the second conditon is not even tested for, thus in your
if ((str_Status != "Sent") || (str_Status != "Cancelled by User"))
(str_Status != "Sent") is true so the if statement is executed. Just use (str_Status != "Cancelled by User") as the sole condition.
|
|
|
|
|