|
|
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
|
|
|
|
|
For a CArray you have to dereference the internal data pointer to the C style array within the CArray.
Any collection not using standard C style arrays for data storage, which I believe is everything but CArray derivatives, will not likely have its contents aligned in a contiguous portion of memory like a CArray will. So viewing such a container's contents would probably be very difficult if not impossible. However, viewing a CArray is easy.
For example, if you are stepping through a class with a CArray derived data member named m_array you can see the contents of index 4 by entering this in the watch window:
*m_array.m_pData[ 4 ]
This assumes that that the array has a size of at least 5. Overstepping the allocated size of the array will probably not hurt in this situation but you will see garbage instead of what you expect to see.
Just think of the watch window as a way to execute a limited line of code. Virtually any syntax you would use in your program should be valid in the watch window. However, don't forget about the scope of the data you want to watch. It's easy to assume that what you put in should work and then believe that the problem is not yours when it doesn't work as anticipated.
|
|
|
|
|
I have run across a problem using CfileDialog on Windows 2000 for which I have not yet found a solution. The problem is as follows:
If I instantiate an instance of a CFileDialog passing TRUE as the first parameter and accepting the default values for all other parameters, and then call DoModal(..) on the object, then the standard CFileDialog is displayed. However, if I navigate to any folder that contains a read-only files, then I hit a user breakpoint deep within NTDLL.
To see this problem, the simplest possible reproduction is to create a dialog based MFC app that uses CFileDialog as its main window.
I had thought that specifying the OFN_DONTADDTORECENT flag might fix this problem but it did not. I also tried getting rid of the OFN_HIDEREADONLY flag, but that had no effect either.
Once the breakpoint is called in NTDLL, you can step over it to receive a 2nd which can be stepped over as well, and then the program continues normally until you shut it down at which point 2 additional breakpoints are encountered. Of course, in release mode, the operation is seamless and no problems are evident.
I have not been able to find anything at MSDN online that gives a description of the problem or a work around. If anyone has any information on a workaround that will keep Win2000 from hitting this internal breakpoint, I would appreciate it
|
|
|
|
|
Sorry that this is not a answer to your problem, but I tried creating a dialog app using CFileDialog as the main window. It worked fine in debug mode on read-only files. The only thing I can say is I have Windows 2000 Professional with SR-1 and DevStudio 6.0 with SR-4.
Sorry I can't help,
Jonathan Craig
|
|
|
|
|
Is theree any decent documentation on writing DevStudio add-ins?
I want to be able to add a menu item to the context menu in the workspace ClassView tab, and then bring up my own dialog when the programmer selects my menu item.
Thanks in advance.
|
|
|
|
|
Hi, what I need is a C++ class to read/write zipfiles(jar-files). The class may not use MFC, because I'm writing the application with WTL. Any suggestions ?
|
|
|
|