|
First off:
An application must not delete a device context whose handle was obtained by calling the GetDC function. Instead, it must call the ReleaseDC function to free the device context.
Secondly
You have to restore the HDC when using SDK type DC's
With MFC i don't think you have this problem.
Yes it's a GDI leak, use VC++ stress utility and watch the GDI values drop like mad. I don't think BoundsChecker checks for these kind of memory leaks...I don't have and never used it, only know what i've read.
Cheers
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
If i do ReleaseDC() also , i have the problem.
I have VC++ 6.0.But in tools i didn't find any stress utility.
Thanks
Neha
|
|
|
|
|
Visual C++ tools menu and you didn't find stress...?
Which version of C++ are you using...
Anyways...Windows 98 comes with (if you install it) resource meter, this should do the same trick.
Even if you call Release it'll still leak, yes...I only pointed that out cuz...well MSDN says so...so do it!
You have to restore your original HDC object
I'm tired and i dunno if i can remember correctly, it's been a while since i programmed SDK...
HDC hdc = ::GetDC(this->m_hWnd);
HGDIOBJ oldBrush = SelectObject(hdc, color);
SelectObject(hdc, oldBrush);
DeleteObject(color);
Sorry I had to refer to some old code, you MUST restore the old object back to original state or you will leak.
If this doesn't work...Then i'm gonna need to know more...
Cheers
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Correction this leakage will ocurr in MFC...so always restore your objects.
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
If you're using pens or brushes, not restoring them results in instant memory leak also. As has been suggested, use the W98 resource meter to see where your GDI resources are going. If you have W2000 or XP, you won't get the problem, the OS plugs the leak for you.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
Thanks all for the replies...
I got the problem fixed ...
Neha
|
|
|
|
|
HockeyDude wrote:
I don't think BoundsChecker checks for these kind of memory leaks
Boundschecker does I think. It reports a list of all resource leaks after the program terminates. It can't do it while the program is running.
Roger Allen
Sonork 100.10016
If I'm not breathing, I'm either dead or holding my breath.
A fool jabbers, while a wise man listens. But is he so wise to listen to the fool?
Please step to the rear of the car and make room for more victims. - John Simmons the Outlaw programmer, 1st Feb 2002, in the lounge
|
|
|
|
|
Aren't I glad I said i don't think...
I read an article on CodeGuru...basiaclly explaining how BoundsChecker is crap and the same can be accomplished with _CrtDebug memory functions.
I've never used it...so i'm unaware of it's abilities..i was only going on what someone else had said. My mistake..
Cheers!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
I am new to templates in C++. Say I have declared Vector<int> in first.cpp and also in Second.cpp. Does the compiler generate two Vector<int> implementation ?. If so is there any way I can force the compiler to generate just a single implementation.
Thanks
|
|
|
|
|
It works exactly the same as if you had two instances of a non-templated class.
The template code bloat is that the compiler needs to generate new classes for each DIFFERENT template parameter it is used with.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
|
It is the linker's responsibility to strip off duplicates across compilation units, so in general there'll be only one implementation.
Code bloat can stem from another reasons:- instantiating
vector s (or other template classes) of many different types
- code bloat resulting from massive inlining
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Joaquín M López Muñoz wrote:
code bloat resulting from massive inlining
Although I'll point out that inline is a suggestion to the compiler, not a command. If you inline stupidly, the compiler will ignore you.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
How can I get the WebPage's Last Modified Time.
Following is my code,but it doesn't work properly.
::HttpQueryInfo always return FALSE. Why?
BOOL CChkOlDlg::IsUrlModified(CString strUrl)
{
BOOL bRet = FALSE,bSucc = FALSE;
HINTERNET hSession ;
hSession = ::InternetOpen(_T("CheckOl"),
PRE_CONFIG_INTERNET_ACCESS,
_T(""),
INTERNET_INVALID_PORT_NUMBER,
0 ) ;
if(hSession)
{
HINTERNET hConnect = ::InternetConnect(hSession,
GetServer(strUrl),
INTERNET_INVALID_PORT_NUMBER,
"",
"",
INTERNET_SERVICE_HTTP,
0,
0);
if(hConnect != NULL)
{
HINTERNET hHttpFile = ::HttpOpenRequest(hConnect,
_T("GET"),
strUrl,
HTTP_VERSION,
NULL,
0,
INTERNET_FLAG_DONT_CACHE,
0) ;
if(hHttpFile != NULL)
{
BOOL bSendRequest = ::HttpSendRequest(hHttpFile, NULL, 0, 0, 0);
if(bSendRequest)
{
char bufQuery[32] ;
DWORD dwLengthBufQuery = sizeof (bufQuery);
BOOL bQuery = ::HttpQueryInfo(hHttpFile,
HTTP_QUERY_LAST_MODIFIED,
bufQuery,
&dwLengthBufQuery,
NULL) ;
if(bQuery)
{
bSucc = TRUE;
}
}
VERIFY(::InternetCloseHandle(hHttpFile));
}
VERIFY(::InternetCloseHandle(hConnect)) ;
}
}
if(!bSucc)
{
}
return bRet;
}
|
|
|
|
|
Possibly because web servers rarely send out the last modified information in the header of an HTTP response.
Test this with telnetting to your host on port 80 and issueing your GET (or HEAD) request manually. Is the info there?
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
Other Severs don't work also.
I use HTTP_QUERY_DATE and HTTP_QUERY_VERSION, ::HttpQueryInfo works OK.
Using HTTP_QUERY_CONTENT_LENGTH,::HttpQueryInfo return a wrong size of the page.
Using HTTP_QUERY_LAST_MODIFIED,::HttpQueryInfo doesn't work.
|
|
|
|
|
C:\Windows\Desktop\Project2\Project.cpp(383) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type '' (or there is no acceptable conversion)
Error executing cl.exe.
here is the code!
ostream& operator << (ostream& s, Market& market)
{
for(int i = 0; i <10; i++)
{
s <<"Stock information: "<< market.stockArray[i].getCompanyName()<<" "<<market.stockarray[i].getstockticker()<<" "<<market.stockarray[i].getmarkettraded()<<"="" "<<market.stockarray[i].gettypeofmanufactr()<<"="" "<<market.stockarray[i].getinitialvalue()<<"="" "<<market.stockarray[i].getnumofoutshares<<endl;
="" return="" s;
="" }
}
<\pre="">
thanks
|
|
|
|
|
takes a right-hand operator of "... what?
Presumably one of the items you're trying to push into the stream is not a basic type, or is of a type that doesn't have << defined.
Try breaking your statement up a bit and you should find out which one is causing the problem:
s << "Stock information: ";
s << market.stockArray[i].getCompanyName();
s << " ";
etc...
------------------------
Derek Waters
derek@lj-oz.com
|
|
|
|
|
This code cannot work. How can you have a loop, and return s in the first iteration ?
Anyhow, this code has some other issues. First of all, you need first to check the stream state. Second of all you need to create a sentry instance to perform prefix and postfix operations. Lastly, this code will not work with formating operators. The way I do it is to stream my data to an ostringstream, then pass it in one go to the ostream passed in. Here is an example
template<class chart,="" class="" traits="">
std::basic_ostream<chart, traits=""> &
operator << (std::basic_ostream<chart, traits=""> & os, const RECT & rc)
{
//Check stream state first
if (!os.good()) return os;
// Create sentry for prefix operations ( it's destructor will carry out postfix operations )
typename std::basic_ostream<chart, traits="">::sentry opfx(os);
if (opfx)
{
std::ostringstream str;
str << "left: " << rc.left;
str << " right : " << rc.right;
str << " top : " << rc.top;
str << " bottom : " << rc.bottom;
str << " width : " << rc.right - rc.left;
str << " height : " << rc.bottom - rc.top;
os << str.str().c_str();
}
return os;
}
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
How do I intercept the command "net send" to remove the name of the user that did the sending in the remote pc's dialog box.
By this i mean somehow finding the HWND of that window and dynamically changing the text at the top of the dialog before
it is sent via a socket
-
|
|
|
|
|
How about this?
HWND hWnd;
HWND hStatic;
hWnd = ::FindWindow(NULL, "Messenger Service ");
if (hWnd)
{
hStatic = ::FindWindowEx(hWnd, NULL, "Static", NULL);
}
Cheers,
/Fredrik
Sonork ID: 100.11430:PhatBoy
|
|
|
|
|
Is it bad programming practice to use properties in your ATL components.
I mean which of the two is better :-
(1) Function(arg1, arg2, arg3)
(2)
arg1=100
arg2=100
arg3=200
Function()
The reason why I'd like to use properties is that I am planning to write some components for use from ASP. And the normal ASP/VB way is to use properties, I think so anyway.
Any ideas or suggestions on this are appreciated.
Thanks in advance.
Nish [ATL newbie]
Nish was here, now Nish has gone;
He left his soul, to turn you on;
Those who knew Nish, knew him well;
Those who didn't, can go to hell.
I like to on the Code Project
Sonork ID 100.9786 voidmain
www.busterboy.org
|
|
|
|
|
I would say (and, to state again, this is only MY opinion)...
Only use a property if:
a) It is going to be persistent (stored with the object) or
b) It is used in more than one method in the object.
Use parameters if the values are only going to be used in that method, otherwise you're incurring the penalty of making COM calls for each parameter and then the method as well.
So, I think you can read that as suggesting parameters.
Also, in ASP you can quite happily use parameters, just like a Sub.
MyObject.MyMethod "Parameter 1", viParameter2, "Some Other Parameter"
------------------------
Derek Waters
derek@lj-oz.com
|
|
|
|
|
Derek Waters wrote:
Use parameters if the values are only going to be used in that method, otherwise you're incurring the penalty of making COM calls for each parameter and then the method as well
Thanks a lot Derek. That was very useful.
Nish
Nish was here, now Nish has gone;
He left his soul, to turn you on;
Those who knew Nish, knew him well;
Those who didn't, can go to hell.
I like to on the Code Project
Sonork ID 100.9786 voidmain
www.busterboy.org
|
|
|
|
|
With properties your component acquires state, so maynot scale well when deployed in MTS where Just in Time activation and ASAP deactivation help in improving throughput. Also if the components are deployed in remote machine or as out of proc components, look at the extra marshalling, network calls.
|
|
|
|