|
This article may not directly answer your question, but is worth looking at if you haven't already.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Hi.
I am stuck at on design that include extensive use of pointer. I prefer using point because with pointers, I have more options such as when to create the data structure and when to delele the data structure. Furthermore, I have more options when passing the pointers to functions. Nonetheless, pointers can be tricky when dealing with some API and other Windows based tools such as MFC.
Here is the problem. In Winsock programming, there are API functions that does "clean up," according to Anthony Jones and Jim Ohlund, authors of Network Programming for Microsoft Windows, Second Edition. Some of these API functions include these functions:
// closesocket(...) // you pass in a sock
// freeaddrinfo(...) // you pass a pointer to a struct addinfo
// WSACleanUp() // you pass in nothing
Okay. Those are just a few "clean up" functions for Winsock. I am sure there are some other ones. Here is my question.
As I have mentioned that I prefer using pointer and creating a new data structure and deleting the pointer when needed. That technique gives me more flexibility. However, with respect the the "clean up" functions above, how do they react to pointers? For example:
// sock *mySocket = socket(...); // mySocket is a pointer to a socket
Now I close it.
// closesocket(*mysocket);
Now, should I still call delete mySocket afterward? My main concern is I do not know whether each the API function mentioned above the pointer if you pass it a pointer.
The same scenarios holds for freeinddrinfo and WSACleanup().
In the case of a struct inaddrinfo, you pass in a pointer. However, do you delete that pointer afterard?
In the case of WSAData, do you delete the pointer to a WSAData structure after calling WSACleanup()?
Currently, I *do* delete all pointers even after calling WSACleanup().
Thanks,
Kuphryn
|
|
|
|
|
sock *mySocket = socket(...);
Now I close it.
closesocket(*mysocket);
Now, should I still call delete mySocket afterward?
Nope. socket(...) does not return a (direct) pointer to something it returns a socket descriptior that you use to reference the created endpoint in the future.
Since you did not directly allocate any memory (using new ), you should not be so hasty to delete it. Also, you should not be passing socket pointers to those functions.
In the case of a struct inaddrinfo, you pass in a pointer [...]
Just because something takes a pointer as a parameter, that does not mean that you automatically are required to dynamically allocate something. You can create a inaddrinfo on the stack, and pass in its address to whatever functions takes a pointer-to-a-inaddrinfo structure.
In the case of WSAData, do you delete the pointer to a WSAData structure after calling WSACleanup()?
Only if you actually allocated the WSADATA structure earlier. If you just created one on the stack, and passed its address to WSAStartup , the structure will go out of scope automatically.
Peace!
-=- James.
"Fat people are hard to kidnap."
(Try Check Favorites Sometime!)
|
|
|
|
|
Thanks.
Several members at Anandtech and GameDev mentioned a easy technique. They both implied that call delete only if you have called new.
I will adopt that technique.
Kuphryn
|
|
|
|
|
A good general practice...! Except when dealing with poorly designed hand-off code (e.g. a function that returns allocated memory, and requires you to clean it up, like strdup(...) ).
Code that does that continues to be a problem even today (ever see someone forget to call SysFreeString(...) on an [out] BSTR pointer...?
Peace!
-=- James.
"Fat people are hard to kidnap."
(Try Check Favorites Sometime!)
|
|
|
|
|
Thanks.
I think it no cool that there is code that mishandles pointers.
Kuphryn
|
|
|
|
|
Is there a way for me to set a minimum size that a window can be resized to? I don't want the user to be able to resize the screen smaller than a certain size. Is there a way to set that to a fixed size that the user cannot pass?
|
|
|
|
|
handle the OnGetMinMaxInfo() message
"... and so i said to him ... if it can't dance and you can't eat it either f**k it or throw it away" 8028finder.com
|
|
|
|
|
I tried handling that but am unsure as to how to code for handling the message. I just called the OnGetMinMaxInfo() function and that didn't work. There is no WM_MINMAXINFO message or anything in the class wizard that I can use. Can you tell me how I might code for handling the message?
|
|
|
|
|
The message is called WM_GETMINMAXINFO.
You do not need to call that function, you will create a handler for that message, if you are using MFC that is what it would be called.
When you handle this message, there is a structure called <cod>MINMAXINFO. If you want to set a minimum size for the window, then you would change the value of the ptMinTrackSize parameters to the minimum height and width for your window. Then if the user tries to resize a window, it will not let them go any smaller than the size that you set.
This structure will also allow you to restrict the size and postion of the window.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
I have put CListCtrl(report style) over the CTabCtrl, added a few pages
to CTabCtrl and tried to use it as a kind of dictionary (every page in tabctrl is a one letter). But there is a problem: I drag listctrl
header to the left, then back to the right (but I left the header a bit
further to the right ) and then the listctrl doesn't refresh properly.
I don't have the faintest idea what it's wrong. Thanks for any help and
sorry for my terrible English.
|
|
|
|
|
Does anyone know of any good (preferably online) references for developing Visual Studio Add-ins?
I have a specific add-in I want to develop, for VC6, but I'm not sure how to go about it. My Pre .NET MSDN doesn't seem to be too useful and the post .NET edition seems to be all about automation in Visual Studio .NET
Derek Lakin.
I wish I was what I thought I was when I wished I was what I am.
Salamander Software Ltd.
|
|
|
|
|
Derek, have a look at WorkspaceWhiz http://workspacewhiz.com/WWhizInterface.html and WndTabs + Add-In Communication Library at http://www.wndtabs.com
I think you'll find some Add-Ins here at CP as well.
Hope that helps. What's your add-in do?
Neville Franks, Author of ED for Windows. www.getsoft.com
|
|
|
|
|
Thanks for the links. I have looked at them already and I don't think they would help.
Basically there are a few areas that I need to deal with:
1. Detect when a dialog resource is being edited and show my add-in's toolbar.
2. Find the source file associated with the current dialog resource.
3. Edit the source file according to user actions in the resource editor.
In a nutshell I am developing an approach for adding automatic size/position updating and would like to develop an add-in to go with it that circumvents the developer having to add any code themselves.
I want some add-in development resources so that I can find out if what I want to do is even possible under VC6 and then find out how to do it if it is.
Any more ideas?
Derek Lakin.
I wish I was what I thought I was when I wished I was what I am.
Salamander Software Ltd.
|
|
|
|
|
The only other links I have are:
http://zmanagers.virtualave.net/
http://www.codeproject.com/macro/wwhizinterface.asp#xx25689xx
I haven't written any add-ins myself. You could also do a Google Search. I don't know if MS have ever documented this stuff very well, if at all. I wonder if it has changed in VS7!!
I don't see why you need an add-in to provide the capabilities you are refering to. Their are several article on CP and CG which address this issue. I've also written code in ED to do this automatically. My code works with any dialog and does not require any coding for specific dialogs. It uses a set of simple rules which dictate what controls should move when the user resizes a dialog.
Neville Franks, Author of ED for Windows. www.getsoft.com
|
|
|
|
|
Thanks for the links; they may turn out to be useful for another idea I have if nothing else
I'm well aware that the idea has been done several times before, I just have a slightly different spin on it
Derek Lakin.
I wish I was what I thought I was when I wished I was what I am.
Salamander Software Ltd.
|
|
|
|
|
I have a wizard page created with the CPropertyPage class. I place a bitmap with the dialog editor at position (0,0). When running the dialog, the class places a border around the entire dialog, part of which contains the wizard pushbuttons. Thus my bitmap does not start at the upper left corner, but is offset by about 10 pixels X & Y.
- Does anyone know how I can load a bitmap starting at (0,0) on a CPropertyPage?
- Does anyone know how I can change the text of the Cancel pushbutton on a CPropertyPage?
Thanks in advance,
Bob
|
|
|
|
|
The bitmap is appearing in the correct place: location 0,0 of the Page. If you want the bitmap to appear at location 0,0 on the Sheet (the containing window that holds the buttons and the tab control), I believe you need to draw it manually from within the CPropertySheet -derived class. This is likely to cause problems, however, because the Sheet is not going to know that you are drawing things there.
You can obtain a temporary CWnd pointer for [Cancel] by calling GetDlgItem( IDCANCEL ) from within the CPropertySheet -derived class, after the Sheet proper has been created. Using that pointer, you can move, size, enable, change the text, etc. of [Cancel].
Peace!
-=- James.
"Fat people are hard to kidnap."
(Try Check Favorites Sometime!)
|
|
|
|
|
James,
Thanks for your response. I was able to place the bitmap on the property sheet. The problem is that when the pages get added, they overlay the bitmap. Is there anyway to have the pages added at some offset so they don't overlay the bitmap on the sheet?
Thanks,
Bob
|
|
|
|
|
Not that I know of, but you could place the bitmap/icon at the same location on each of the property pages. That is what I do...
Peace!
-=- James.
"Fat people are hard to kidnap."
(Try Check Favorites Sometime!)
|
|
|
|
|
We use MAKEFOURCC(c1,c2,c3,c4) to create a fourcc.
How can we get the four characters back from the FOURCC?
[VISUAL STUDIO 6.0] [MFC] [WIN98/2]
Bluute tette!
|
|
|
|
|
Use reference parameters or pointers
frisco wrote:
MAKEFOURCC(&c1,&c2,&c3,&c4)
|
|
|
|
|
How did you know to answer frisco's question before he even asked it
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
That's not what I mean.
FOURCC fourcc; (in fourcc there are four characters)
this gives something like this: 880175460
how can i retrieve the four characters from var fourcc?
[VISUAL STUDIO 6.0] [MFC] [WIN98/2]
Bluute tette!
|
|
|
|
|
I guess Prem Kamur needs to refine his psycic abilities
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|