|
yashraj1215 wrote:
char myvar[21];
myvar[21] = "text";
The second method seems to cause problems with my compiler (Dev-C++) when used in certain situations.
It's actually problematic in all situations. What is says is that the 22nd "position" of myvar points to "text", but since myvar only has 21 characters (0-20) to begin with, whatever happens to follow myvar in memory is being stepped on.
|
|
|
|
|
yashraj1215 wrote:
myvar[21] = "text";
this pasically is saying
put "text" into the myvar at position 22
Remember that char myvar[21] has 21 characters accessed by myvar[0] to myvar[20]
Hoep this helps.
Regards,
Brian Dela
|
|
|
|
|
yashraj1215 wrote:
char myvar[21] = "text";
This means "myvar is an array of 21 char s, and initialize the first five elements to the characters 't' 'e' 'x' 't' '\0' "
yashraj1215 wrote:
char myvar[21];
myvar[21] = "text";
This is incorrect code, that's why it doesn't compile. It's trying to assign an array of characters to one element in a character array.
It is also overrunning the array bounds. The elements are myvar[0] thru myvar[20] . Storing something in myvar[21] will overwrite other data.
--Mike--
"So where does that leave us? Well, it leaves us right back where we started, only more confused than before." -- Matt Gullett
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
|
|
|
|
|
I have successfully created a program to edit the value of a key in the registry... finally! However, I still have a few questions about my code.
The following is one of the lines in my code:
RegSetValueEx(hKey, TEXT("LegalNoticeCaption"), 0, REG_SZ, (LPBYTE) mycaption, 51);
I used this code to set the value of the LegalNoticeCaption key to the value of mycaption, a previously declared char.
Question 1 --
I do not understand what purpose "(LPBYTE)" serves in this code; the code will not compile without it. I found "(LPBYTE)" in the MSDN library, but it never explained what it does or what it means... does anyone know?
Question 2 --
The last parameter of the RegSetValueEx function is supposed to be the size of the buffer. Is the buffer size equal to one byte per character?
Question 3 --
What is the difference between a signed char, an unsigned char, and a char? What are their individual purposes?
Thanks for your help.
|
|
|
|
|
I start with #3
#3 signed char and char are the same thing
unsigned char and BYTE are the same. char being an integer data type needs unsigned version.
#1 since unsigned char has smallest size(1 byte) it is usually used to pass data buffers
LPBYTE == unsigned char*
#2 this one is tricky
for strings its == sizeof(TCHAR) * strlen
|
|
|
|
|
Thanks for replying! But I have questions about your response.
1) Does LPBYTE automatically allow the use of an unsigned char version of "myname," which was preiously declared as a char?
2) What is TCHAR?
Thanks again.
|
|
|
|
|
yashraj1215 wrote:
2) What is TCHAR?
It is a Win32 character string data type that can be used to describe ANSI, DBCS, or Unicode strings.
|
|
|
|
|
1. not automatically, but using static_cast or old C cast. The idea here is that any datatype could be treated as array of bytes in memory (arguably smallest unit allowed in C++) example "int" datatype occupies exactly the same space in memory as "unsigned char[4]". It is more convention than a rule of C/C++.
2. TCHAR is a Windows convention when you compile ANSI it converts to "char" (1 byte), when you compile UNICODE it compile it converts to wchar_t (2 bytes). Therefore, when you deal with string sizes in bytes it is important to remember size of the basic unit (1 or 2 bytes)
|
|
|
|
|
yashraj1215 wrote:
I do not understand what purpose "(LPBYTE)" serves in this code; the code will not compile without it. I found "(LPBYTE)" in the MSDN library, but it never explained what it does or what it means... does anyone know?
While you did not indicate, I would imagine you have mycaption defined as a char, rather than a BYTE. For example, using:
LPBYTE mycaption = "Some Caption Here";
or
BYTE mycaption[32] = "Some Caption Here";
you could have called RegSetValueEx() like:
RegSetValueEx(hKey, TEXT("LegalNoticeCaption"), 0, REG_SZ, mycaption, _tcslen(mycaption) * sizeof(TCHAR));
yashraj1215 wrote:
The last parameter of the RegSetValueEx function is supposed to be the size of the buffer. Is the buffer size equal to one byte per character?
Yes, unless you are dealing with DBCS (i.e., Unicode). In that case, every character uses two bytes.
yashraj1215 wrote:
What is the difference between a signed char, an unsigned char, and a char? What are their individual purposes?
A char and signed char are the same thing (i.e., they use the sign bit). If a type does not have the unsigned qualifier, it is assumed signed.
yashraj1215 wrote:
What are their individual purposes?
It actually depends on what you are storing. ASCII characters (0-127) can be stored in a char, whereas extended ASCII (0-255) must use an unsigned char.
|
|
|
|
|
um, i was thinking of writing a server for something and suddenly something bothered me, like this:
If you have a router between your network and the internet that has a built in firewall, and you have lets say.. port 3000 open, and someone tries to establish a tcp connection with your computer on the network... a syn packet will be sent to the ip address of your internet connection, so it arrives at the router, and the router sees its destined for port 3000 and lets it pass..but then, what if two computers on the network both have their port 3000 listening.. how does it know which should reply, or for what computer the connection was ment???? I'm sure the sollution is pretty simple but i just couldn't think of it, and its bugging me.
Kuniva
--------------------------------------------
|
|
|
|
|
You have to explicity tell the router that an incoming port 3000 get routed to port 3000 on that computer. If you make a connection outbound, then there is information there to route the response back to you. It can't magically determine where an inbound port is routed to.
Joel Lucsy
|
|
|
|
|
Standard port forwarding...
onwards and upwards...
|
|
|
|
|
erm...right. But the thing is, our router uses DHCP, so one time my PC will have this ip, the other it will get another assigned. So you see, i can't specify a forewarding ip address.... (btw i'm not administering our router due to technical restrictions, otherwise i'd know all this)
Kuniva
--------------------------------------------
|
|
|
|
|
You might be able to specify the routing based on mac address. Don't know of any router that did this, but then again, I've only dealt with fairly cheap ones.
Joel Lucsy
|
|
|
|
|
Usually the firewall will allow you to specify a forwarding address. So if you want all connections to port 3000 on your router to be sent to an internal host you would configure the router to forward to a specific internal IP address. When the request comes in to the router, the router routes it to the specified internal address.
Each host has only one IP address, so only one host will get the packet. Now you could of course configure it to be forwarded to the broadcast address and this would mean each host recieves the packet. This could be ugly though.
--
"The money power of the country will endeavor to prolong its rule by preying upon the prejudices of the people until all wealth is concentrated in a few hands and the Republic destroyed."
-- Abraham Lincoln
|
|
|
|
|
I have a CFormview based SDI application. On the formview, I have a property sheet displayed, which has quite some edit controls.
Although I have specified accelerator keys in the resource, the program never respond to any key press. So I am thinking of CMyView::PreTranslateMessage, then CMyView::WindowProc, but neither of them can capture wm_char message when I pressed any key when the edit control on property page is having the input focus.
what can I do? Thanks a lot!
|
|
|
|
|
It's just a guess, i don't use the MFC framework, but don't the WM_CHAR messages only get sent to the actual edit window?
Try using GetWindow() to get the handle of the edit control, and then run a loop using GetMessage() to get the first message in the message queu. Then check it for WM_CHAR and ...
It's just a guess though, there's probably an easier way
Kuniva
--------------------------------------------
|
|
|
|
|
I am not sure. But in one article Nish wrote, you can use PreTranslateMessage to capture wm_keydown or other messages by the dialog instead of having it processed by the control which have the input focus.
I think I should be able to do the same in my app. but
The GetWindow() would be a messy one in my case even it works, since I have hundreds of edit controls.
any other hint?
|
|
|
|
|
Hi,
I am developing a Application which communicated with a Wireless
Protocol Stack on board,
through Serial Communication from a Windows XP m/c. through PPP packets. I
am using MFC API's
for sending data. Is there any mechanism to find out what actual data is
been sent through the COM port
and which protocol is used in sending. I mean the format of the data packets
and so..
Please respond soonly and it would be a great help for me..
Thanks,
pramodav@sasken.com
Pramod Kumar A
SASKEN-INDIA
|
|
|
|
|
Hi
I want to know the physical size of my monitor in inches/millimeters/centimeters. This is what I do currently:
CDC dcDisplay;
if(!dcDisplay.CreateDC("DISPLAY", NULL, NULL, NULL))
{
MessageBox("Failed to get display DC.", "Error", MB_OK|MB_ICONEXCLAMATION);
ExitProcess(0);
}
int xDPI = dcDisplay.GetDeviceCaps(LOGPIXELSX);
int yDPI = dcDisplay.GetDeviceCaps(LOGPIXELSY);
int xRes = dcDisplay.GetDeviceCaps(HORZRES);
int yRes = dcDisplay.GetDeviceCaps(VERTRES);
int xInches = xRes / xDPI;
int yInches = yRes / yDPI;
const double dInchToMillimeter = 25.4;
double xMillimeter = xInches * dInchToMillimeter;
double yMillimeter = yInches * dInchToMillimeter;
So I get 13 Inches horizontal (330,2 mm) and 10 Inches vertical (254 mm).
But there's another method, that outputs something different:
int xMillimeter = dcDisplay.GetDeviceCaps(HORZSIZE);
int yMillimeter = dcDisplay.GetDeviceCaps(VERTSIZE);
Outputs 320 mm horizontal and 240 millimeters vertical.
Which method is more trustful? One more thing: If I measure
my display with a ruler it seems that all values determined by both functions are too small, e.g. it seems that my display has a width of at least 350 mm and a height of at least 260 mm
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
From what I understand of it, there is no really accurate way to determine the monitor size.
|
|
|
|
|
Windows assumes the monitor's resolution is 96dpi. There's no way that your program can accurately work out how big the monitor is, unless you look in the registry for the monitor model and lookup a database...
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
I have a Dialog project that when compiled will only show the MFC Icon with Windows Explorer. If you click on the file and display properties, then the Icon displayed is the one that I created for it.
Any suggestions as to what I am doing wrong.
Thanks in advance.
Eldon Zacek
Czech-Mate Enterprises, LLC
|
|
|
|
|
Change both the 32x32 sized icon AND the 16x16 and your problem may be fixed.
-KMAZ
|
|
|
|
|
In the VC++ icon editor, there are several available icon types. The one that is normally displayed with your app is the 32x32 size but a second one is also created by default of size 16x16. Explorer usually uses the smaller one. To fix your problem, redraw the smaller one too and rebuild your app.
I am always doing this myself too.
|
|
|
|