|
I'd rather not do anything that involves hacking up the exe once it's compiled. Talk about a messy build process...
|
|
|
|
|
I'ma C++ newbie, and i'm trying to find a useful occasion where copy constructors can be used. It's quite useless learning the thing and then not knowing when or what to use it for.
MO money, mo problems
|
|
|
|
|
myclass m1 = m2; // implicit call to copy constructor
myclass m1(m2); // explicit call to copy constructor
m1 = m2; // explicit call to operator=
m1(m2); // error if tried here
The compiler will generate a bitwise version of the copy constructor it you do not define your own version. This is ok as long as you class, and its data types, does not contain in allocated data pointers. If they contain data pointers, then you'll have two classes pointing to the data and when one of the class is destoyed the data pointed to is destoyed. What that means, is the data pointer in the class that still exist is now invalid and anything you try to do with it (including freeing it) it will cause problems (probably crash your program). Therefore, you need to create your own copy constructor that allocates memory for its self so you can make a copy of the stored data.
Note what I just said about copy constructors also applies to operator=, except that if you supply a copy constructor and you don't supply an operator=, then the compiler should generate an operator= that uses your copy constructor (instead of a bitwise copy). Therefore, if you supply a copy constructor, you should not need to supply your own operator=.
That should give you a good start at understanding why copy constructors are important. After all, whether you supply your own or the compiler generates one, there is going to be a copy constructor.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
hi everyone..
i have a little problem with UPDATE_COMMAND_UI...it seems to work perfectly in non-dialog based programs but when it comes to dialog-based ones the following are noticed:
1-the OnUpdateFileNew function(which is called by the ON_UPDATE_COMMAND_UI) is not called until my menu item is pressed...it should be called before the item is displayed..
2-the CCmdUI* in the previous function belongs to a weird class called CTestCmdUI which is in wincore.cpp...it should be a pointer to a CCmdUI class in cmdtarg.cpp....
actually i'm new in this update command ui thing so it will be very appreciated to explain more about it to me...
thanx..
|
|
|
|
|
MFC doesn't implement the automatic update of UI elements for dialog based apps.
If you want to have this functionality for a menu in a dialog based application you could do something like the following (it wasn't thoroughly tested and makes use of undocumented functions so, as always, use it at your own risk):
In you dialog class declaration, add the following member:
afx_msg void OnInitMenuPopup(CMenu* pMenu, UINT nIndex, BOOL bSysMenu);
In your dialog's cpp file, make the following changes (change "YourDialog" to the actual class name of your dialog too):
BEGIN_MESSAGE_MAP(YourDialog, CDialog)
ON_WM_INITMENUPOPUP()
END_MESSAGE_MAP()
void AFXAPI AfxCancelModes(HWND hWndRcvr);
void YourDialog::OnInitMenuPopup(CMenu* pMenu, UINT nIndex, BOOL bSysMenu)
{
AfxCancelModes(m_hWnd);
if (bSysMenu)
return;
ENSURE_VALID(pMenu);
CCmdUI state;
state.m_pMenu = pMenu;
ASSERT(state.m_pOther == NULL);
ASSERT(state.m_pParentMenu == NULL);
HMENU hParentMenu;
if (AfxGetThreadState()->m_hTrackingMenu == pMenu->m_hMenu)
state.m_pParentMenu = pMenu;
else if ((hParentMenu = ::GetMenu(m_hWnd)) != NULL)
{
CWnd* pParent = GetTopLevelParent();
if (pParent != NULL &&
(hParentMenu = ::GetMenu(pParent->m_hWnd)) != NULL)
{
int nIndexMax = ::GetMenuItemCount(hParentMenu);
for (int nItemIndex = 0; nItemIndex < nIndexMax; nItemIndex++)
{
if (::GetSubMenu(hParentMenu, nItemIndex) == pMenu->m_hMenu)
{
state.m_pParentMenu = CMenu::FromHandle(hParentMenu);
break;
}
}
}
}
state.m_nIndexMax = pMenu->GetMenuItemCount();
for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax;
state.m_nIndex++)
{
state.m_nID = pMenu->GetMenuItemID(state.m_nIndex);
if (state.m_nID == 0)
continue;
ASSERT(state.m_pOther == NULL);
ASSERT(state.m_pMenu != NULL);
if (state.m_nID == (UINT)-1)
{
state.m_pSubMenu = pMenu->GetSubMenu(state.m_nIndex);
if (state.m_pSubMenu == NULL ||
(state.m_nID = state.m_pSubMenu->GetMenuItemID(0)) == 0 ||
state.m_nID == (UINT)-1)
{
continue;
}
state.DoUpdate(this, FALSE);
}
else
{
state.m_pSubMenu = NULL;
state.DoUpdate(this, state.m_nID < 0xF000);
}
UINT nCount = pMenu->GetMenuItemCount();
if (nCount < state.m_nIndexMax)
{
state.m_nIndex -= (state.m_nIndexMax - nCount);
while (state.m_nIndex < nCount &&
pMenu->GetMenuItemID(state.m_nIndex) == state.m_nID)
{
state.m_nIndex++;
}
}
state.m_nIndexMax = nCount;
}
}
Hope that helps, and please let us know if it worked or not.
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
Hi everybody. I'm a C++ newbie so if my questions seem to shock the life out all you veterans out there plz forgive me. I"m just having problems trying to understand what on earth a copy constructor does or is used for (assuming that it does have a use in our current existing life!) If someone could just give me a clear example(s) on this, I would appreciate it. I would also like a little explanation on what it might (it at all) be used for. Thanxs (again i apologize if my questions seem to ignorant )
Respect nerds, chances are you'll be working for one!
|
|
|
|
|
|
I checked that one out already. Still didn't make sense. Plus somehow my computer's been acting really weired with the online encoding, so im not even sure what i'm looking at is what it's supposed to be (i'm getting extra parenthesis and brackets in unusual locations). Any other suggestions??
|
|
|
|
|
|
Hi,
I am doing a project on win32 threads. I have created a event inside the thread and looping using while() and waitonsingleobject() until the condition is met.
For some reason I have to use thread. I am calling the thread in WM message but I want to wait there itself(where I called the thread) until the thread is finished. How can I do this???
I tried using a global boolean variable setting that to true when the thread is started and to false when the thread is terminated, and creating another evet to wait until this boolean variable becomes false.But it did'nt work very well.my app started hanging...how can i solve this..
Thanks in advance.
|
|
|
|
|
You message loop should run independent of the thread.
Only if your program is terminating should the message loop ever wait on the thread.
If you supply the window handle into a variable the thread can access, the thread can post a registered window message back into your message handler, which your handler can detect, to know that the thread is done processing. Otherwise, the message handler can go about its regular business and your progrma will not appear to be hung.
|
|
|
|
|
Dear Group,
I am trying to get the source (src) of images in web pages. I am using IHTMLElement2 (IE's API) to get the information regarding the html elements. I successfully extracted images, but i dont know how to extract the src of images.
for example: if you have,
then how would you extract "/intl/en_uk/images/logo.gif" using the IE's API !!
I know i can do that by searching through the html source code, and do a similarity match for the word (src) ... that would be too time consuming
does anyone know an easy better way ???
cheers
llp00na
|
|
|
|
|
llp00na wrote:
I am using IHTMLElement2 (IE's API) to get the information regarding the html elements. I successfully extracted images, but i dont know how to extract the src of images.
If you got the IHTMLElement2 for the image tag, try querying for IHTMLElement interface and then using getAttribute() on it.
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
llp00na wrote:
I know i can do that by searching through the html source code, and do a similarity match for the word (src) ... that would be too time consuming
It depends on the size of the page (i.e. the HTML) and whether image links are coded in plain ol' HTML vs. being injected into the document using JavaScript.
See the LinkChecker example in this[^] article. You may be able to use it with almost no code changes.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
|
Hi. Iwant to get the owner name of a file or directory. I hope to get the creators name.
Thus I used the GetFileSecurity to get the file security id and then the GetSecurityOwnerDescriptor to get the account security id. Then, I stack.
According to the manual you have to use the LookupAccountSide specifing two buffers as parameters: One to get the account name and another to get the domain name. Also according to them you need to give the current size of the buffers. The call will fail if one of buffer is not large enough and it will return the correct buffer sizes. It will also fail for other reasons like network failure etc.
Does anyone knows what is the error returned due to a buffer failure? Is it the same error for both buffers or a different one? How many calls do I need until I correct the buffers (by reading the sizes and allocating the buffers) until I get anyothe legitimate failure??
Why MicroSoft, NEVER, NEVER, NEVER documents the possible ways that a function may fail??? Is this a developers friendly company???
|
|
|
|
|
I use something like:
PSECURITY_DESCRIPTOR pSecurityDescriptor;
PSID pSidOwner;
SID_NAME_USE rSidNameUse;
DWORD dwAccountSize,
dwDomainSize;
char *pszAccount,
*pszDomain;
if (GetNamedSecurityInfo(
(LPSTR) lpszObjectName,
SE_FILE_OBJECT,
OWNER_SECURITY_INFORMATION,
&pSidOwner,
NULL,
NULL,
NULL,
&pSecurityDescriptor) == ERROR_SUCCESS)
{
dwAccountSize = 0;
dwDomainSize = 0;
LookupAccountSid(NULL, pSidOwner, NULL, &dwAccountSize, NULL, &dwDomainSize, &rSidNameUse);
pszAccount = new char[dwAccountSize];
pszDomain = new char[dwDomainSize];
if (LookupAccountSid(NULL, pSidOwner, pszAccount, &dwAccountSize, pszDomain, &dwDomainSize, &rSidNameUse) == TRUE)
...
delete [] pszAccount;
delete [] pszDomain;
LocalFree(pSecurityDescriptor);
}
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Thanks. I do not think that the GetNamedSecurityInfo versus a combination GetFileSecurity,
GetSecurityOwnerDescriptor will make much difference. To my view if I have two functions I localise slightly the failure. In the GetFileSecurity I know that I faild to get the file SID whilst with GetSecurityOwnerDescriptor I know I faild to get the owner account SID. Unless the GetNamedSecurityInfo returns a different account SID from the proposed combination.
My real question is again the two calls of the LookupAccountSid. Like your case how do I know that the first one faild due to zero buffer size and not for any other reason (e.g. the file is across the network and the network went down when I was examining, or the file is been deleted and been left with a duggling pSidOwner). Also will one call set both buffer sizes or one of them and then will fail again because the second buffer is still NULL?
Any detailed documentation on the failures will be great.
Its an art to keep things simple
|
|
|
|
|
Dimitris Vikeloudas wrote:
Like your case how do I know that the first one faild due to zero buffer size and not for any other reason
It returns ERROR_INSUFFICIENT_BUFFER .
Dimitris Vikeloudas wrote:
Also will one call set both buffer sizes or one of them and then will fail again because the second buffer is still NULL?
They are both set to the necessary size.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
At a breakpoint I see:
m_pParent = 0x003330d60 {CMainFrame hWnd=0x00060643 {unused=???}}
////
I am passing the MainFrame CWnd object into a constructor and assigning the object to m_pParent.
What I want to know is what the hex values assigned to m_pParent and hWnd mean...and why the values are different? Isn't hWnd a pointer to the Windows window??
Thanks.
Jerry
|
|
|
|
|
HWND is the handle of the window, a reference that is used by Windows to keep track of open windows. m_pParent is a pointer to the CWnd object, I see no reason why they should be the same?
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
m_pParent is a pointer to an MFC CWnd-derived object. That object encapsulates a window and allows you to manipulate it through various methods and properties. One of those properties (member variables) is the handle to the window (hwnd), which is simply a unique id assigned by Windows to each window created. Therefore, your CWnd pointer and its hwnd value are never going to be the same.
Cheers,
Tom Archer - Visual C++ MVP
Archer Consulting Group
"So look up ahead at times to come, despair is not for us. We have a world and more to see, while this remains behind." - James N. Rowe
|
|
|
|
|
Hi,
I created an executable with Visual c++. At some point I had to change the
icon of the file (\res subdirectory). Now, the new icon was immediately
shown on the computer I use to run Visual c++. The problem is on two
computers that are used to evaluate the tool I am developing. No matter
what I do the old icon is used by Windows Explorer and is shown in the
top left corner of the application window.
Now, if I copy the executable file to a server on the network, the new
icon is used by Windows Explorer on some workstations and the old one
on the others. My guess is that a computer gets somehow infected by the
old icon by I can not prove that becose I have run out of Windows
workstations in our network
Regards
Andrej
|
|
|
|
|
voda wrote:
At some point I had to change the
icon of the file (\res subdirectory).
Exactly how did you go about changing it? My guess is that you only changed one of the resolutions (e.g., 16x16) rather than all of them (16x16, 32x32, 48x48).
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Here is a start from MSDN "Customizing Icons":
In this example, the icon is in the c:\MyDir\MyProgram.exe file, with an index of two. The registry entry that assigns the custom icon to all .myp files is as shown here.
HKEY_CLASSES_ROOT
.myp
(Default) = MyProgram.1
MyProgram.1
(Default) = MyProgram Application
DefaultIcon
(Default) = C:\MyDir\MyProgram.exe,2
Finally, call SHChangeNotify to notify the Shell to update its cache.
I am not sure what parameters to use with the SHChangeNotify function. Maybe you can enlighten us when you figure it out?
|
|
|
|