|
What I was reying to imply was the following:
1. He has address of string that was on the STACK of a function which has already returned.
2. If he calls IsBadStringPtr() he will get an answer depending upon if the data happens to hit a NUL byte or not before reaching the end of the stack memory. If he limits the range to the size of the orignal stack variable, it might still return as 'okay', even though we already know technically it is not.
3. The answer should be BAD, but it won't necessarily be bad because that stack memory would probably still be valid AND he might have a NUL byte in there.
So, my final answer is that IsBadStringPtr will let you know if it is truly bad, but it should not ever be used as a test that it is good. In this case it would imply the memory is okay to use, but indeed it is not - you will be overwriting your stack,a nd if you are only reading, you are probably reading code and local variables of another function by now.
|
|
|
|
|
You might find this code snippet I developed interesting:
You can call this to find out if the address is a member of the local stack memory pool or not.
If not, it might be a local function of another thread’s stack, or from the memory allocation pool.
<br />
<br />
BOOL WINAPI IsOnStackOrNot(LPCVOID pObject)<br />
{<br />
BOOL bRetVal = FALSE;<br />
<br />
if( pObject ){<br />
<br />
LPVOID pStack;<br />
MEMORY_BASIC_INFORMATION TheMemoryInfo;<br />
<br />
_asm mov eax, esp;<br />
_asm mov pStack, eax;<br />
<br />
if( sizeof(TheMemoryInfo) <= VirtualQuery(pStack, &TheMemoryInfo, sizeof(TheMemoryInfo)) ){<br />
if( ((DWORD)pObject >= (DWORD)TheMemoryInfo.BaseAddress) &&<br />
((DWORD)pObject <= ((DWORD)TheMemoryInfo.BaseAddress + (DWORD)TheMemoryInfo.RegionSize) ) ){<br />
bRetVal = TRUE;<br />
}<br />
}<br />
}<br />
<br />
return bRetVal; <br />
}<br />
<br />
If you also compared address to CURRENT value of ESP and EBP, you could probably deduce if it is a local variable, a parameter, or something from a PREVIOUS function call's stack.
|
|
|
|
|
In function foo , the pointer you are returning points to a temporary stack string that goes out of scope when the function returns. You need to allocate memory on the heap using new and then return this pointer. Of course, now you'd need the caller to manually delete the string.
|
|
|
|
|
"some text" gets placed on the stack. it will remain there until the next function call. when cout is called, it places the arguements on the stack and will overwrite part of "some text". if you make the array a const or static it will go in the code or data segment (not the stack) and it will remain.
Just livin a dream.. dont wake me!
|
|
|
|
|
I'm writing an app that I want to be able to dynamically move some controls around on my dialog box. I was thinking of simply using ::GetWindowRect() and ::MoveWindow() to do that, but for those functions I need the window handle (HWND). Can the member variable connected to those controls work as the window handle, or houw can this be done?
Danny
|
|
|
|
|
bugDanny wrote:
Can the member variable connected to those controls work as the window handle, or houw can this be done?
Why not just use CWnd::GetWindowRect() and CWnd::MoveWindow() ? No handle required.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
You can use control variable associated with it.Alternatively ,Use GetDlgItem() for getting control windows and use those.
|
|
|
|
|
Depending on what you want to do, there is also some nice articles on here for dynamically moving all controls when resizing dialogues.
I tend to map controsl to control variables and use their own move methods, eg:
m_btnOK.MoveWindow(...);
Rather than:
pWnd = GetDlgItem(IDOK)
if(pWnd != NULL)
pWnd->MoveWindow(...)
Mapping variables to the controls uses less code and no need to worry about correct id values, null pointers etc.
HTH.
Andrew
|
|
|
|
|
Most controls are directly derived from CWnd, in which case you can use the CWnd member function of ::GetWindowRect() and ::MoveWindow() , meaning :
RECT rect;
m_mycontrol.GetWindowRect(&rect);
If you absolutley want to use the upper scope functions, you can retrieve the HWND using GetSafeHwnd()
HWND hWnd = m_mycontrol.GetSafeHwnd()
BTW, you might want to consider also GetClientRect() , as well as ScreenToClient() and ClientToScreen() to play around moving controls, because I am afraid that the two functions you mentioned will not be sufficient.
Hope this helps,
~RaGE();
|
|
|
|
|
|
Hi All
I am making an application in which I have to insert the values into the tree recursively.
I have been stucked that how should I do this?
I am using CTreeCtrl class of MFC for tree control.
So Please help me ...
Thanks.
|
|
|
|
|
Recursion simply means that a function calls itself. What are you populating the tree control with?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Infact I want to insert a node into the tree
- Then all the subnodes of that node will be called recursively and being inserted into the tree.
What I am doing is as follows
<br />
<br />
Now I want to insert all the local folders of Outlook Express into the tree as it looked into the Outlook Express .
But The tree from this code is not resembling to that one.
So please tell how should I modify programm to look like Outlook Express.
From the code it is clear that it enumerates all the folders & subfolders of outlook exress , So I want to display it in the tree form.
Note that
"m_pStoreNamespace is the object of Interface IStoreNameSpace"
Please reply.
|
|
|
|
|
I see you are using code from this article. So what exactly is or is not happening? Does the tree control get populated at all? Are items missing? Is the hierarchy wrong?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Ya I am using sample from the link You have mentioned.
As I told I want to insert the folders & subfolders of the outlook express in the order as it is in outlook express to make user interface better, as in the article values are inserted into listbox.
So please suggest me.
Thanks
|
|
|
|
|
rajeevktripathi wrote:
As I told I want to insert the folders & subfolders of the outlook express in the order as it is in outlook express...
If the items are being inserted correctly but are just in the wrong order, it sounds like you need to add the items to some data structure first, sort them, and then add them to the tree control. If that does not sound right, you'll need to better explain what your program is doing that is not right (that's why I asked those other three questions).
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
HI!!
for developing a download manager utility... i will have to use reliable udp to ensure that packets are not lost and are deliv'rd in proper order.... how do i implement it?
V.G
|
|
|
|
|
Hi,
You cant ensure that messages sent over UDP will arrive in the order they were sent in, however, you can add an int (order) to the message structure indicating the order of the sent message, then you can re-arrange these messages according to that number.
To ensure that all messages arrive, implement a hand shaking mechanism. Something like:
1. Send a Message to the other end.
2. Mark it as "did not reach" i your program.
3. If the message reaches its destination, the destination sends an acknowledgment
4. After a predefined timout, if no acknowledment arrives, resend the message with the same order.
Good luck
|
|
|
|
|
Previously, I have an ActiveX control which I use it in my MFC GUI program.
The wrapper class (inheritanced from CWnd) for the activex control is generated automatically through class wizard. Everything just work fine.
Now, I need my application to work in non-gui mode. Hence, no dialog or windows will be created to host the active x control.
I just copy the ActiveX wrapper class file, which is generated previously, into my console project. i realize that a runtime error will occur whenever i try to use the active x control. this is because there is no dialog/ or windows to host that activex control.
I read an article at http://www.codeproject.com/com/consoleactivex.asp
The author shows the way by using COM. However, i am not familiar with COM. I prefer to use back the wizard generated wrapper source code, which is much more easier.
may i noe how can i solve this problem? do i need to created a hidden window for it? or is there better way?
thanks!
cheok
|
|
|
|
|
Use the class wizard to generate a wrapper class, not derived from CWnd, but from COleDispatchDriver.
In ClassWizard click Add Class then select From a type libary and select the .tlb file of your control.
After you have the wrapper class call CoCreateInstance to create the object, something like:
IDispatch* pDisp;
CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, dispid, &pDisp);
where clsid is the class id for the object, dispid is the ID of object's IDispatch interface
After a successful call of CoCreateInstance use the AttachDispatch method from the wrapper class and then you can call ActiveX methods, like this:
CWrapperClass myDisp;
myDisp.AttachDispatch(pDisp);
myDisp.SomeActiveXMethod();
Remember to call CoInitialize before CoCreateInstance and when you're done using the object call pDisp->Release() in order to decrement the object's reference count and destroy it.
|
|
|
|
|
Thanks. Using COleDispatchDriver as parent class really work!
I didn't use AttachDispatch since I cann't make it works. Most probably I miss out something. However, by using CreateDispatch just rock I assume there is no clean up needed after CreateDispatch from the MSDN example.
Thanks for help!
cheok
|
|
|
|
|
This component is produced by Giga.INC. Please give me some information and suggestion of this. Thanks!
|
|
|
|
|
Respected all
I have picturebox on my DialogBox(Dialog based MFC app) ,, when I run my prog, the bitmap displayed on picture box but when the size of bitmap s max then problem r coming b/c the Dialog boc which have a picture box has its feault sizze so how i can change the size of dialog box to its max, size.
so that no problem to me while to display large bitmaps.
Thanking u people
david
|
|
|
|
|
Recommend reading the articles at CP on resizable dialogboxes.
I also recommend that you write your questions in english; I lost you at "s max", "r", "Dialog boc" and "feault sizze", so I have no idea if my interpretations where even close to correct.
INTP
Every thing is relative...
|
|
|
|
|
Try ShowWindow(SW_MAXIMIZE). Look up ShowWindow on MSDN for all kinds of other uses.
Danny
|
|
|
|