|
I have an application that can also run as a service via srvany. It performs a monitoring task and uses the PlaySound method defined in mmsystem.h to play a .wav notification on certain events. It runs fine under XP as an app or as a service.
Under Win7, the app runs fine. But when running as a service under Win7, I get no sound. The "allow service to interact with desktop" option is available but ignored under Win7 as part of Session 0 isolation. I expect this is somehow related.
I'm looking for verification or alternate approaches.
Thanks.
modified 5-Apr-13 13:28pm.
|
|
|
|
|
You are most likely right in your conclusion. I think the session 0 isolation prevents such interactions.
A possible work-around is to have your Service start or interact with a non-service component that runs in the user session.
|
|
|
|
|
I have weird bug: in a MDI aplication, if I mapped OnFileOpen in follow way:
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
after the document file has opened, the application crashes with follow message:
(KERNELBASE.DLL): 0xC0000005: Access Violation.
but only in Release mode ... in Debug mode, everything is going well ...
if I mapped OnFileOpen in follow way:
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
again, everything is going well ... did you meet with this behaviour ? Perhaps you give some hint ... Thank you.
|
|
|
|
|
In a Debug build the compiler performs additional tasks, for instance it zeroes variables you haven't initialized (e.g. WinAPI structs) (in Release build the unitialized data contains garbage).
Have a look at the following CodeProject article: "Surviving the Release Version"[^].
Veni, vidi, vici.
|
|
|
|
|
Check your CMyApp::OnFileOpen() code and the functions that are called from there. Comment all lines in that function except the base class CWinApp::OnFileOpen() call and uncomment step by step until the violation occurs. Then you should know which part of your code is responsible.
|
|
|
|
|
Inside of CMyApp::OnFileOpen I didn't call CWinApp:OnFileOpen .. here is the buggy code:
void CMyApp::OnFileOpen(void)
{
CFileDialog dlgFile(TRUE);
dlgFile.DoModal();
return;
}
and in release mode, the application crashes ...
|
|
|
|
|
Even if I used:
void CMyApp::OnFileOpen(void)
{
CFileDialog dlgFile(TRUE);
return;
}
and the application is crashing down ...
|
|
|
|
|
Crashes it in this function or later?
If you did not call CWinApp::OnFileOpen() , no document is created. So the reason for the crash is probably somewhere in your document creation. Did you call OnFileNew() or use ProcessShellCommands() to create a document?
|
|
|
|
|
No, I didn't call CWinApp::OnFileOpen , but I call OpenDocumentFile(...) , something like that:
void CMyApp::OnFileOpen(void)
{
CFileDialog dlg(TRUE);
if(IDOK == dlg.DoModal())
{
POSITION pos = dlg.GetStartPosition();
while(pos)OpenDocumentFile(dlg.GetNextPathName(pos));
}
AfxMessageBox("By here, everything it's OK.");
}
after all, I think that the problem it's in another place ... I really don't know ...
And this is weird, because if I open the same file from MRU, everything is OK ...
modified 5-Apr-13 5:54am.
|
|
|
|
|
It's difficult to find such errors in release versions. Using a message box is a good idea to check where the violation occurs. Because it occurs when not calling OpenDocumentFile() , I assumed that it is somewhere in the document handling (e.g. trying to access non-existing documents).
But when it is OK using ProcessShellCommands() (MRU)
At the moment I have only two ideas:
- Call
OpenDocumentFile() with a fixed file name to see what happens (no other calls from within OnFileOpen() ). - Perform a complete rebuild if you have changed something in your project.
|
|
|
|
|
This is became strange: if I call only:
OpenDocumentFile(_T("D:\\Flaviu\\SampleImages5\\Test.xxx"));
, everything is OK, but when I go through normal way:
CString strFile;
if (dlgFile.DoModal()==IDOK)
{
pos=dlgFile.GetStartPosition();
while (pos!=NULL)
{
strFile=dlgFile.GetNextPathName(pos);
AfxMessageBox(strFile);
OpenDocumentFile(strFile);
}
}
is crashing down ... in Release mode only ...
I have to digg in ...
|
|
|
|
|
So the problematic code is at least isolated even when it looks OK. As next step you may assign the fixed file name to strFile ignoring the selection from the dialog.
|
|
|
|
|
Another trial:
CString strFile;
if (dlgFile.DoModal()==IDOK)
{
pos=dlgFile.GetStartPosition();
while (pos!=NULL)
{
strFile=dlgFile.GetNextPathName(pos);
AfxMessageBox(strFile);
OpenDocumentFile(strFile);
}
}
AfxMessageBox("Second chance");
OpenDocumentFile(_T("D:\\Flaviu\\SampleImages5\\Test.xxx"));
AfxMessageBox("Final ...");
the crashes is occur only after the "final" message box ...
|
|
|
|
|
Did you try doing a Rebuild All like Jochen suggested?
Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty
|
|
|
|
|
Of course I did ... something weird is happend ... because if I use only CFileDialog dlgFile(TRUE); in CMyApp::OnFileOpen and the application is crashing down .. I wonder if CFileDialog doesn't have some bug ... 
|
|
|
|
|
Sorry, I did not mean to insult you, but when something really weird is going on, Rebuild All is a good thing to do. I wanted to make sure you had tried that because just last week, I had a weird string related problem that I was trying to chase down. Rebuild All was not my first thought, so I ended up spending at least an hour trying to make sense of it before I finally did the rebuild, which fixed the problem.
Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty
|
|
|
|
|
I found the problem: the destructor of CFileDialog has problems, and I had solved in follow way: I used CFileDialog variable on the heap, just like this:
CFileDialog* pDlgFile = new CFileDialog(TRUE);
delete pDlgFile;
and everything it's OK now ...
I want to kindly thank you all of you for your interest and patience ! Best wishes for you ! Bye.
modified 5-Apr-13 9:12am.
|
|
|
|
|
Flaviu2 wrote: I found the problem... Moving variables from the stack to the heap is usually not the solution to a problem. You likely just masked it.
"One man's wage rise is another man's price increase." - Harold Wilson
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Flaviu2 wrote: the destructor of CFileDialog has problem More likely you are referring to a variable that has been destroyed as your dialog has gone out of scope.
Use the best guess
|
|
|
|
|
|
i have problem with CAsyncSocket class when i called listen in widows service application.
i successfully create Thread but my listen fuction didn't work correctly.
here my code..
BOOL CMyThread::InitInstance()
{
while (!AfxSocketInit());
MySocket sock;
while (sock.Create(3005)==SOCKET_ERROR);
while (sock.Listen()==SOCKET_ERROR);
HANDLE file;
file=CreateFile(_T("C:\\initinstance.txt"),GENERIC_WRITE,FILE_SHARE_WRITE,NULL,CREATE_NEW,FILE_ATTRIBUTE_NORMAL,NULL);
CloseHandle(file);
return TRUE;
}
my application create "initinstance.txt" file successfully but when use commmand "netstat -na" port 3005 not listening..
where is my mistake?
|
|
|
|
|
There seems to be no error in the posted code. But the error may be in your MySocket implementation.
You may also delete the file first to ensure that the file has not been created by a previous run.
|
|
|
|
|
thanks for answer my question
i change a little my code like this...
BOOL CMyThread::InitInstance()
{
while (!AfxSocketInit());
MySocket sock;
while (sock.Create(3005)==SOCKET_ERROR);
while (sock.Listen()==SOCKET_ERROR);
HANDLE file;
file=CreateFile(_T("C:\\initinstance.txt"),GENERIC_WRITE,FILE_SHARE_WRITE,NULL,CREATE_NEW,FILE_ATTRIBUTE_NORMAL,NULL);
CloseHandle(file);
Sleep(30000);
return TRUE;
}
socket listening for 30 sec with 6 thread
and after 30 sec thread is 5 and socket is close.
so...
and i understand my thread is closed after that..
here is my code for create thread...
CMyThread* pThread =
(CMyThread*)AfxBeginThread(
RUNTIME_CLASS(CMyThread),
THREAD_PRIORITY_NORMAL,
0,
CREATE_SUSPENDED);
while(pThread==NULL)
{
Sleep(1);
pThread =
(CMyThread*)AfxBeginThread(
RUNTIME_CLASS(CMyThread),
THREAD_PRIORITY_NORMAL,
0,
CREATE_SUSPENDED);
}
pThread->ResumeThread();
WaitForSingleObject(pThread->m_hThread,INFINITE);
what do you think? do i have mistake here?
and i'm no sure about calling "WaitForSingleObject(pThread->m_hThread,INFINITE);"
|
|
|
|
|
You are creating a user-interface thread. With socket operations worker threads are usual.
Also, why did you retry to create the thread if the first call fails? This makes no sense.
If the thread creation is done by your main thread, it will be blocked by calling WaitForSingleObject() until the thread terminates.
The skeleton for using a worker thread would look like this:
class CMyClass
{
public:
void StartThread();
protected:
bool m_bKill;
CWinThread *m_pThread;
static UINT ThreadFunc(LPVOID pParam);
};
void CMyClass::StartThread()
{
m_pThread = AfxBeginThread(ThreadFunc, this, THREAD_PRIORITY_NORMAL,
0, CREATE_SUSPENDED);
m_pThread->ResumeThread();
}
UINT CMyClass::ThreadFunc(LPVOID pParam)
{
CMyClass* pThis = reinterpret_cast<CMyClass*>(pParam);
bool bKill = false;
while (!bKill)
{
if (pThis->m_bKill)
break;
}
return 0;
}
|
|
|
|
|
thanks a lot.
Solved 
modified 5-Apr-13 9:51am.
|
|
|
|