|
You can't.
Well, not without keeping some extra information anywhere.
Really this is a design problem, not an implementation problem - it's good practice to allocate and free memory at the same level of a program, so that level already knows how it allocated the memory.
For example
char* str = new char[100];
somefunction(str);
delete[] str;
char* str = "Hello world";
somefunction(str);
// No need to delete anything
The point is that "somefunction" didn't allocate the memory so it can't know how to free it and shouldn't try.
Basically whenever you allocate some memory you need to think about how it's going to be freed, and ensure that it's done at the same level as it was allocated, which is probably the only place that knows how to do it.
|
|
|
|
|
You may want to try with IsBadWritePtr . Do some experimentations with it to see how it handles strings (literal and dynamically-allocated strings).
Michel
It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
- TreeBeard
|
|
|
|
|
Or, just
try{ delete[] str; } catch(...){}
...make it about Visual C++, and don't ever mention Visual Basic. Nick Hodapp (MSFT) in Semicolon[^]
|
|
|
|
|
I used to code java like that! Does it work for c++ too?
[VISUAL STUDIO 6.0] [MFC] [WIN98/2]
|
|
|
|
|
Try
const LPCSTR str = _T("test");
and when the compiler complains about const do as it says. Don't cast the const away
Todd Smith
|
|
|
|
|
I want to print a page which has predefined area, so that the printer prints the content which is in the defined area.Say for example, a document usually has 32x13 inches ruler. we predefine the size to 8x11 inches area of the document. we actually need to print the content of the 8x11 inches?
any help will be greatly appreciated. i desperately need this info. please send reply to vgkotha@rediffmail.com
thanks in advance,
from
venu:confused
|
|
|
|
|
Do you mean you want to print to a selected area of the page?
If you do, override the OnPrepareDC() function and modify the pInfo->m_rectDraw member var to limit the printable rectangle to your app to the area of interest.
You can do that by using something like:
pInfo->m_rectDraw.left = pDC->GetDeviceCaps(LOGICALPIXELSX) * inches_offset1 ;
pInfo->m_rectDraw.top = pDC->GetDeviceCaps(LOGICALPIXELSY) * inches_offset2 ;
And so on...
Roger Allen
Sonork 100.10016
I think I need a new quote, I am on the prowl, so look out for a soft cute furry looking animal, which is really a Hippo in disguise. Its probably me.
|
|
|
|
|
Hi all,
I use IDiskQuotaControl->FindUserName() and IDiskQuotaControl->AddUserName() to add quota entry to a network shared volume for every user.
But There are miss match of the function parameters between the Visual studio promotion and the search result of F1 help.
The Visual studio promotion after I type the funciton name and the "(" is:
///////////
HRESULT FindUserName(LPCWSTR pszDomain,
LPCWSTR pszName, PDISKQUOTA_USER **ppUser);
/////////
but when I search use F1 help:
the result is:
///////////////
HRESULT FindUserName(
LPCWSTR pszLogonName,
PDISKQUOTA_USER *ppUser
);
Then I tried the first function. compile and link ok but when execute to it, a Debug Error! occurce:
/**************
Debug Error!
Program: ***
Module:
FIle:i386\chkesp.c
Line: 42
The value of ESP was not properly saved across a funciton call. This is usually a result of calling a function declared with one calling convention with a funciton pointer declared with a different calling convention.
***************************
I suspect that the error was caused by the reson that there are two functions one is we used and can compile and link but the real function in some dll is the other one.
But when I use the second one in code, it can not be compiled. say the this funciton does not take two parameters.
And the same situation with the AddUserName()
Does any one know how to sovle this problem?
Thanks very much for your help.
Laura.
Bu
|
|
|
|
|
This is a general problem for me that I've still not worked out properly even though I've been hitting it for the last couple of years. Reading files with CArchives I can never stop them reading too much of the file and causing a GPF. An example for just now would be I'm using CSockets, so I've got a CSocketFile and a CArchive object as well. I'm using it as part of an ftp client and at the moment its at the point of logging in to the ftp server. There is a big(20 line) welcome message on the server so I need to read this data from the CArchive. When I do a straight
archivein >> stringtxt;
I only get the first 3 lines of the welcome message. When I try
while(!archivein.IsBufferEmpty())
{
blah;
}
I get that the buffer is always empty so it never goes into the loop. As a last resort I tried changing it to make sure it looped.
while(archivein.IsBufferEmpty())
{
blah;
}
I know that code is wrong but it got into hte loop at least but obviously it went into an infinite loop so it was useless.
I tried using archivein.ReadString() but this always causes GPFs. A basic example is.
while(receivedFromServer = archivein.ReadString(buffer,100))
{
blah;
if(receivedFromServer == "")
return;
}
but that just totally craps out on me
Any hints on generally dealing with CArchives, using CArchives with CSockets or with reading files in general.
thanks for reading the most obscure and confused question ever
|
|
|
|
|
If I have a button, and made an OnButton function for it by dbl clicking the button in design view, and then I want to delete it what all needs to go in the code? I see thats theres reference to it in the gray regions of the code(message maps etc), and one time I deleted something from the gray area and the app got destroyed. So do we or do we not delete stuff from the 'gray'areas?
Thanks,
ns
|
|
|
|
|
u do, if u attached a member variable to it, search for all the occurence of it and kiss her goodbye!
Papa
Murex Co.
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
So the following is not a cause for concern? I am free to go and comment out lines in the gray areas? I tried it on a very simple app and it seems to work, but I am afraid to try it on my mainproject.
BEGIN_MESSAGE_MAP(CEnchangeView, CFormView)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
<code>
ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
Thanks,
ns
|
|
|
|
|
AFAIK, deleting the function in ClassWizard deletes its message map entry.
But if you WANT to do it by hand but are afraid to confuse VisualStudio, you can always close your project and do it with an editor from 'the outside'.
|
|
|
|
|
If you're using VC6, select 'OnButtonTest' function in ClassView, open context menu and select 'Delete'. This will delete OnButtonTest declaration in .h, its definition in .cpp and message map entry as well.
Tomasz Sowinski -- http://www.shooltz.com
*** Vodka. Connecting people. ***
|
|
|
|
|
You can delete it manualy - delete the handler definition from h and cpp files
and also the binding from BEGIN_MESSAGE_MAP/END_MESSAGE_MAP section in cpp file (ON_BN_CLICKED).
If you don't want to edit wizard generated sections of code do (In VC6):
Go to the class wizard, make sure the dialog class is selected,
in Message Map tab see the Member function listbox.
Select your OnButton handler and push Delete function.
Note that you need to delete the implementation of the handler in cpp file manualy.
Pavel
Sonork 100.15206
|
|
|
|
|
For a modeless launch, I get a pointer to the window, so I can senmessage it with that.
But for a modal dialog when I do
CMyDialog myDialog;
myDialog.DoModal()
and then want to send a message to myDialog, will I do this?
<code>CMyDialog* p = &myDialog;
p->SendMessage</code>?
I'd check it out myself in code, but cant right now....
Thanks,
ns
|
|
|
|
|
u can send a message to anything derived from CWnd using this method
If u wanna send to another dialog, u can get its a pointer from FindWindow
Papa
Murex Co.
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
I'm looking up FindWindow right now...
You cant use it to find a window in another app right? It wouldnt know the classname etc....
Thanks,
ns
|
|
|
|
|
if u need to find a child window within a parent window u can use FindWindowEx providing the Window Handle of the CWnd named m_hWnd.
In order to know the class name u can see the output of Spy++ or do like he does! There's even an article on CP that does that!
Papa
Murex Co.
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
You cannot send a message from the same thread because DoModal won't return until the dialog is closed.
The opinions expressed in this communication do not necessarily represent those of the author (especially if you find them impolite, discourteous or inflammatory).
|
|
|
|
|
Hi,
I have two PCs and like to see if both have same service packs installed. Where can I find this information in VC6? thanks
|
|
|
|
|
|
I want to use CRecordset and CDatabase classes to open MDB files without registering them on DSN. HOw can i do that and what possible compatibility issues will there be.
In my dream, I was dorwning my §orrow§
But my §orrow§, they learned to §wim
|
|
|
|
|
Using CDaoRecordset isn't an option?
Tomasz Sowinski -- http://www.shooltz.com
*** Vodka. Connecting people. ***
|
|
|
|
|
http://www.codeproject.com/database/excel_odbc_write.asp
Papa
Murex Co.
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|