|
I'm still pretty new to GDI programming, but it was my understanding that as long as I select the original GDI object back into the DC, the resource would be cleaned up properly when it goes out of scope ( I am not using pointers for these objects ). What I don't understand is why the GDI resouce count ( in the Task manager under Windows 2000 ) shows the GDI resouces growing to an unmanageable amount in a very short period of time ( e.g. 2,000 in under a minute of program execution ).
Here's what I've done. I have a multi-threaded application that draws bar graphs to the screen (among other things, but we'll just focus on the bar graphs). One thread reads data from the serial port and writes it to a global data structure. A draw thread then gets notified that it has updating to do and it reads data from that data structure. That draw thread then calls Draw() on a global bar graph container object.
I have created a bar graph library that abstracts the bar graph functionality. The container class I mentioned above (CObject inherited), holds four bar graphs and is responsible to update internal data of each of the graphs. One of these container objects is used throughout the program and is global. I call Draw() on this container class (passing it a DC) both in the view's OnDraw and also in a secondary draw thread (as mentioned above) (CWinThread inherited). I synchronize access with a critical section. I think that the problem is in this global class.
Is there something about global classes that I am not taking into account here when it comes to GDI? My GDI objects that I create are created in the scope of the function (method) and not in the the class scope (e.g. m_gdiObjectName ).
Any suggestions would be helpful ( I hope I've been clear enough ).
Thanks.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
For all of the GDI objects that you create, are you calling DeleteObject on them, and DeleteDC or ReleaseDC for the device contexts that you create.
Because part of allowing the GDI objects to properly destroy is to replace the original objects into the DC, because this frees the objects that you created to be properly destroyed.
You should always destroy the objects that you explicitly create.
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!
|
|
|
|
|
According to the GDI source code, the destructor of each of the GDI objects should be doing this for me. The destructor calls this:
BOOL CGdiObject::DeleteObject()
{
if (m_hObject == NULL)
return FALSE;
return ::DeleteObject(Detach());
}
My objects are all created without using new and should be destroyed when they go out of scope. It doesn't appear that they are.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
Sorry, I forgot that you were using GDI wrapper objects. So if you set a break point in the destructor for your objects, are the objects being deleted properly?
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!
|
|
|
|
|
Yep. They're getting deleted. I'm stumped here.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
I want to use CSockets to send a file(text file) across a network. One program is the server, and the other is client(of course). What is the easiest way to do this?
|
|
|
|
|
Microsoft has a really good example of this. Go to http://support.microsoft.com/default.aspx?scid=kb;EN-US;q175668. This example will work running both client an server on the same machine, but you could very well move the server to another machine on your network and see it work over a network.
Best Regards and good luck.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
Look up TransmitFile declared in Mswsock.h
MSDN ___
The Windows Sockets TransmitFile function transmits file data over a connected socket handle. This function uses the operating system's cache manager to retrieve the file data, and provides high-performance file data transfer over sockets
___ MSDN
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
If he use TransmitFile... how does the other side receive the file then!?
Rickard Andersson@Suza Computing
ICQ#: 50302279 (Add me!)
E-mail: nikado@pc.nu
I'm from the winter country SWEDEN!
|
|
|
|
|
Rickard Andersson wrote:
If he use TransmitFile... how does the other side receive the file then!?
Unfortunately there is no ReceiveFile
So we'll have to recv() the entire data .
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
Nish - Native CPian wrote:
So we'll have to recv() the entire data .
Aaargh!
Rickard Andersson@Suza Computing
ICQ#: 50302279 (Add me!)
E-mail: nikado@pc.nu
I'm from the winter country SWEDEN!
|
|
|
|
|
I may have to kill you. That totally freaked me out. I was thinking "Oh Crap! Where is that backup CD?".
Good laugh, though. How did you do it?
|
|
|
|
|
|
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
Nice little piece of JavaScript!
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!
|
|
|
|
|
lets see you create real blue screen ?????????????????????????????
nice try.
Aizik Yair
Software Engineer
|
|
|
|
|
Hi
I have created a new dialog project. Now I want to add that PROJECT into an exitsting project's workspace. I can do this but the dialog project outputs a .exe file. How do I change this to create a .lib file so I can link correctly??
---
|
|
|
|
|
It doesn't really work that way. You'll need to create a "Win32 Static Library" ( File | New... in Visual Studio ). Once you've done so, you'll have a library project to work with. When compiled it will build a .lib file. This project is where you'll have to create your dialog and related class. It is possible to move your existing .cpp and .h file for your dialog into a static library such as this, but doing so is a bit of a pain. You will probably have to copy resouce code (from the .rc file) to a .rc file in the static library project. Making all the connections then is a bit tedious. Once you do have this library built, you will have to change the project settings in the main project so that it knows where to find your new library. I hope this helps steer you in the right direction.
Good luck.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
Hi.
I have a char * to a data buffer. What is the best way to assign data from char * into a CString object? For example:
-----
// char *myChar = new char[10];
// memcpy(myChar, "abcdefghij", 10);
// CString myString;
-----
What is the best say to insert data from myChar into myString?
Thanks,
Kuphryn
|
|
|
|
|
CString myString(myChar);
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
|
Um.. the best way is to pass the argument to the constructor, so that the string is constructed and assigned in the one go. Of course the REAL answer to the question is to avoid C style strings where-ever possible..... :P
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
|
|
ahhhh. Yeah. In my final code (working version), I had to allocate one additional byte for the null-terminator.
Kuphryn
|
|
|
|