|
|
Ravi Jadhav wrote:
C:\>MyExe stop
That will run a second instance of MyExe. You'll need to use IPC to look for a running instance and tell it to stop its work.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
I dont want the second instance. Can you please help me how to use IPC?
|
|
|
|
|
|
Ravi Jadhav wrote: If MyExe is already running then the above command will stop it.
do you want to create service!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
It would be Win32 or MFC application
|
|
|
|
|
|
Thanks I think this will suffice my requirement
|
|
|
|
|
Create some gloabl object like NamedPipe, Mutux etc to manage single instance
Use PostQuitMessage to exit
|
|
|
|
|
Could you find a simpler way to solve your problem?
Example
C:\>MyExe start
write on a registry or on a fixed file
RUN = TRUE
and then the program will start
C:\>MyExe stop
write on a registry or on a fixed file
RUN = FALSE
and this instance ends
The first instance, thatsometimes (like into the OnIdle function) are checking the key , understands that he needs to be closed and .... close itself .
hope that helps
|
|
|
|
|
So what exactly is the question? You've given us a high-level overview, but nothing specific.
"The largest fire starts but with the smallest spark." - David Crow
|
|
|
|
|
This is a poor solution as it involves polling and persistent storage.
Steve
|
|
|
|
|
Hi
Stephen Hewitt wrote: poor solution as it involves polling and persistent storage
I know that,... I according to you .
But the bettest (if exist ) solution depends on how complex is his program and how much time he coud spend on this problem.
My suggestion is only an example, he probally can adapt it to his program, or it can be a way to find a more simple way.
If not,...well he has many other ways, according to others resp.
Bye
|
|
|
|
|
Can anyone please point out why the AfxParseURL function is not working 4 me..
i've used it as:
CString URL=("http://www.yahoo.com");
BOOL bParse;
CString csSvrName;
CString csObjName;
INTERNET_PORT nPort;
DWORD dwServiceType = AFX_INET_SERVICE_HTTP;
bParse=AfxParseURL( URL, dwServiceType , csSvrName, csObjName, nPort );
|
|
|
|
|
shuchigo_jane wrote: why the AfxParseURL function is not working 4 me
What is the problem ?
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
nothing wrong with d code then?
it gives me a "debug assertion failed" message,plus no value returned in bParse..
|
|
|
|
|
shuchigo_jane wrote: it gives me a "debug assertion failed" message
And how are you sure that this is this code that causes the crash ? Use your debugger yo track the crash (press F5 to start and F9 to set breakpoints).
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
shuchigo_jane wrote: it gives me a "debug assertion failed" message,plus no value returned in bParse..
On first look there is no error in code, have check what line no is DEBUGGER showing you assertion!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
will this detailed code help tracking it??
CInternetSession session("My Session");
CHttpConnection* pServer = NULL;
CString tmpstr;
char inbuff[100000];
UINT nBytesRead;
CHttpFile* pFile = NULL;
try
{
void *szBuff=NULL;
CString URL=("http://www.yahoo.com");
BOOL bParse;
CString csSvrName;
CString csObjName;
INTERNET_PORT nPort;
DWORD dwServiceType = AFX_INET_SERVICE_HTTP;
bParse=AfxParseURL( URL, dwServiceType , csSvrName, csObjName, nPort );
pServer = session.GetHttpConnection( csSvrName, nPort);
pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_GET, url);
pFile->AddRequestHeaders(pBuf);
pFile->SendRequest();
UINT nRead = pFile->Read(szBuff, 1023);
while (nRead > 0)
{
//read file...
}
delete pFile;
delete pServer;
}
catch (CInternetException* pEx)
{
LPTSTR lpszError=NULL;
//catch errors from WinInet
pEx->GetErrorMessagelpszError,1023);
}
if(pFile==NULL)
{
AfxMessageBox("Error in openurl");
}
else
{
nBytesRead=pFile->Read(inbuff,sizeof(inbuff));
tmpstr.Format("Read %d",nBytesRead);
AfxMessageBox(tmpstr);
}// endif
session.Close();
|
|
|
|
|
Please use your debugger to check where it crashes. Then, if you are not able to correct the problem, give us detailed information about the crash (where it crashes, what the problem is, ...)
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
When you trying to read:
...
UINT nRead = pFile->Read(szBuff, 1023);
...
your szBuff is NULL - initialize this buffer (i.e.: szBuff = new BYTE[1023]).
-----------
Mila
|
|
|
|
|
{
ShowBanner();
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
cerr << _T("MFC Failed to initialize.\n");
return 1;
}
if (argc < 2 || !ParseOptions(argc, argv) || pszURL == NULL)
ShowUsage();
int nRetCode = 0;
CTearSession session(_T("TEAR - MFC Sample App"), dwAccessType);
CHttpConnection* pServer = NULL;
CHttpFile* pFile = NULL;
try
{
// check to see if this is a reasonable URL
CString strServerName;
CString strObject;
INTERNET_PORT nPort;
DWORD dwServiceType;
if (!AfxParseURL(pszURL, dwServiceType, strServerName, strObject, nPort) ||
dwServiceType != INTERNET_SERVICE_HTTP)
{
cerr << _T("Error: can only use URLs beginning with http://") << endl;
ThrowTearException(1);
}
if (bProgressMode)
{
cerr << _T("Opening Internet...");
VERIFY(session.EnableStatusCallback(TRUE));
}
pServer = session.GetHttpConnection(strServerName, nPort);
pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_GET,
strObject, NULL, 1, NULL, NULL, dwHttpRequestFlags);
pFile->AddRequestHeaders(szHeaders);
pFile->SendRequest();
DWORD dwRet;
pFile->QueryInfoStatusCode(dwRet);
// if access was denied, prompt the user for the password
if (dwRet == HTTP_STATUS_DENIED)
{
DWORD dwPrompt;
dwPrompt = pFile->ErrorDlg(NULL, ERROR_INTERNET_INCORRECT_PASSWORD,
FLAGS_ERROR_UI_FLAGS_GENERATE_DATA | FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS, NULL);
// if the user cancelled the dialog, bail out
if (dwPrompt != ERROR_INTERNET_FORCE_RETRY)
{
cerr << _T("Access denied: Invalid password\n");
ThrowTearException(1);
}
pFile->SendRequest();
pFile->QueryInfoStatusCode(dwRet);
}
CString strNewLocation;
pFile->QueryInfo(HTTP_QUERY_RAW_HEADERS_CRLF, strNewLocation);
// were we redirected?
// these response status codes come from WININET.H
if (dwRet == HTTP_STATUS_MOVED ||
dwRet == HTTP_STATUS_REDIRECT ||
dwRet == HTTP_STATUS_REDIRECT_METHOD)
{
CString strNewLocation;
pFile->QueryInfo(HTTP_QUERY_RAW_HEADERS_CRLF, strNewLocation);
int nPlace = strNewLocation.Find(_T("Location: "));
if (nPlace == -1)
{
cerr << _T("Error: Site redirects with no new location") << endl;
ThrowTearException(2);
}
strNewLocation = strNewLocation.Mid(nPlace + 10);
nPlace = strNewLocation.Find('\n');
if (nPlace > 0)
strNewLocation = strNewLocation.Left(nPlace);
// close up the redirected site
pFile->Close();
delete pFile;
pServer->Close();
delete pServer;
if (bProgressMode)
{
cerr << _T("Caution: redirected to ");
cerr << (LPCTSTR) strNewLocation << endl;
}
// figure out what the old place was
if (!AfxParseURL(strNewLocation, dwServiceType, strServerName, strObject, nPort))
{
cerr << _T("Error: the redirected URL could not be parsed.") << endl;
ThrowTearException(2);
}
if (dwServiceType != INTERNET_SERVICE_HTTP)
{
cerr << _T("Error: the redirected URL does not reference a HTTP resource.") << endl;
ThrowTearException(2);
}
// try again at the new location
pServer = session.GetHttpConnection(strServerName, nPort);
pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_GET,
strObject, NULL, 1, NULL, NULL, dwHttpRequestFlags);
pFile->AddRequestHeaders(szHeaders);
pFile->SendRequest();
pFile->QueryInfoStatusCode(dwRet);
if (dwRet != HTTP_STATUS_OK)
{
cerr << _T("Error: Got status code ") << dwRet << endl;
ThrowTearException(2);
}
}
cerr << _T("Status Code is ") << dwRet << endl;
TCHAR sz[1024];
while (pFile->ReadString(sz, 1023))
{
if (bStripMode)
StripTags(sz);
cout << sz;
}
// NOTE: Since HTTP servers normally spit back plain text, the
// above code (which reads line by line) is just fine. However,
// other data sources (eg, FTP servers) might provide binary data
// which should be handled a buffer at a time, like this:
#if 0
while (nRead > 0)
{
sz[nRead] = '\0';
if (bStripMode)
StripTags(sz);
cout << sz;
nRead = pFile->Read(sz, 1023);
}
#endif
pFile->Close();
pServer->Close();
}
catch (CInternetException* pEx)
{
// catch errors from WinINet
TCHAR szErr[1024];
pEx->GetErrorMessage(szErr, 1024);
cerr << _T("Error: (") << pEx->m_dwError << _T(") ");
cerr << szErr << endl;
nRetCode = 2;
pEx->Delete();
}
catch (CTearException* pEx)
{
// catch things wrong with parameters, etc
nRetCode = pEx->m_nErrorCode;
TRACE1("Error: Exiting with CTearException(%d)\n", nRetCode);
pEx->Delete();
}
if (pFile != NULL)
delete pFile;
if (pServer != NULL)
delete pServer;
session.Close();
return nRetCode;
}
alantop
|
|
|
|
|
shuchigo_jane wrote: it gives me a "debug assertion failed" message...
Knowing what line of what file would go a long way towards solving the problem.
"The largest fire starts but with the smallest spark." - David Crow
|
|
|
|
|
Hi Friend,
I am creating very basic C++ checklist for developer. I have include lots of comments however I am looking for more..... Can you please let me know some of your valuable comments.
Thanks
|
|
|
|
|
itkid wrote: very basic C++ checklist for developer.
Such as?! Would you mind listing one or two samples for us to get clearer what the check list is about? Then I can add some of mine.
Maxwell Chen
|
|
|
|