|
extern class A;
A fun1()
{
return A();
}
void fun2(A& a)
{}
int main()
{
fun2(fun1());
}
I think specify fun2(...) argument as a const reference make sense. Because when the call to fun2(...) is made the compiler has to generate a temporary object in order to hold the object returned by fun1(...), and this temporary object default to const!But somehow compiler doesn't complain!
Mark Petrik Sosa wrote:
A a;
return a;
is the same as
return A();
is "return A();" just a call to the constructor?
|
|
|
|
|
Hi guys hopefuly someone will be able to help.
I need to open a file for reading but this file is already open by another application for writing.
I have tried playing around with the flags in CreateFile but have still not succeeded.
Does anyone know how to do this?
|
|
|
|
|
If the other app hasn't specified sharing, then you can't do this. The CreateFile call has a sharing parameter which can be any one of (or combination |'d together of)
FILE_SHARE_DELETE
FILE_SHARE_READ
FILE_SHARE_WRITE
or you can specify 0, which means no sharing. This applies when you open a file, and means that you are happy to let subsequent calls to CreateFile open the file if they specify only the access you're willing to allow.
If the other app has specified zero, you can't open it anyhow, but if it's specified FILE_SHARE_READ then you *could* open it for reading, but not for read/write or just write.
Does that help?
Steve S
Developer for hire!
|
|
|
|
|
Thanks for the help Steve.
I just used File Monitor to check how it is being opened by the other application (I do not have source code for it)
It says: Options: Openlf Access: All
I doubt it is allowing share read... I guess I cannot use CreateFile to open this file...
Jeremy.
|
|
|
|
|
Hello...
Arturdt wrote:
I need to open a file for reading but this file is already open by another application for writing.
Which Application lock the File ???
Can you specify the file share permission from both applications ???
When yes, you must only speciefy the correct file share permission when you create or open the file (FILE_SHARE_READ|FILE_SHARE_WRITE).
|
|
|
|
|
The application locking the file is Edonkey (I am reading the .part files)
However I need to do this whilst edonkey is running.
Jeremy.
|
|
|
|
|
You could make a temp copy of the file for your own program, then delete the temp file when finished. That wouldn't require direct access to the target file.
u6ik
|
|
|
|
|
Yes, I am currently making a temp copy however I am dealing with multiple files of 9,500KB many times reaching to gigabytes of data... so I would like to avoid this extra copy!
|
|
|
|
|
Hello...
I want to get the Font width from a font handle and the ::GetObject(...) function to retrieve the font data (in a LOGFONT structure)... But often the lfWidth member is zero or very small...
How to get the correct font width ???
|
|
|
|
|
//You can get it like this:
double width;
RECT Rect;
width=Rect.right;//This is the width of your window.
|
|
|
|
|
which has to do with fonts how, exactly ?
Steve S
Developer for hire!
|
|
|
|
|
That will give you the average width (if available) of a character (in logical units). That may not be what you want, unless it's a fixed pitch font. Better (but slower) is to select the font into a device context, and use the GetTextExtentPoint32 functions for specific strings. Alternatively, if you really want the average width, you can do this using GetCharABCWidths and a bit of math.
Steve S
Developer for hire!
|
|
|
|
|
I believe what you want is something like GetTextMetrics(), which will return an average width in units based on the DC your using. A LOGFONT's lfWidth returns an average width in logical units. Also you can use DrawText() with DT_CALCRECT to get accurate dimensions on a given peice of text on a given DC.
|
|
|
|
|
Thanx for your very fast reply...
I hoped that i mustn't select it to dc and can calculate the max font width or better max letter width from the LOGFONT structure or other else...
But also big thanx...
|
|
|
|
|
Yes and No...
TEXTMETRIC struct defines the right member that i need (tmAveCharWidth), but i need always a dc to get them... So i hoped it exists any other way to calculate them from LOGFONT structure or other else...
But always big THX for your reply...
|
|
|
|
|
Without a DC a real width doesn't exist until it's associated with a DC. If your printing it to a high dpi printer your width will be different then on a low dpi monitor. If you want something more "logical" use the font size which is calculated from LOGFONT's height.
|
|
|
|
|
Hello...
Mhhh...
Mark Petrik Sosa wrote:
Without a DC a real width doesn't exist until it's associated with a DC.
I don't understand ?
I think the LOGFONT height it's the height of the font. The size is fixed and independent from the dc...
What's the different about the width...
When i create a font with a height of 20 pixels then is height from the font on a screen dc different as from the printer dc, but i think it's difference about the resolution and the count of pixel per inch...
Can you explain your idea?
Best regards...
|
|
|
|
|
Good question.
From the MSDN on LOGFONT:
If lfWidth is zero, the aspect ratio of the device is matched against the digitization aspect ratio of the available fonts to find the closest match, determined by the absolute value of the difference.
The height of a font is in logical units. Which is why a font at size 8 can look huge on a computer with large fonts set.
The Windows GDI was designed to make as little assumptions as possible about what it's drawing on. On a printer 20 pixels is very tiny because it's DPI is so high. There are even monitors that aren't at the normal 96 dpi, so these would not look right if it was embedded with a nonlogical number. Some devices don't even use pixels but other measurements, like twips, so until the DC is set with this information you can't get the width on some fonts.
Why can't you get the font's average width logical units? I'm not sure, perhaps it has to do mostly with the font, whether an accurate font to that size has been selected or not, or whether a font author must set this information in the header. Maybe windows is just reluctant to provide such an inaccurate approximation, I don't know.
In my opinion it doesn't seem like a big deal (apart from being interesting) since it's a logical value anyways. If you were to use it, you'd have to make all the calculations that GetTextMetrics makes for it to work across all DCs. I can't see where you'd use it without a DC.
I hope this makes things somewhat clearer.
|
|
|
|
|
Hello Mark...
Thx for your comments... It helps me a lot to understand the difference about logical untits and the real size on dc'S...
Mark Petrik Sosa wrote:
I can't see where you'd use it without a DC
I need the width of the font in some calculations of my new app...
But before the window is drawing...
At this point the explicit creation of a dc handle to retrieve only the width of the font looks very involved...
Best regards...
|
|
|
|
|
I've used DrawText() with DT_CALCRECT, when the string is long enough, then the speed will
be very slow.
|
|
|
|
|
Hi All
Got a weird problem. I am using VC++ SDK v6.0 and placing a Progbar active component in the dialog window for obvious progress status reasons... however, it causes the window to disappear from the program. Not just the dialog window, the whole program vanishes from the screen. I know it's running due to the program icon in the taskbar, though nothing is shown onscreen. Also, when removed from the resource dialog all is fine and the window reappears.
I'm not sure what's going on as I've used PBs before with no trouble. comctl32.lib is in place and the correct headers... all very weird.
Any thoughts?
u6ik (The Confused)
|
|
|
|
|
Try calling InitCommonControlsEx() with ICC_PROGRESS_CLASS before you start your main winproc.
|
|
|
|
|
Don't know how I missed that, my idiot moment for the day.
Many thanks
u6ik
|
|
|
|
|
an opc simple : I can run opc server and client in one pc. But when Opc running in another pc , the opc client can't connect to server. Why? How can I config opc server ,server pc and client pc ,thank you!
|
|
|
|
|
I made an graphic mfc ocx . But I want to see it in IE at remote client. And I use this ocx in server mode in asp.net. How Can I convert it. I want't to program it repeatly.
|
|
|
|