|
I've recently moved my data base code into a worker thread, which works just fine unless the data base open fails. I currently have the thread wait 15 seconds, and then try the open again. This process repeats until the data base opens successfully or the application exits. The problem I'm having is that, when this logic is occurring, my UI thread will fail with an access violation some time later. It appears that having the CDatabase::OpenEx() call fail causes some sort of corruption to either the UI thread's MFC state or its stack, which is then exposed as the UI is navigated.
I'm using SQL Server 2005 Express, Service Pack 2.
I've tried the following to resolve this:
1. If I comment out the data base operations (OpenEx() ... Close() ), the UI does not crash.
2. If I comment out the data base operations like in #1, and replace them with a AfxThrowDBException(...) , the UI does not crash.
3. One suspect was the CDatabase::OpenEx() implementation, which does some hinky looking things trying to find a window handle. I overrode it and passed a NULL window handle to the ::SQLDriverConnect() call that does the real work of connecting to the data base. The UI still crashes.
From these results I can only conclude that there is some kind of problem here using CDatabase /CRecordset in a worker thread that isn't documented. I've searched on MSDN and Google'd several times, and only found claims of issues with specific ODBC drivers.
Anyone have any suggestions, or ideas that I've missed?
Software Zen: delete this;
|
|
|
|
|
Hi Gary,
Are your CDatabase functions inside your application executable or are you calling them from a helper DLL? Are you static or dynamic linking?
Does the error occur if you add the following before attempting to use CDatabase::OpenEx:
AFX_MANAGE_STATE(AfxGetStaticModuleState());[^]
Best Wishes,
-David Delaune
|
|
|
|
|
The CDatabase functions are inside my application executable, and MFC is dynamically linked.
I tried using your AFX_MANAGE_STATE() suggestion, but it had no effect.
Thanks for the help .
Software Zen: delete this;
|
|
|
|
|
Hi,
Apologies if this has been covered somewhere but I've not found anything related. I'm working on an idea which would require a long-running task to complete at the time the user logs off, I know it's possible to delay the logoff but I was hoping to find a way to run the task as part of the logoff, something like when Windows synchronises offline folders (not sure if that's exactly the right term as I am working from memory here).
Does anyone have any ideas?
Thanks
|
|
|
|
|
|
*click*
Good Answer.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
Thanks for the reply, it is a user mode application and I know I can prevent shutdown by returning false for WM_QUERYENDSESSION but that keeps the logged in session alive, what I want to do is to run the code during the logoff, effectively after the user has been logged off.
For example, when you a running Windows XP on a domain and you have offline file enabled, you will see the synchronisation window appear during the logoff to sync any remaining files back to the domain controller, I'm trying to achieve something like this. The app does not have to remain a user mode app, it could quite easily become a service if that is required but preventing the logoff is not what I'm trying to achieve.
Thanks.
|
|
|
|
|
__DanC__ wrote: Thanks for the reply, it is a user mode application
Usermode applications are limited in their ability to delay/prevent shutdown. You are basically limited to what I described in my previous posts. I believe that you have 5 seconds to respond to the WM_QUERYENDSESSION so you might be able to perform some last-second tasks.
__DanC__ wrote: For example, when you a running Windows XP on a domain and you have offline file enabled, you will see the synchronisation window appear during the logoff to sync any remaining files back to the domain controller, I'm trying to achieve something like this.
Have you considered using Logon/Logoff[^] or Startup/Shutdown[^] scripts? This is typically what an administrator would use to execute something on shutdown/logoff.
Best Wishes,
-David Delaune
|
|
|
|
|
Thanks for the tip, I'll have a look into the scripts and see if they can do what I need. I've just discovered SCM notifications which look promising although I haven't read enough about them to know if they can do what I want yet.
|
|
|
|
|
__DanC__ wrote: I've just discovered SCM notifications which look promising
Yeah, you will have some additional time I think... 20 seconds when you handle the SERVICE_CONTROL_SHUTDOWN message. You can keep posting STOP_PENDING to the SCM for some additional time.
Best Wishes,
-David Delaune
|
|
|
|
|
Hi,
I have created a SDI application with having a LeftView and RightView.LeftView is inherited from CTreeCtrl class where as the rightview is inherited from CFormView class.Can anybody tell me how to split the rightview into 2 halves?
Thanks,
Abinash
|
|
|
|
|
|
You may be inherit yourself CMySplitterWnd inherited from CSplitterWnd.
|
|
|
|
|
**************************************
//#include "simple calculator.h" ->code
class CExerciseApp : public CWinApp
{
public:
virtual BOOL InitInstance();
};
class CMainFrame : public CFrameWnd
{
//CString s = _T("1032");
//int n = ParseInt( s );
public:
CButton b1, b2, b3, b4, b5;
CEdit text1, text2, res;
CString str1, str2;
//CFont font;
long a, b, c;
CMainFrame();
void addition();
void substruction();
void production();
void dividation();
void modulation();
DECLARE_MESSAGE_MAP()
};
*******************************
#include <afxwin.h>
#include <string.h>
#include <windows.h>
#include <math.h>
#include "simple calculator.h"
#define plus 11
#define minus 12
#define product 13
#define divide 14
#define mod 15
#define textone 500
#define texttwo 600
#define result 700
char str[50];
CMainFrame::CMainFrame()
{
Create(NULL, L"MENU BUILDING");
text1.Create (WS_CHILD | WS_VISIBLE | WS_BORDER, CRect(5,10,120,30), this, textone);
text2.Create (WS_CHILD | WS_VISIBLE | WS_BORDER, CRect(140,10,255,30), this, texttwo);
res.Create (WS_CHILD | WS_VISIBLE | WS_BORDER, CRect(275,10,390,30), this, result);
text1.GetWindowText(str1);
text2.GetWindowText(str2);
wsprintf (str,L"%s",str1 );
a=atol(str);
wsprintf (str,L"%s",str2 );
b=atol(str);
//wsprintf ( a,L"%s",str1);
//wsscanf(str1,"%ld",&a);
//a=atol(str);
//wsprintf ( (LPWSTR)str,L"%c",str2 );
//wsprintf ( b,L"%s",str2 );
//b=atol(str);
//wsscanf(str2,"%ld",&b);
b1.Create (L"+", WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON, CRect(5,50,30,70), this, plus);
b2.Create (L"-", WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON, CRect(45,50,70,70), this, minus);
b3.Create (L"*", WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON, CRect(85,50,110,70), this, product);
b4.Create (L"/", WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON, CRect(125,50,150,70), this, divide);
b5.Create (L"%", WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON, CRect(165,50,190,70), this, mod);
//font.CreateFont(20,0,0,0,20,0,0,0, ANSI_CHARSET,OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_DONTCARE,L"arial");
//sta.SetFont(&font);
}
BEGIN_MESSAGE_MAP( CMainFrame, CFrameWnd)
ON_BN_CLICKED (plus, addition)
ON_BN_CLICKED (minus, substruction)
ON_BN_CLICKED (product, production)
ON_BN_CLICKED (divide, dividation)
ON_BN_CLICKED (mod, modulation)
END_MESSAGE_MAP()
void CMainFrame::addition()
{
c=a+b;
}
void CMainFrame::substruction()
{
c=a-b;
}
void CMainFrame::production()
{
c=a*b;
}
void CMainFrame::dividation()
{
c=a/b;
//SetDlgItemInt(result,UINT(c),1);
}
void CMainFrame::modulation()
{
c=a%b;
sprintf(str,"%ld",c);
//SetDlgItemInt(result,UINT(c),1);
CClientDC dc(this);
//wsprintf(str1,"%ld",c);
//res.SetWindowText(str1);
//dc.TextOut(50, 50, L"goutom", 6);
//wsprintf((LPWSTR)str, L"%c", c);
dc.TextOut(280, 15, (LPCTSTR)str, strlen(str));
//str1.Format(L"%ld",c);
//res.SetWindowText(str1);
}
//SetDlgItemInt(IDC_BUTTON4,UINT(c),1);
BOOL CExerciseApp::InitInstance()
{
m_pMainWnd = new CMainFrame;
m_pMainWnd->ShowWindow(SW_NORMAL);
m_pMainWnd->UpdateWindow();
return TRUE;
}
CExerciseApp theApp;
// when i run this code , it run but not give me a error message. plz solve my error.
|
|
|
|
|
goutom roy wrote: when i run this code , it run but not give me a error message. plz solve my error.
Are you saying that it runs correctly? If so then there is nothing to fix. However, if you are saying it does give an error message, then please tell us what the message is.
|
|
|
|
|
goutom roy wrote: when i run this code , it run but not give me a error message. plz solve my error.
Assuming you mean the opposite of what you wrote - Why don't you just step through the code with the debugger and see where it fails?
Also, next time you post your code please embed it in the "code block" tags.
|
|
|
|
|
goutom roy wrote: ...it run but not give me a error message. plz solve my error.
Contradiction.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
could i place a CFromView class on a CDialog class int a dialog-based app?
how to place CFromview on CDialog?
I mean: I have a dialog template with CFromView class ,could I doModal this dialog?
modified on Sunday, November 8, 2009 7:40 PM
|
|
|
|
|
Do you mean CFormView?
Величие не Бога может быть недооценена.
|
|
|
|
|
Why would you even want to? Just add the controls you need to the dialog template.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi,
you can add a TabWnd to the Dialog.
Then you can add a CFormView to this TabWnd.
When you move/resize the TabWnd, you can "hide" the TabWnd and you only see the active CFormView.
Naturally you can switch the View into the TabWnd with another View...
I hope this helps you
Greetings
|
|
|
|
|
Hi All
I am getting Unhandled exception at 0x7714c3c2 accident.I know it's hard to say why came.Becouse it's not in fix step.
When i try to debug the code then it's jump in Disassembly.And it's point here
mov ecx,dword ptr [eax+0Ch)
I know it's difficult to say reason. How can i trace point wahy unhandled exception come.
Plz help me
|
|
|
|
|
Check the call stack to trace the location of the expection on debugging!!!!
Величие не Бога может быть недооценена.
|
|
|
|
|
yaa
Unhandled exception at 0x7714c3c2 rt.exe 0xC0000005: Access violation reading location 0x0
|
|
|
|
|
Can u tell the function in which it is crashing?
Величие не Бога может быть недооценена.
|
|
|
|
|