|
Hi Nick,
I found the messages I referred to:
With external resourcefile dialog with Custom Control not loaded [9:24 9 Jul 00]
Anyoune knows differences with custom controls in NT and W98??? [2:00 7 Jul 00]
I don't know if the following could help, however...
A few days ago, I was trying to solve a problem I had with animated cursor resources (they got loaded only when linking to MFC DLLs, but not when linking to static libs), and I had a look in CWinApp::LoadCursor() code discovering the 'undocumented' function AfxFindResourceHandle(), which is used throughout MFC code to load resources.
Its declaration is in AFXWIN.H (line 3920):
// Use AfxFindResourceHandle to find resource in chain of extension DLLs
#ifndef _AFXDLL
#define AfxFindResourceHandle(lpszResource, lpszType) AfxGetResourceHandle()
#else
HINSTANCE AFXAPI AfxFindResourceHandle(LPCTSTR lpszName, LPCTSTR lpszType);
#endif
Here is an excerpt from MSDN ("Extension DLLs"):
"...
Sharing Resources and Classes
Exporting resources is done through a resource list. Each application contains a singly linked list of CDynLinkLibrary objects. When looking for a resource, most of the standard MFC implementations that load resources look first at the current resource module (AfxGetResourceHandle) and if the
resource is not found walk the list of CDynLinkLibrary objects attempting to load the requested resource.
Walking the list has the disadvantages that it is slightly slower and requires managing resource ID ranges. It has the advantage that a client application that links to several extension DLLs can use any DLL-provided resource without having to specify the DLL instance handle. AfxFindResourceHandle is an API used for walking the resource list to look for a given match. It takes the name and type of a resource and returns the resource handle where it was first found (or NULL).
If you wish to not walk the list and only load resources from a specific place, use the functions AfxGetResourceHandle and AfxSetResourceHandle to save the old handle and set the new handle. Be sure to restore the old resource handle before you return to the client application.
..."
---
If you have any idea about my problem, please let me know. I posted a message here, but without much luck. Hope you'll have more...
Paolo.
|
|
|
|
|
I want to override CWinApp::OnFileNew and CWinApp::OnFileOpen, but I don't know how they work.
Does anybody know how they work, or even have some code for overriding them?
Thanks,
Nisse
|
|
|
|
|
Just look at the MFC source code; that is what it is provided for.
As for how to override, the easiest way is to use the ClassWizard to do that.
|
|
|
|
|
I was hoping so, but I can't find it!
Where can I find the MFC source code?
Thanks!
|
|
|
|
|
Does anyone have an idea on how to obtain the MAC address of a PC.
|
|
|
|
|
|
I'm in the process of building a tool that allows you to add user-defined messages and handler functions to your apps without having to manually edit files.
It seems that I need to create these messages all the time, and manually adding them to my projects (for me, that's a minimum of three files I have to change for each message) is a royal pain in the patootie.
If anyone is interested, I can put up a web page showing my progress every couple of days. The first iteration of the tool will be a stand-alone executable that can be added to your tool menu, but future plans are to make it a fully integrated add-in for Visual Studio. Of course, this too will only be applicable for Visual C++.
When the project is done, I'll post the source and executable here on The Code Project.
Comments?
|
|
|
|
|
hello!
i've to change the windows opening screen in one of my applications and my own application's inteface should appear even before the desktop comes.Can you please help me?
thanks
|
|
|
|
|
Hi,
CString m_sProto;
CString sProtocols="PROTOCOL";
m_sProto = sProtocols; <- This is throwing one exception.
I know it is throwing one exception catch(...).
But how to know the exception?
Thanks,
Kotesara
|
|
|
|
|
Hi. This is from the MSDN.
CString::operator =
const CString& operator =( const CString& stringSrc );
throw( CMemoryException );
const CString& operator =( TCHAR ch );
throw( CMemoryException );
const CString& operator =( const unsigned char* psz );
throw( CMemoryException );
const CString& operator =( LPCWSTR lpsz );
throw( CMemoryException );
const CString& operator =( LPCSTR lpsz );
throw( CMemoryException );
Remarks
The CString assignment (=) operator reinitializes an existing CString object with new data. If the destination string (that is, the left side) is already large enough to store the new data, no new memory allocation is performed. You should be aware that memory exceptions may occur whenever you use the assignment operator because new storage is often allocated to hold the resulting CString object.
Example
The following example demonstrates the use of CString::operator =.
// example for CString::operator =
CString s1, s2; // Empty CString objects
s1 = "cat"; // s1 = "cat"
s2 = s1; // s1 and s2 each = "cat"
s1 = "the " + s1; // Or expressions
s1 = 'x'; // Or just individual characters
And heres what it says about CMemoryException.
A CMemoryException object represents an out-of-memory exception condition. No further qualification is necessary or possible. Memory exceptions are thrown automatically by new. If you write your own memory functions, using malloc, for example, then you are responsible for throwing memory exceptions.
So your catch should be something like this
try
{
// do the string stuff
}
catch(const CMemoryException e)
{
// do something with it
}
catch(...)
{
// just to catch any others that crop up.
// make sure you do somehing drastic if anything appears
// here because it SHOULD NOT HAPPEN.
}
Hope this helps. Pete
|
|
|
|
|
Pete, I agree with your reply, but have a pet peeve against the catch(...) construct, especially under VC.
First, note that this code leaks:
try {
CException *e = new CException;
throw e;
}
catch(...) {
MessageBox ("Hello");
}
because the pointer is lost - there's no way to call CException->Delete() . (This leak problem is not true of all compilers, which just makes matters muddier from a portability standpoint)
Secondly, processor traps such as access voilations and divide by zero are also caught by catch(...), and there is no way that I know of to distinguish them inside the catch block.
Opinion: Catch what you expect might be thrown and can deal with, and leave the rest to the OS.
|
|
|
|
|
Hi. Yes, I personally never use the catch(...) because of the very things you mention in your post. I didn't like the fact that I couldn't do anything intelligent from within the catch(...) block. If you do catch an error in catch(...) you could just tell the user and then either carry on and hope for the best or just shut down app.
Neither are optimal solutions.
If anyone has any contributions to this I would be interesting in hearing it.
Pete
|
|
|
|
|
leave it to the OS? you mean the lovely "This application has performed an illegal operation" message box?
ask the average user which is more important: leaking 30 bytes or preventing the app from crashing without warning.
if i do a "catch(whatever w)", i always follow it with a catch(...). or, if i'm wrapping C code, or someone else's code, or around code that has the potential to jump out pf array bounds (like when you are filling a buffer that you didn't allocate).
in fact, i often put a catch(...) around every major code section, just in case something gets by testing. i also make sure that i do something intelligent in the catch, like attempt to get into a safe state.
the headaches that little construct can save are worth megabytes of leaked memory, to the average user.
-c
|
|
|
|
|
Hi,
Try this one
catch(CException e) //i'm not sure if is pointer of not
{
TCHAR szCause[MAX_PATH];
szCause[0]=0x00;
e.GetErrorMessage(szCause,sizeof(szCause));//
}
But the best way is to read CopyConstructor help for CString because the exception types are defined there.
Best regards,
/REMUS
|
|
|
|
|
I had develop an application which is running fine in the debug mode. There is no warnings there in either debug mode.I had handled all the possible exception. When I try to run that code in release mode on my computer it works fine. but when i run that exe in some another computer it crashes it give some memory handled exception on other machine. Can anybody can guide on this.
Also if anybody know about the Purifiers available for the VC++6 on Windows NT platform please let me know.
Thanks in Advance,
N.S.
|
|
|
|
|
Hi,
Usually the problems appear so frequently from 2 resons.
If you use MFC and modify the prototype of message handlers like ON_MESSAGE(WM_WHATEVER,OnWhatever) ....
OnWhatever has prototype LRESULT OnWhatever(WPARAM,LPARAM) otherwise you get your crash...
Other reason is uninitialized mebers. Normaly to avoid such situations you should add for each members default values and so on.
By the way to debug it in release version use for your project settings at c/C++ tab page for debug info -> Program database , for optimizations -> Disable Debug and in Link tab check the generate debug info check box. And now you have debug info in release!!
Try to get them with Bug Trapper from www.mutek.com
I whish you luck and patience,
/REMUS
|
|
|
|
|
If it is always working OK on your machine I would guess that the problem is something to do with the DLLs linked to your app.
Have your tried statically compiling the application with MFC libraries?
|
|
|
|
|
This question looks very familiar and I think I have provided a reply already, so probably it was the CodeGuru web site that I saw it. That site has been having problems so perhaps my reply was lost.
One good possibility is that you might be using ASSERT or something like that; if so, then the code would be executed for the debug version only.
Another possiblity might be that you are not checking all return codes from SDK functions etc. and there might be an error that you could catch and provide an error message for and quit sooner so that it would be easier to fix.
The other answer about uninitiallized variables could be an explanation; I think that the debug version might (I am not sure) initialize memory to zeros eventhough they are not initialized explicitly.
|
|
|
|
|
I need to hide the windows menu in a NT 4.0 windows application. Originally, the design of the application had a menu but the "design" of the application "has been changed" to one without a menu.
The functionality of the menu is provided by button controls in a child window.
I searched the MSDN, MSDN online, CodeGuru, CodeProject, Experts-Exchange, etc. without finding any information on "hiding a menu" in a Windows application.
|
|
|
|
|
Read MSDN for
CDocTemplate
CSingleDocTemplate
CM....
maybe you will find a hint
/REMUS
|
|
|
|
|
Hi,
I'm working with a Single-Document-Interface application (SDI).
In the resource editor, (VC++6.0), I tried changing the default icon (16x16) and (32x32) for saved documents.
But now when I save, the file still gets the old default icon. What's going on?
I would appreciate it if someone can tell me how to fix it.
Thank you.
|
|
|
|
|
You need to rebuild your icon cache. Tweak UI will do it, or if you don't have that, go to Control Panel/Display/Appearance tab. In the Item combo box, select Icon. Change the size to 33, apply it, then back to 32. That will rebuild the cache.
|
|
|
|
|
Does anyone know how the Unicode (wide-char) string is constructed. I have a unicode text file and I want to use WideCharToMultiByte to manipulate the contents. My problem is that I read the file as binary (byte-by-byte) and I dont know how to construct the wide-character string (used as the input for the function) to result the ANSI string. My project doesn't define unicode (therefore doesn't support unicode).
Thanks a lot in advance for any ideas.
|
|
|
|
|
Unicode uses 2 bytes for one character.
"Byte-order Mark" MSDN article could be helpful for you.
|
|
|
|
|
Hello,
how can I view the items of an array or an MFC Collection in the watch view? Let's say I have an CObArray named m_Array. Now I've typed into the watch window "m_Array[0]" to have a look at the first item in the array, but this doesn't work.
Any ideas are very welcome.
Matthias
|
|
|
|