|
An app which has worked fine under W2K crashes in the exception handler under XP both with the binary built under W2K or XP, using VC++6.
It happens at the END_CATCH line in the code below (generates an access
violation at 0xc0000005) if the file does not exist.
It worked fine in W2K. What is different between W2K and XP that could cause this?
BOOL CUnembedDlg::OpenFile(CString f_name)
{
TRY
{
// Open the file in text mode to do
// CR-LF -> LF converison.
CStdioFile cstdf(f_name, CFile::typeText | CFile::modeRead);
DWORD f_size = cstdf.GetLength();
LPTSTR s = file.GetBufferSetLength((int)f_size);
cstdf.Read(s, (UINT)f_size);
cstdf.Close();
file.ReleaseBuffer(-1);
m_FileSize = file.GetLength();
if (-1 == file.Find("embedded-sysfiles", 0))
{
CString err_msg = "File not recognized";
MessageBox(err_msg, f_name, MB_OK | MB_ICONERROR);
m_combo1.SendMessage(WM_SETFOCUS, 0, 0);
m_combo1.Clear();
return false;
}
return true;
}
CATCH(CFileException, e)
{
e->ReportError();
e->Delete();
m_combo1.SendMessage(WM_SETFOCUS, 0, 0);
m_combo1.Clear();
m_combo1.RemoveFromMRU(f_name);
m_combo1.RefreshCtrl();
}
END_CATCH
return false;
}
while (!asleep)
code();
|
|
|
|
|
I believe that the problem you are having is caused by the e->Delete(); line. It has been a while since I have used MFC style exceptions, but I believe that the MFC macros automatically call the delete function for you through the MACRO.
Look at how the macro is defined I bet it expands to include a call to Delete.
This is correct if you are using standard C++ exception blocks
try
{
}
catch(CException* pE)
{
}
but not the MFC way.
You have probably just been unluck not to find if before.
|
|
|
|
|
Matt,
Thanks. you were spot on. stdafx.h is where delete() is called, in the deinfition of the END_TRY macro. I guess I got confused between standard C++ exception handling and the MFC macros.
I double checked and found that I'd actually been running the debug build on W2K, which explains why it hadn't crashed before (the release build does).
Curiously, and maybe you know the answer to this as well , in the debug build the message box popped up by ReportError() includes the message:
<path\filename> contained an invalid path
but the release version just has an empty message box with the warning icon and an OK button - no message.
while (!asleep)
code();
|
|
|
|
|
Where should you put initialization code for a new dialog in my program? The classwizard wont make any OnInitDialog(). I tried to put it in the constructur and even in the WM_CREATE function, but it crashes the program. help...
|
|
|
|
|
Usually it is put in OnInitdialog. I think, your program is crashing due to some other problems.
|
|
|
|
|
Are you talking about initializing the data in the window of a dialog? If so, the you do want to place this in the OnInitDialog handler. I think that you should take one more look at the classwizard to see if you can create the OnInitDialog handler for you.
Otherwise manually edit the message handlers and add a handler for the WM_INITDIALOG message.
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!
|
|
|
|
|
You need to be more specific on some issues:
tordyvel wrote:
Where should you put initialization code for a new dialog in my program?
That depends entirely on the data and when it's being used.
tordyvel wrote:
The classwizard wont make any OnInitDialog().
What do you mean by this? In Visual C++ .NET, any dialog's created from a dialog template do not by default have OnInitDialog handlers. Is this what you mean? If that is the case, you can add the handler from the dialog class' Properties dialog. If not, you need to let us know what you mean when you say that the Class Wizard "wont make any OnInitDialog".
tordyvel wrote:
I tried to put it in the constructur and even in the WM_CREATE function, but it crashes the program. help
How exactly does it "crash". GPF? ASSERT? We need more details if someone is going to be able to help you.
Cheers,
Tom Archer
Author - Inside C#, Visual C++.NET Bible
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the af
|
|
|
|
|
Hi
I have made an database application that works with a lot of different data.
I would now like to make a new window that should be able to show calculation results based on this data.. I wonder what kind of View should I use
( I would like to put the data in some kind of grid) note i would not like to use CRecordView..
Could someone please help this Rookie
Best regards
Henrik
|
|
|
|
|
You can either use and activeX control like MSDataGrid, Hierarchial data Grid etc. or you can Use Chris Maunder's grid available in this site.
|
|
|
|
|
I am attempting to "port" an mfc application to windowsXP and everything runs fine, but there are a few finer points of the UI that aren't correct.
For example:
The menu background color and the toolbar button face colors aren't correct. They are darker than they should be (but the gripper is correct). Also, the 3d bevel along the bottom edge of the lowest toolbar looks different on the gripper than on the rest of the toolbar.
I've written a manifest and that gives me the new button, scrollbar, etc. style, but the affore mentioned issue remains.
Has anyone seen an article from Microsoft addressing this issue? (I searched MSDN to no avail.) Any guidance would be appreciated.
|
|
|
|
|
Use the TBSTYLE_TRANSPARENT flag:
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT | TBSTYLE_TRANSPARENT) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1;
}
HTH
--
Andrew.
|
|
|
|
|
The TBSTYLE_TRANSPARENT style flag makes no difference.
There's a subtle difference in the background color in my MFC application and Windows Explorer, Internet Explorer, Movie Maker and a few other applications that seem to be more targeted for XP. Let me point out that the toolbars in Visual Studio, all of the Office XP products, WordPad, Notepad, etc. are NOT the same color as the first set of apps that I mentioned. My application shares their colors, not what I'd consider the more correct colors.
|
|
|
|
|
How to open the MSWord application, by automation, into my own window ?
Thanks.
|
|
|
|
|
Get the Path of winword.exe in your computer and then Through Winexec function all that exe with it's path
Samir Sood
|
|
|
|
|
Get the Path of winword.exe in your computer and then Through Winexec function call that exe with it's path
Samir
|
|
|
|
|
To opne word in your MFC application, first you have to create an application which supports Doc/View architecture. Then use COleDocument instead of usual CDocument class. Find out the help for COleDocument. If still u find it difficult, then send me a mail.
|
|
|
|
|
I have made this checkbox on my app. It's a non MFC app. it just get light gray when i press it and turns white again when i release, what do i do?
Thankyou
|
|
|
|
|
Either BS_AUTOCHECKBOX has not been specified in the style or you have code that is resetting the state.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Oh, thankyou It was the AUTOCHECK
|
|
|
|
|
What function/message shall i use?
|
|
|
|
|
For non-MFC apps, look at the BM_GETCHECK and BM_SETCHECK messages.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
|
I am planning to write the distributed C++ MCSD exam. Now I noticed that the books have all been discontinued (the MS Press books for it), but the exam isstill there and is not listed amonst exams that will be discontinued. Do you guys think that this exam will be around in the 6 months or so, or do you see it phase out within this year?
|
|
|
|
|
Hey guys, I've got one that I hope someone can help with:
Over on codeguru.com there is an article titled Separating the views of an MDI application into different DLLs
What I'm trying to do is create this same fucntionality within a SDI application. This app is workflow based and using an MDI just doesn't work for this type of application.
Here's some of what I have; In my DLL, I have exported one function:
extern "C" AFX_EXT_API UINT Init(CString *strLabel,CRuntimeClass **pRunTimeClass)
{
new CDynLinkLibrary(View1DLL);
*pRunTimeClass = RUNTIME_CLASS(CTestView);
*strLabel = "View 1";
return 0;
}
In my test application I have a menu that will call this method when selected:
void CMainFrame::OnViewSwitchtodll()
{
HINSTANCE hDLL;
LPDLLFUNC lpfnDllFunc;
UINT uReturnVal;
CString strLabel;
CRuntimeClass* runtimeclass;
hDLL = LoadLibrary("View1.dll");
lpfnDllFunc = (LPDLLFUNC)::GetProcAddress(hDLL,"Init");
if (!lpfnDllFunc)
{
FreeLibrary(hDLL);
}
else
{
uReturnVal = lpfnDllFunc(&strLabel,&runtimeclass);
CAADoc* pDoc = (CAADoc*)this->GetActiveDocument();
pDoc->SwitchToView(runtimeclass);
}
}
This loads up the DLL grabs a function pointer to the Init function exported in the DLL and then passes the runtimeclass to the SwitchToView() in my Document class (this was taken from an article on CodeProject).
When I step into SwitchToView the runtimeclass object appears to be fine... and I do not receive errors... but the mHwnd of the runtimeclass is ??? in the Variable inspector during debug.
I've come to the point where I need someone else to take a look at this - so any help?
Thanks in advance,
Dave "Dak Lozar" Loeser
|
|
|
|
|
I have two views in my application . One is rich edit view and one is edit view . They are split using the splitter windows . But the edit view by default has horizontal and vertical scroll bars associated with it. How to get rid them and make them auto vertical and horizontal scroll bars. I have overriden the precreatewindow function of edit view with the following code
cs.style &= (WS_CHILD | WS_VISIBLE );
cs.style &= ~(WS_HSCROLL);
cs.style &= ~(WS_VSCROLL);
cs.dwExStyle &= ~(WS_EX_RIGHTSCROLLBAR);
but to no avail . Can anyone suggest a solution
|
|
|
|