|
Use Windbg "ba r1 0000ffff" can break when address(0x0000ffff) reads.
But I don't know how to open and location the source code.
|
|
|
|
|
The first thing that came to mind is to search for g_iNum in the entire code base and put breakpoints where ever it is being accessed.
«_Superman_»
I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) (October 2009 - September 2013) Polymorphism in C
|
|
|
|
|
This MSDN page lists size as one of the primary components of a font. Do I understand correctly that this means Times New Roman is a typeface but not a font, 8pt Times New Roman is a font, and 12pt Times New Roman is a different font? If so, it seems like the word font is used in places I would intuitively have thought deal with typefaces. For example, this talks of installing a "font." I thought the way fonts work is that there is a file that specifies the shape of each character, which can then be drawn at whatever scale one desires. In other words, the thing one installs is Times New Roman, not Times New Roman at a specific point size. Is that right?
I have more questions, which deal directly with WinAPI, but they hinge on the answer to this one.
|
|
|
|
|
This is no standard use of what the word font means, it means different things to different people. Typeface is a term with far more precision because it comes from the print industry and the general public would rarely use the word.
That said, Windows deals with two main classes of fonts by which they really mean file types. They have bitmap fonts (sometimes called screen fonts or raster fonts) and they have scaleable fonts (sometimes called vector fonts).
So specifically when you are installing a font either of your statements could be true. If you are installing a raster/bitmap font file then you will get the size it represents as pixels in the file and optionally a limited number of scaled sizes. If you are installing a truetype, adobe or postscript vector font you get full the typeface and the ability to scale any size you like.
To make matters more confusing Windows carries a system called cleartype which may or may not be in use by a program. Cleartype is a subpixel render that when you re-scale a font and it is converted to raster (bitmap) for the final display, it makes decisions about those pixels on the boundary that are partially in and out. It doesn't make the crass blank decision that if 50% or more is inside then it turns the pixel on. It uses shading and hints built into the font to make the decision instead.
Then finally in windows there is a further complication that all of what we have discussed is meaningless without knowing which device context we are talking about. A screen device context is very different to a printer device context, as an example there is no cleartype on any printer device driver I know of. Some printer drivers may not even support every font size and type and they are allowed to silently pull a font substitution. So anything we discuss may be wrong on a different device context.
A lot of this is historic and even now largely unavoidable Windows for device drivers is not a closed system. Any manufacturer or developer can write and install a device driver. Linux is even more uncontrolled in many ways because the O/S sourecode can be changed by anyone and there are even more options and differences there.
At the moment you haven't dealt with one of the huge variations which is what characters are represented in the font or in your terms you would probably say how many glyphs are represented in the typeface. This leads into what keys maps to what glyphs which is called mapping or encoding by the O/S. Even the display direction is not set in stone unlike English many languages go right to left and it is supported. Being able to type vertically may or may not be supported the usual problem it throws up is condensing and proportionality rules get thrown into chaos.
If you want more precision around things you are going to also give us precision that is what device context are we talking about when you ask the question. Device context here as a very precise meaning on windows
About Device Contexts | Microsoft Docs[^]
In a programming sense to do anything with a font, you first create a device context and every operation on a font requires you to send the device context as part of that call. So I can't answer much without knowing what device context you are talking about.
In vino veritas
modified 6-Sep-18 23:24pm.
|
|
|
|
|
This does clarify some of the questions I would otherwise have asked already. With that, I'll go into the specific scenario I'm dealing with: I'm working on a music notation program, which will be getting its music symbols from a font. (For now it will involve drawing symbols to the screen, so looks like that makes display device contexts the relevant ones.) I have installed the Bravura font, and would like to use it for this purpose. The first difficulty is the proper way to select it. My understanding is that what I installed is an example of what MSDN calls a physical font, and there is no way to select a physical font directly, all font selection instead involving specifying a set of properties one wants the font to have, then allowing Windows to find the physical font that most closely matches those properties from among those available to the device in question. Is that right?
I had no idea what values I would need to specify for most of the parameters of CreateFont in order for the font mapper to find Bravura as a match. The cHeight and cWidth parameters are especially confusing for reasons I'll get back to, but many of the other parameters are too, given that they seem to be text-specific, while my font isn't used for text. So instead I called EnumFonts. I assume it's possible for this function to find more than one match for the given typeface name, but am unsure about the implications of the number of matches it finds. I believe my font should be one that can be scaled freely to different sizes. Would one expect EnumFonts to call the callback specified by the lpProc parameter once for every possible size such a font can be rendered in? Or, if it calls the callback only once (which is what happened for me), what do the lfHeight and lfWidth fields of the LOGFONT struct passed to it indicate, if not that the font can only be rendered at that one (logical-unit) size after all?
I have still more questions after this, but it will be easier to check whether I'm in the right ballpark with what I've said so far first.
modified 7-Sep-18 0:32am.
|
|
|
|
|
There is no requirement to enumerate the font you can just straight ask for it.
I am going to assume you know how to get a device context for your window to display it in.
I am going to assume the font is a TTF font.
If you want to test it just type in any name of a truetype and it should change how any new text sent to the window displays .. try "Gabriola" or something crazy like that and what it does .
#include <tchar.h>
BOOL SetFontToDC(HDC Dc)
{
LOGFONT lf = {0 };
HANDLE TTFHandle;
lf.lfHeight = -16;
lf.lfWeight = FW_NORMAL;
lf.lfOutPrecision = OUT_TT_ONLY_PRECIS;
_tcscpy_s(lf.lfFaceName, LF_FACESIZE, _T("Bravura"));
TTFHandle = CreateFontIndirect(&lf);
if (TTFHandle != INVALID_HANDLE_VALUE)
{
SelectObject(Dc, TTFHandle);
return TRUE;
}
return FALSE;
}
You get what the indirect is about, it means programatically no user prompts or asking. So this will not ask any questions it will fail quiet if we have done something wrong. On the API that is what any indirect call usually means and yes its a strange terminology as well. Direct is the opposite it means ask the user directly.
There are other options you can ask it for about the font on the LOGFONT structure but none of it is mandatory, 0 for any field means default which is why I zeroed the structure at create.
tagLOGFONTA | Microsoft Docs[^]
In vino veritas
modified 8-Sep-18 0:25am.
|
|
|
|
|
Ah, the crucial thing I didn't realize is that it does no harm to set things one doesn't care about to 0. This is particularly helpful with the width field - I was afraid I was going to have to figure out what ratio of height to width displays the characters without distortion, and use it to calculate what width I need for each desired height, but I've tried a few different height values just now with the width set to 0 and it stays proportional. Excellent.
I held off for a while to see whether I had any more questions - sizing would have been the next issue - but I think I have those all worked out too. Thanks for the help.
|
|
|
|
|
The difference is quite simple. A typeface is a design, like Arial or Times New Roman.
A font is the implementation of a typeface.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I actually like your definition but it won't help you with Windows and it will just cause confusion
Open up notepad ask to change font....
What you call a typeface they call a font, then they have a thing called font style which is "bold", "italic", etc and then a size
Open up Wordpad we have something slightly different ....
Here we have font family, then "normal", "bold", "italic" etc becomes fonts and then a size.
In the programming level for the most part closely ressembles the Wordpad situation.
We have a facename which is generally a typeface (but there are some weird ones like wingdings)
We have a style which is bold, italic, condensed etc
We have a size which may be exact or allow the context to adjust
That is why when trying to understand Windows fonts, it is better to just deal with what you have because much of it isn't consistent even within Windows.
In vino veritas
|
|
|
|
|
Write a program that will provide help with basic unix commands. The program should contain a loop that asks the user to input a unix command or enter quit to stop the program. Your program should recognize at least 6 of the basic unix commands like pwd, etc.). Your program should print out the brief description of the command the user entered. If the user enters a command that your program does not recognize, then print a message to that effect.
You must use the C++ string data type for your input variable.
Hint: use the unix man command to get the brief description for the commands you plan to put in your program. The brief description is the text that appears in the NAME section of the man page, after the command name followed by two hyphens (–). For example:
NAME
pwd -- return working directory name
|
|
|
|
|
No, we don't do your homework. If you've made an honest attempt and are stuck on some detail, come back, show us your code and ask a specific question.
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Start with the basics and build on it gradually. The first thing you need is a program that accepts a string from the user and checks to see if is the word "quit". If it is anything else then print "unknown command" and go back and wait for the next input. If it is "quit" then exit the program. Once you have that working you can add the other commands one at a time, testing the program after each one.
|
|
|
|
|
Something is definitely wrong here. This is the most simplest, succinct explanation that could be offered, so why in the crap is it not being taught/understood in the school system? Is it the students or the instructors that are to blame?
"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
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Well said.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
I suspect it's a mixture. Some teachers are not so good, some students lack the ability, some are lazy. But I suspect we never hear from the ones who do have good teachers, and ability, and are prepared to try things for themselves.
|
|
|
|
|
I created a socket_raw, the custom protocol type is 0x2328, and I send 0x2328 type data on another machine. The capture packet can be captured, but recvfrom cannot receive it. What should I do? Here is the code received.
struct sockaddr_ll sll;
struct ifreq ifr;
if ((sd = socket (PF_PACKET, SOCK_RAW, htons (0x2328))) < 0) {
perror ("socket() failed to get socket descriptor for using ioctl() ");
exit (EXIT_FAILURE);
}
memset (&ifr, 0, sizeof (ifr));
sprintf (ifr.ifr_name, "eth1");
if (ioctl (sd, SIOCGIFINDEX, &ifr) < 0) {
perror ("ioctl() failed");
return (EXIT_FAILURE);
}
memset (&sll, 0, sizeof (sll));
int sll_len;
sll.sll_family = AF_PACKET;
sll.sll_ifindex = ifr.ifr_ifindex;
sll_len = sizeof(sll);
char buffer[1024];
recvfrom(sd, buffer, sizeof(buffer), 0, (struct sockaddr *)&sll, &sll_len);
|
|
|
|
|
|
recvfrom has no return value, because there is no data, so it is blocking. And if I change 0x2328 to 0x0003, I can receive it.
|
|
|
|
|
Try making it a non-blocking socket. You should then get a status return.
|
|
|
|
|
After I set it to non-blocking, I always returned error code 11, but I didn't find the error message corresponding to 11.
|
|
|
|
|
Could you show the actual code used to obtain the error?
|
|
|
|
|
|
It won't help you with your problem but error code 11 is EGAIN defined in errno.h. It indicates that you should execute the function again until you get data or an error, or give up (time out). It is returned by non-blocking functions when the corresponding blocking function would block.
|
|
|
|
|
int main(int argv, char *argc[])
{
struct ifreq ifr;
struct sockaddr_ll sll;
int sd, sll_len;
sll_len = sizeof(sll);
if ((sd = socket(PF_PACKET, SOCK_RAW, htons(0x2328))) < 0)
printf("create socket failed!\n");
sll.sll_halen = ETH_ALEN;
strcpy(ifr.ifr_name, "ens33");
ioctl(sd, SIOCGIFFLAGS, &ifr);
ifr.ifr_flags |= IFF_PROMISC;
if(fcntl(sd, F_SETFL, O_NONBLOCK) == -1) {
perror("fcntl");
exit(errno);
}
char recvbuf[2048];
sleep(5);
int n_read = recvfrom(sd, recvbuf, 2048, 0, (struct sockaddr *)&sll, &sll_len);
if (n_read <= 0)
{
printf("%d\n", errno);
}
}
I started to cycle data before I hibernate, but I still can't receive it
|
|
|
|
|
I found the reason. Previously, because send and recv were sent and received on the same network card, it could not be received.
|
|
|
|
|