|
Basically its not a good idea to interact with the desktop from a service. How ever I think giving the dektop interactive privilage to the service will solve your problem. To do so, select your service in the service constrol manager( "services.msc" ), take the logon tab, tick the "Allo&w service to interact with desktop" check box and restart your service.
ox0101 wrote: create a Service progam, and use it to WinExec a other progress,
WinExec function should not be used by newer applications. Please use CreateProcess() or ShellExecuteEx() functions.
|
|
|
|
|
Thats due to the fact that a "desktop object" is associated to a user session with the OS, and that a service have no "destop" since it run inside the OS behind the users.
It is in general wrong to assume that a service is running inside a user context.
What you can do is try to get who are the user that are logged on the machine, get the desktop associated to one of them and then create the process into that context.
See MSDN about "Windows Stations", "Desktop Objects" and the "CreateProcess" API.
WinExec is not the good API, since it creates the new process in the same context of its creator (that has no place to have an interactive interface, being a service).
****
On more remind: to be more productive, don't title a post in a programming forum "Help me", since it gives no clue about the nature of the help.
Imagine the forum displaying 100 posts titled "help me". Do we have to open all of them before to understand if we can helpful or not ?
A more appropriate tile may be "Process and Services", for example.
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
sorry,
i will give a nice title next time
|
|
|
|
|
You can use the CreateProcessAsUser API to run the other program in the context of an interactive user.
«_Superman_»
|
|
|
|
|
if you want to this, the service has to run under a user account. But this isnt right. A serivce hasnt anything to do on a desktop of a user. Use the "All User" Directories for output.
Greetings from Germany
|
|
|
|
|
thank everyone,
sometimes i cant express my mind
the title is "CFileDialog in Windows Service"
i cant get the loged user's Desktop
Now i find a method,but it's my result i want to get
the fllowing:
PSID psidEveryone;
// Create a SID for the built-in "Everyone" group
SID_IDENTIFIER_AUTHORITY sidAuth = SECURITY_WORLD_SID_AUTHORITY;
if (!AllocateAndInitializeSid( &sidAuth, 1, SECURITY_WORLD_RID,
0, 0, 0, 0, 0, 0, 0, &psidEveryone )){
// Error
}
HWINSTA hWinSta = GetProcessWindowStation();
if (hWinSta == NULL){
// Error
}
AllowAccessToWinSta(psidEveryone,hWinSta);
HDESK hDesk = GetThreadDesktop(GetCurrentThreadId());
if (hDesk == NULL){
// Error
}
(from Jerry Richer 's Program Service-Side Windows)
|
|
|
|
|
How Can use it?
i put it in my ON_BN_CLICK
example:(i still dont get the loged user's desktop )
PSID psidEveryone; <br />
<br />
SID_IDENTIFIER_AUTHORITY sidAuth = SECURITY_WORLD_SID_AUTHORITY;<br />
if (!AllocateAndInitializeSid( &sidAuth, 1, SECURITY_WORLD_RID, <br />
0, 0, 0, 0, 0, 0, 0, &psidEveryone )){<br />
}<br />
<br />
HWINSTA hWinSta = GetProcessWindowStation();<br />
if (hWinSta == NULL){<br />
}<br />
AllowAccessToWinSta(psidEveryone,hWinSta);<br />
<br />
HDESK hDesk = GetThreadDesktop(GetCurrentThreadId());<br />
if (hDesk == NULL){<br />
}<br />
<br />
<br />
<br />
STARTUPINFO startinfo;<br />
RtlZeroMemory(&startinfo,sizeof(STARTUPINFO));<br />
startinfo.cb=sizeof(STARTUPINFO);<br />
startinfo.lpReserved = NULL;<br />
startinfo.lpReserved2 = NULL; <br />
startinfo.cbReserved2 = 0;<br />
startinfo.lpDesktop = NULL; <br />
startinfo.dwFlags = 0;<br />
PROCESS_INFORMATION pinfo;<br />
RtlZeroMemory(&pinfo,sizeof(PROCESS_INFORMATION));<br />
CreateProcess(NULL,<br />
_T("E:\\work\\work\\InspectnPro\\InspectnPro\\debug\\InspectnPro.exe"),<br />
NULL,<br />
NULL,<br />
TRUE,<br />
NULL,<br />
NULL,<br />
NULL,<br />
&startinfo,<br />
&pinfo);
|
|
|
|
|
How I can Move dailog box by clicking anywhere not only on caption bar?
Thanks .
|
|
|
|
|
sampat wrote: How I can Move dailog box by clicking anywhere not only on caption bar?
Handle the LButtonDown message and send the WM_NCLBUTTONDOWN, message from it as follows
void CMYDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
SendMessage( WM_NCLBUTTONDOWN, HTCAPTION, (LPARAM) MAKELPARAM( point.x, point.y) );
CDialog::OnLButtonDown(nFlags, point);
}
|
|
|
|
|
Thanx buddy .... everything is solved
|
|
|
|
|
The solution given by NS is the right way to do it.
«_Superman_»
|
|
|
|
|
Like this...
UINT CTestDlg::OnNcHitTest(CPoint point)
{
return HTCAPTION;
}
But if you want to be more specific, try the following... it will exclude the borders, menu, etc.
UINT CTestDlg::OnNcHitTest(CPoint point)
{
UINT uHitTest = CDialog::OnNcHitTest(point);
if( uHitTest == HTCLIENT ) return HTCAPTION;
}
- ns -
|
|
|
|
|
Paul DiLascia's article[^] will be interesting.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Hi ,I am new in mfc and c++, and currently I have got problem with this kind of error
basically , i have to file get.cpp and send.cpp
and i want to share variable across that files
and i thought we can use keyword "extern"
so here is my code
in send.h
int g_iEnabled
class csend
{
......
}
in get.h
extern int g_iEnabled
class cget
{
....
}
is that the rightway to share variable across multiple files
thanks for your help
bye
|
|
|
|
|
Put the int g_iEnabled declaration in the .cpp file.
«_Superman_»
|
|
|
|
|
Hi thanks men for the solution, it works perfectly
|
|
|
|
|
Hi all,
The question might be strange, but I have a MFC application (say on client system) which will be started by another program from another system (say server) using PsTools command via network. Both systems are connected using a crossover cable and once the server starts the client program it sends commands to client as per user request on server program (which is also a MFC program). The client program is multi-threaded program and records/playbacks videos from framegrabber. Everything is fine for a while, but recently the client program started acting weird, the program closes abruptly without any warning or message or anything, it just disappears (not even its trace in task manager) while the server is still running, the client should close only when the server sends a quit ('Q') command. I tried to have a message pop up in 'OnClose()' function etc etc, but nothing works, it just disappears randomly.
I wonder if there is any way to figure out what the problem/error is, any suggestions??
thanks,
-PNT.
PKNT
|
|
|
|
|
I've seen this happen when an exception is raised and the EXCEPTION_REGISTRATION linked list is corrupt. See here[^] for more information. The following program demonstrates this (it's from memory so bear with me):
void main()
{
__asm
{
mov eax, 0
mov FS:[0], eax
}
*(char*)0 = 0;
return 0;
}
Steve
|
|
|
|
|
In addition to what Stephen Hewitt pointed out... there are other situations which may cause the symptoms you are describing. For example... if you have a global structured exception handler and a second exception occurs while inside your handler code... the application will simply be terminated and would 'dissapear'.
Another situation which would cause the application to 'just dissapear' would be calling:
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
This single line of code would cause the application to simply dissapear when an exception occured.
I would suggest downloading Debugging Tools for Windows[^] and attaching WinDbg to a debug build of your application.
Best Wishes,
-David Delaune
|
|
|
|
|
Thanks for your replies, I thought of using WinDbg, but couldnt figure out exactly how to use it. But will check out for some articles on it. BTW in my program there are no stacks or heavy memory allocations or anything memory intensive, its just get the frame data from framegrabber and write it to a raw avi file on the hard drive.
Will try WinDbg to find the problem.
-PNT
PKNT
|
|
|
|
|
Kiran Satish wrote: there are no stacks
Yes there is: simply calling a function and using local variables uses the CPU's stack. This is the same stack that holds the EXCEPTION_REGISTRATION linked list.
Steve
|
|
|
|
|
I tried to use WinDbg while running this application but its gives me .pdb file not found or mismatched error. I recompiled the program in debug mode and tried to run again and it gave me the same error.
Are there any settings that needs to be set in project options of the applicaiton in debug mode??
-PNT
PKNT
|
|
|
|
|
|
That option "Generate Debug Info" is always enabled in my applications in debug mode. Will go through the PDB files article in a min.
I found a problem/unhandled exception wihtin the application relating to CComVariant. As I said my application communicates with another system using ethernet while at the same time it communicates with another program within the system using COM port. Inorder to handle the events from COM port (CMSComm object), I use a CComVariant object to read the data from CMSComm object whenever it triggers OnReceiveMessage() event. This is how I have used it in my program -
void CMyApplicationDlg::OnReceiveMessage()
{
if(m_ComRecCommand.GetCommEvent() == 2)
{
CString buffer,vidname,val;
m_cvRespInput.Clear();
m_cvRespInput = m_ComRecCommand.GetInput();
buffer = m_cvRespInput.bstrVal;
}
}
It gives me error at line 8, when I watch the variable in debug mode, it shows VT_ERROR for CComVariant object. This is not the case before using ethernet communication from another system. But once I use it, this one shows only VT_ERROR. Am confused on understanding why this is happening???
PKNT
modified on Thursday, January 15, 2009 8:56 PM
|
|
|
|
|
Kiran Satish wrote: when I watch the variable in debug mode, it shows VT_ERROR for CComVariant object.
What is the m_cvRespInput.scode (status code) value? It should be giving you an error code.
Best Wishes,
-David Delaune
|
|
|
|