|
> real-world structures share some common elements that will
> be used in future templates. Since sizeof(T) is used to limit
> the amount of data copied, what is unsafe about the template?
You're using a C++, right? (last time I've checked C had no templates). Don't expect bitwise copy to work correctly with C++ objects. Moving bits around will work only if your structs are simple aggregates of primitive types like int, char or double.
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
> Moving bits around will work only if your structs are
> simple aggregates of primitive types like int, char or double
In this instance the structs are simple aggregates, but your point is well taken.
Having programmed in C for the past several years it is sometimes difficult adjusting to C++.
Thanx for your input.
>>>-----> MikeO
|
|
|
|
|
I'm working on an application that contains a CListCtrl. One requirement for the list is that it always displays its vertical and horizontal scrollbars, regardless of the client area. I've tried simply setting the WS_HSCROLL and WS_VSCROLL styles during creation, but to no avail. After much trial and error, I was able to force the scrollbars to display by modifying the list's style in response to a WM_SIZE message.
//
// WM_SIZE handler
//
void ACtrlGrid::OnSize(UINT f_nType, int f_cx, int f_cy)
{
// call base class
CWnd::OnSize(f_nType, f_cx, f_cy);
// re-add horz + vert scrolls
UINT nStyle = GetStyle();
if ( (nStyle & WS_HSCROLL) != WS_HSCROLL
|| (nStyle & WS_VSCROLL) != WS_VSCROLL )
{
ModifyStyle(0, WS_HSCROLL | WS_VSCROLL,
SWP_NOMOVE | SWP_NOSIZE |
SWP_NOZORDER | SWP_FRAMECHANGED);
}
else
{
// ... actually handle WM_SIZE message
}
}
I have two problems with this approach. First, as a result of re-adding the scrollbars the client area size changes which generates another WM_SIZE message. Eventually this recursion is terminated, no thanks to me, but its still a hack. My second issue involves the CListCtrl's header sizing ability. With this approach it is impossible to grab the last column's sizing handle because the vertical scrollbar is covering the right edge of the last column header item. It seems that the listview don't realize when the vertical scrollbar is displayed, and as a result, the horizontal scrollbar range is not increased to account for the extra room the scrollbar is covering.
I'm really looking for an elegant way to override the listview's default scrollbar implementation.
Your assistance is greatly appreciated.
Mike
|
|
|
|
|
You can inherit a class from clistctrl, and then overwrite it's
OnPaint function to force the scrollbar displayed.(ugly)
|
|
|
|
|
I am able to have an icon in the system tray and am able to maximise/minimise from system tray. But I want the 'Maximise' item in the menu to be disabled after the window has been maximised. For this I am writing the following code, but it does not bring the desired result.....
CMenu menu, *pSubMenu;
if (menu.LoadMenu(IDR_POPUP_MENU)){
pSubMenu = menu.GetSubMenu(0);
if (pSubMenu)
::EnableMenuItem(pSubMenu->m_hMenu, uItem1, MF_GRAYED);
}
Please HELP!!!
Thanks in advance
Anubha
|
|
|
|
|
You should call it from pSubMenu not the Global.
pSubMenu->EnableMenuItem(ID_MY_ITEM, MF_BYCOMMAND|MF_DISABLED); (or grayed whichever you prefer)
Bret Faller
Odyssey Computing, Inc.
|
|
|
|
|
Thanks for the reply. But this still didn't work for me.
Any more inputs....
Thanks
Anubha
Telmax Communications
|
|
|
|
|
I have to simulate the upload of a file to a php document that normally would handle the submission of a form.
if i fill the html form, all works great
but if i simulate the submission of the form like
document.php3?file=D:\file.txt&p=toto&t=titi
the document file.txt won't upload on the server
Could you help me ?
PS : please reply in the forum and by mail @ nicolas.lecorre@axyus.com
|
|
|
|
|
|
Perhaps some kind soul out there can see what I'm doing wrong here:
The following code tries to get some registry values.
UCHAR ServerIP[ 16 ], ServerToPort[ 16 ], ServerFromPort[ 16 ];
UCHAR LocalIP[ 16 ], LocalToPort[ 16 ], LocalFromPort[ 16 ];
HKEY key1, key2;
DWORD disp, type, size;
LONG result;
// Open the company key
result = RegCreateKeyEx( HKEY_CURRENT_USER, "UHS", 0, "", REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS, NULL, &key1, &disp );
// Open the Local subkey
result = RegCreateKeyEx( key1, "Local", 0, "", REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS, NULL, &key2, &disp );
// Get the values of IP, InPort, OutPort
result = RegQueryValueEx( key2, "IP", 0, &type, LocalIP, &size );
+ result = RegQueryValueEx( key2, "ToPort", 0, &type, LocalToPort, &size );
+ result = RegQueryValueEx( key2, "FromPort", 0, &type, LocalFromPort, &size );
// Open the Server subkey
result = RegCreateKeyEx( key1, "Server", 0, "", REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS, NULL, &key2, &disp );
// Get the values of IP, InPort, OutPort
? result = RegQueryValueEx( key2, "IP", 0, &type, ServerIP, &size );
result = RegQueryValueEx( key2, "ToPort", 0, &type, ServerToPort, &size );
result = RegQueryValueEx( key2, "FromPort", 0, &type, ServerFromPort, &size );
The registry entries are just IPs and port numbers and the editor shows they are OK. When the above code is run it fills in everything EXCEPT ServerIP. This call returns an error "234" which the ISDN helpfully identifies as "More data available". If I leave out the two calls marked with "+" the thing works and I get the ServerIP.
I have tried to change the order of calling things but no matter what I do, one of the values returns an error. I have tried all kinds of other things like having individual key handles, flushing etc. but nothing works.
My registry is not corrupt and I have tried this on two different machines in different offices. Hope someone knows what's happening.
|
|
|
|
|
You should initialize size parameter before calling RegQueryValueEx - on input it should contain size of the buffer provided by the caller:
size = sizeof(ServerIP);
result = RegQueryValueEx( key2, "IP", 0, &type, ServerIP, &size );
This applies to all RegQueryValueEx calls, not only ServerIP.
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
You are an angel of mercy. It works!!! Thank you.
(Lesson for others: Don't be stupid like me. Read the MSDN parameter doco very carefuly.)
|
|
|
|
|
I am trying to learn VC++ and have a small project I would like to try.
On NT 4.0 Workstation pop up a message box before a user logs on using the Ctrl-Alt-Delete sequence. I have read MS articles on enumerating desktops and using WinLogon events but can't seem to get anything sent to the "WinSta0\?????" desktop.
All I realy want is to send a message that the wks is being upgraded please don't logon until after it reboots.
Am I crazy can this not be done.
Thanks ahead of time. If you can even point me to some sample code or tell me where to look I would appreciate it......
|
|
|
|
|
> On NT 4.0 Workstation pop up a message box before a user
> logs on using the Ctrl-Alt-Delete sequence.
It seems that you need to use the Winlogon/GINA stuff. MSDN has detailed info about this. Honestly, it's not a project for a beginner. Good luck, anyway.
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
Hi.
I want to create an array of an array of char's. Basically, I want to call calloc (or whatever) on a char**. Whenever I do this, I get runtime memory errors or compile time casting errors.
I need this so that I can create an 20 element long array of an array of 256 char's (that's confusing ). However, I will not know the actual lengths of the arrays until runtime, so that's why it needs to be dynamically allocated. Any help would be appreciated.
|
|
|
|
|
OK, here's how to do it (if I get the definition correct). So, you basically want an array of pointers to strings, just like argv**. I'm going to do it for the case of 20 elements, but you can replace it with any variable you want:
int i;
char **aszNames;
char **pCurr;
aszNames = malloc( sizeof(char*) * 20 );
pCurr = aszNames;
for(i = 0; i < 20; i++) {
*pCurr = malloc( sizeof(char) * 257 );
pCurr++;
}
After this, you have 20 string elements which can carry a max of 256 characters. Of course, you can make everything variable by replacing the constant values.
And remember, to clean up after yourself after this.
Frank
|
|
|
|
|
Thanks for the quick response!
The code works, but I have a question about cleaning up:
Should I call free() on both the pointers or just one?
Thanks in advance!
|
|
|
|
|
You have to clean up both pointers. So, for the code I gave before, you would cleanup this way:
pCurr = aszNames;
for(i = 0; i < 20; i++) {
free(*pCurr);
pCurr++;
}
pCurr = NULL;
free(aszNames);
aszNames = NULL;
That's pretty much it. I NULLed the pointers because I use the debugger a lot and it helps me remember whether or not there is anything assigned to the pointers.
Frank
|
|
|
|
|
|
Hello, first of all, let me say that I'm a begginer speaking english... so, I'm sorry if it's hard to read my question.
I have developed a win2k service using the a downloaded service wizard, now I would like to install it and to run it...
If I make a double click to start it up (as a normal app.) it don't make anything.
This service is intended to control some not allowed key presses (alt+tab and so on...)
I had developed an app. some time before with a class that handled them, and it worked for me, but now it don't make anything.
I'm using SetWindowsHookEx(...)
If you want/can help me, please send an answer to the forum, I will answer any question that you could have referenced to my project and surely caused by my "english".
Thank you in advance.
|
|
|
|
|
You cannot run a service like a normal application, if you just doubleclick on it, it does nothing. Just like you say...
I don't know what wizard you used to make the service, and how it works, but normally you install a service by typing, in a command promt, "appname -install", and starts it by typing "net start servicename". Both without the quotes...
A service runs as standard a the "system" user, and whey you try to use SetWindowsHookEx() you get events fro the system user, not for the logged on user.
In the service manager you can make the service log on as a specified user, and then it *might* work, if the same user logs on. But, if another user logs on itdon't work, because the service catches events for the user it logs on asn ot the interactive user...
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
There's an MSDN article called "Installing a Service" that shows code to register (install) a service with the SCM.
Often, a service application has command line options that can be used to trigger the install and uninstall code - for example running '> MyService /i' could run the install code.
Once that's done, you can use net start, SC.EXE, or the services applet in control panel to control things. You'll find registry entries for your service in HKLM\SYSTEM\CurrentControlSet\Services.
HTH
|
|
|
|
|
I believe I asked how to convert a number from normal base 10 to hexadecimal, base 16. Now I need to go the reverse, I need to convert a hexadecimal string to a base 10 number...ie: 14 in hex is 20 in decimal, 3C in hex is 60 in decimal.
|
|
|
|
|
|
That looks like the function I need. However the following should work (I think) and doesn't.
long temp = strtoul("0x14", NULL, 10);
I thought this should return 20 (the decimal value of the hex-string 14), however it returns 0, which means that it couldn't convert the string....what am I missin?
|
|
|
|
|