|
We had this very same kind of problem in one of our apps. We knew it was caused by a resource leak, but I had spent weeks trying to fix it. All GDI objects I allocated were check/destroyed etc, but it still persisted until quite recently when we found the culprit:
SHGetFileInfo(path, 0, &fileinfo, sizeof(fileinfo), SHGFI_ICON | SHGFI_SMALLICON | SHGFI_SHELLICONSIZE);
It seems that this system procedure allocates an icon that you need to destroy yourself. If your using this call make sure you call the corresponding DestoryIcon() on the member var listed in the MSDN fo a SHFILEINFO object.
Roger Allen
Sonork 100.10016
In case you're worried about what's going to become of the younger generation, it's going to grow up and start worrying about the younger generation. - Roger Allen, but not me!
|
|
|
|
|
Thank you very much.
I do appreciate your advice.
I have gone thru your suggestions.
All code are implemented the correct way, i.e all are destroyed afterwards except for one occurence. This i have corrected but the problem still remains.
An interesting comment by someone else is to monitor the GDI Objects in Task Manager. I however are unable to activate it in NT. Any advice here.
Thanks.
Louis
|
|
|
|
|
I've had this same problem myself. You have a resource leak (as others have noted). If you want to debug your resource consumption, you can use the task manager. Now, I'm not sure that this is the same in NT, but under Win2K open the Task Manager and select the "Process" tab. Then click the "View | Set Columns..." menu item. In the resulting dialog, make sure you have "GDI Objects" checked and click "Ok". Now, run your application and watch the "GDI Objects" column. You will, in all liklihood, see your object count go up to something like 8000 or 9000 and then crash. At least that's what happened to me.
As others have noted you need to release your resources when you're done using them including any new DCs you've created. Make sure you call ReleaseDC on any new DCs you've created with CreateCompatibleDC, or any other DC creation mechanism, when you're done with it. This is where the vast majority of my problems were. Once I fixed them all, my app only used 34 GDI objects (on average).
Hope this helps.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
Hi Everybody,
I work in VC++(MFC). I wish to block the internet access of a machine. The machine can be connected to the internet through a dial up connection or a cable internet connection. Can anybody help me in achiving this.
Thanking all in anticipation.
Regards,
Onkar
|
|
|
|
|
I think that you're asking this question in the wrong forum. Actually, I'm not so sure that you've got the right web site. Your question relates more to networking--specifically IP filtering. This type of thing is usually accomplished with hardware such as a router. If you don't have control over the hardward or the network domain, I think that you're out of luck. I personally use a Linksys cable/dsl router that provides IP filtering on the firmware. This allows me to determine which IPs can surf the internet and which can't.
This could probably be accomplished by writing code and puting a computer running that code between the computer you want to block and the internet, but why would you want to do that. Decent hardware to accomplish the same is cheap.
Anyhow, I think you've got the wrong forum. Good luck, though.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
For a dialout connection, I guess you could just keep the port
on which the modem is attached open (hence unavailable).
For a NIC, hmm... maybe you could open
every socket (all 65536 of them)
and keep them open as well?
|
|
|
|
|
int WideCharToMultiByte(
UINT CodePage, // code page
DWORD dwFlags, // performance and mapping flags
LPCWSTR lpWideCharStr, // wide-character string
int cchWideChar, // number of chars in string
LPSTR lpMultiByteStr, // buffer for new string
int cbMultiByte, // size of buffer
LPCSTR lpDefaultChar, // default for unmappable chars
LPBOOL lpUsedDefaultChar // set when default char used
);
cchWideChar is int so it must less than 65535.But I have BSTR the data is large than 65536. How can I convert to char.
Pz give me some hints.
THX.
|
|
|
|
|
It's a short that needs to be less than 32767, or 65535 if it is unsigned.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
O. yes.int needs to be less than 32767. Then it more hard to convert WideChar to MultiByte. Have any way to do this ?
|
|
|
|
|
*short* needs to be less than 32767. int needs to be less than 65535 * 32767. Have you tried it ?
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
char* fname;
int n_n = MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,fname,-1,NULL,0);
LPWSTR yty; yty = (LPWSTR)malloc(n_n * sizeof(WCHAR));
MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,fname,sizeof(fname),yty,n_n);
|
|
|
|
|
Hi
Has anobody tried to use the "Microsoft Forms 2.0 Frame Control" in VC++? It seems to not work properly when I call the property "GetObject": it gives me a useless Idispath because I can't access to the props and methods of the control. This only happen when inserting a custom control (the Calendar control for instance)in the Frame control.
Any clue?
|
|
|
|
|
Hello,
I have to get the value of the an Excel cell into a stand alone MFC app.
The excel file is already opened. I do not need an excel file reader.
What I'd like is to connect to an already opened xl and periodically read a specific cell.
I have no clue where to start from what technology to use.
Any direction/hint/source code more that welcomed.
thx.
|
|
|
|
|
Are you willing to use Office Automation? That is probably your best bet, but when you build the app that uses office automation, it is dependant on a specific version of Excel. Here's the main page on MSDN for office automation docs:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnoffdev/html/vsofficedev.asp
Once you're there, click on the link called "Visual C++/MFC - Information and Sample Code". Once there, you just scroll a bit to a sub heading called "Microsoft Excel Automation". You'll find several examples there that should help you get going. The first one looks like it may help you http://support.microsoft.com/default.aspx?scid=KB;en-us;q179706
Good luck.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
Hi !
My app (VC6) is an ATL object, and I would like, during the initialization of the object, to create a window and to post messages to this window. Right now, the only thing the app is doing is to display a message box when a message is received....nad it doesn't work !!!
Here is what I'm doing :
Here is my window class :
<br />
#include "atlwin.h"<br />
#define WM_MYMESSAGE WM_APP+1<br />
<br />
class CMyWindow : public CWindowImpl<CMyWindow><br />
{<br />
public:<br />
CMyWindow(){};<br />
virtual ~CMyWindow(){};<br />
DECLARE_WND_CLASS("MyWindow") <br />
<br />
BEGIN_MSG_MAP(CMyWindow)<br />
MESSAGE_HANDLER(WM_MYMESSAGE, OnMyMessage)<br />
END_MSG_MAP()<br />
<br />
LRESULT OnMyMessage(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& Handled)<br />
{<br />
::MessageBox(NULL,"Message","Message",MB_OK);<br />
return 0;<br />
}<br />
};<br />
and here is my interface code (in the class declaration, I just added a member of type CMyWindow*) :
<br />
CEventBox::CEventBox()<br />
{<br />
m_pMyWindow=new CMyWindow;<br />
RECT myRect;<br />
myRect.bottom=100;<br />
myRect.left=0;<br />
myRect.top=0;<br />
myRect.right=100;<br />
m_pMyWindow->Create(NULL, myRect, NULL, 0, 0, 0U, NULL);<br />
}<br />
<br />
STDMETHODIMP CEventBox::SendEvent(long lNbrEvent, long lSpaceTime)<br />
{<br />
PostMessage(m_pMyWindow->m_hWnd,WM_MYMESSAGE,0,0);<br />
return S_OK;<br />
}<br />
For my tests, I try to use this ATL object in a VB project, where I call the method 'SendEvent' of the interface. Nothing crashed but I cannot see the window I created in the constructor of CEventBox and the message box of OnMessageBox is never displayed.
Any help will be greatly appreciated !
Thank you !
Jerome
|
|
|
|
|
Hi,
I like to create a nice looking icon list (similar to this).
I'm not skilled in GUI programming, so I like to ask for help. How about creating an empty CDialog , then dynamlically create and position all my icons and texts (icons can vary on runtime). Well, this would be similar to HTML and a scripting language filling the page with icons and text.
I have two questions:
1. Where do I create my controls, OnInitDialog() or PreSubclassWindow() ? Sumthing I have too look at?
2. How do I get a scrollbar when controls do not fit into the dialog? For example when I have lots of icons, then the dialog should automatically show a vertical scroll bar.
Thanks for pushing me into the right direction.
|
|
|
|
|
|
My company has a NT domain server, connected by Windows 9x/Me clients. I want to write a program checking the user's group for authorization. Which WinAPI function can provide such information for window 9x/Me clients? Thanks.
Ruxo Zheng
|
|
|
|
|
hi everyone,
my sdi application is base on listview and the contents displayed in the listview are retrieved from a database.. the database is accessed via odbc.. i use a dialog to gather input information.. whenever the information is submitted from the dialog, i created a crecordset/odbc object within the additem function in the dialog class and make sql insert call within the dialog class.. i called the updateallviews function from the sdi/listview right after the new new data is stored in the database, ie when the dialog get destroyed..
i'm getting the database update delay problem.. whenever i call updateallviews, the content of the listview doesn't get updated(the newly added item doesn't show up) until i call updateallviews the 2nd time.. does anyone know how to solve this database delay problem? thx!
|
|
|
|
|
To All,
I am using SetItemText after the column is properly inserted and the InsertItem function is called. The Scrollbar shows that the rows have been inserted, but I can't see any text when using SetItemText. What a headache. What should I do?
|
|
|
|
|
David Kadish wrote:
What should I do?
You should write with what type of control you work. It is a ListView? Show a code. Do you think we have a telepathy?
|
|
|
|
|
The List control can be a little bit quirky sometimes. Not knowing what your code looks like makes it a little difficult to diagnose, but here is my InsertItem/SetItemText code for a front-end application to a DVD collection database:
for( int i = 0; i < m_titles.GetSize(); ++i )
{
CMovieTitle* title = (CMovieTitle*)m_titles[i];
int itemCount = m_movieList.GetItemCount();
m_movieList.InsertItem(itemCount, title->m_sTitle ,0);
m_movieList.SetItemText(itemCount,1,title->m_sFormat);
m_movieList.SetItemText(itemCount,2,title->m_sRegionCode);
m_movieList.SetItemText(itemCount,3,title->m_sRating);
m_movieList.SetItemText(itemCount,4,title->m_sReleaseDate);
m_movieList.SetItemText(itemCount,5,title->m_sVideoReleaseDate);
m_movieList.SetItemText(itemCount,6,title->m_sStudio);
m_movieList.SetItemText(itemCount,7,title->m_sPresentation);
m_movieList.SetItemText(itemCount,8,title->m_sFeatures);
m_movieList.SetItemText(itemCount,9,title->m_sSound);
m_movieList.SetItemText(itemCount,10,title->m_sLanguage);
m_movieList.SetItemText(itemCount,11,title->m_sDuration);
}
CMovieTitle is a wrapper class that I use to hold one record from the database. In this example I am iterating through all of the records and inserting the data into a list control.
You also may be interested in how I am initializing my list control. Here's my code from OnInitDialog (my app is a dialog app):
m_movieList.InsertColumn( 0, "Movie Title", LVCFMT_LEFT, -1, 0);
m_movieList.InsertColumn( 1, "Format", LVCFMT_LEFT, -1, 1);
m_movieList.InsertColumn( 2, "Region Code", LVCFMT_LEFT, -1, 2);
m_movieList.InsertColumn( 3, "Rating", LVCFMT_LEFT, -1, 3);
m_movieList.InsertColumn( 4, "Release Date", LVCFMT_LEFT, -1, 4);
m_movieList.InsertColumn( 5, "Video Release Date", LVCFMT_LEFT, -1, 5);
m_movieList.InsertColumn( 6, "Studio", LVCFMT_LEFT, -1, 6);
m_movieList.InsertColumn( 7, "Presentation", LVCFMT_LEFT, -1, 7);
m_movieList.InsertColumn( 8, "Sound", LVCFMT_LEFT, -1, 8);
m_movieList.InsertColumn( 9, "Features", LVCFMT_LEFT, -1, 9);
m_movieList.InsertColumn( 10, "Language", LVCFMT_LEFT, -1, 10);
m_movieList.InsertColumn( 11, "Duration", LVCFMT_LEFT, -1, 11);
m_movieList.SetColumnWidth( 0, 60 );
m_movieList.SetColumnWidth( 1, 60 );
m_movieList.SetColumnWidth( 2, 60 );
m_movieList.SetColumnWidth( 3, 60 );
m_movieList.SetColumnWidth( 4, 60 );
m_movieList.SetColumnWidth( 5, 60 );
m_movieList.SetColumnWidth( 6, 60 );
m_movieList.SetColumnWidth( 7, 60 );
m_movieList.SetColumnWidth( 8, 60 );
m_movieList.SetColumnWidth( 9, 60 );
m_movieList.SetColumnWidth( 10, 60 );
m_movieList.SetColumnWidth( 11, 60 );
I hope this helps. If you have questions after looking at my code (which has been tested, BTW), feel free to send them my way.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
perlmunger wrote:
m_movieList.SetColumnWidth( 0, 60 ); m_movieList.SetColumnWidth( 1, 60 ); m_movieList.SetColumnWidth( 2, 60 ); m_movieList.SetColumnWidth( 3, 60 ); m_movieList.SetColumnWidth( 4, 60 ); m_movieList.SetColumnWidth( 5, 60 ); m_movieList.SetColumnWidth( 6, 60 ); m_movieList.SetColumnWidth( 7, 60 ); m_movieList.SetColumnWidth( 8, 60 ); m_movieList.SetColumnWidth( 9, 60 ); m_movieList.SetColumnWidth( 10, 60 ); m_movieList.SetColumnWidth( 11, 60 );
Hi Matt,
Ever heard about that for{} instruction ;P;P?
~RaGE();
|
|
|
|
|
Ever heard how inefficient for loops are? Might be tidy, but it is certainly slower. Not to mention, my column widths may not always be equal.
Thanks.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
My computer have two VGA adapter ( No.1, No.2 ), set No.1 to the main display, No.2 is free, I want capture the content of No.1, then make some transform and copy to No.2.
The puzzle is, how to identify No.2( or No.3, No.4.. ), as far as know the function GetDC( NULL ) can get desktop( main display ) content.
|
|
|
|
|