Re: load string from stringtable inside a windows service
On Feb 12, 11:43 pm, Joseph M. Newcomer <newco...@flounder.com> wrote:
If you are a service, how are you showing a message box?
Since you show no code, there is no way to tell what is happening. The=
short answer is:
you are doing something wrong, fix it. Without seeing any code, that's=
all the answer
that can be given.
joe
On Thu, 12 Feb 2009 02:08:07 -0800 (PST), Janma <rohi...@gmail.com> wrote=
:
I am using a windows service and am calling an mfc function which
writes to log. The function is inside another MFC App project. Inside
that function i am loading a string from stringtable and writing it to
the logfile. The issue is that the string is not getting written to
the log. If before writing to the log, i display the string in
messagebox, it shows up correctly. but its not showing in the log
file.
In DLL we do a AFX_MANAGE_STATE(AfxGetStaticModuleState()). Do we have
to do that in service also?
Can anyone tell why this is happening?
Thanks,
Rohit
Joseph M. Newcomer [MVP]
email: newco...@flounder.com
Web:http://www.flounder.com
MVP Tips:http://www.flounder.com/mvp_tips.htm
I am not showing a message in the service. I am having two projects.
one is an mfc dialog app. and other is a service. I have created all
the resources in the mfc app. I have also created an mfc class in the
app for some functionality. It also writes the date\time to log. I am
sharing this class between service and mfc app. If i use this class
inside the MFC app then it works fine and writes date time to log. But
when i use this class inside the service it does not write the date
time to log.
This i assume might be happening because the string resource that i am
using inside the service is actually defined inside the mfc app.
Below is some piece of code.
void CMyLog::OpenLogFile(CString strPath)
{
CString errStr;
int err = _tfopen_s(&logFile, strPath, _T("w+"));
if(logFile == NULL)
return;
CString logStr(_T
("\n***********************************************************************=
*****************************
\n"));
_ftprintf_s(logFile, logStr);
SYSTEMTIME st;
GetLocalTime(&st);
errStr.LoadString(IDS_LOGERR_DATE); \\\\\\\\\\\\\\\\\\\
IDS_LOGERR_DATE --------> DATE - %d/%d/%d TIME - %d:%d:%d \n
logStr.Format(errStr, st.wMonth, st.wDay, st.wYear, st.wHour,
st.wMinute, st.wSecond);
_ftprintf_s(logFile,logStr);
_ftprintf_s(logFile, _T
("*************************************************************************=
***************************
\n"));
fflush(logFile);
}
Here the string logStr is not getting written correctly to the
logfile.
If i try doing logStr.Format(L"DATE - %d/%d/%d TIME - %d:%d:%d \n",
st.wMonth, st.wDay, st.wYear, st.wHour, st.wMinute, st.wSecond);
i.e. using the string from the stringtable directly into the code then
it gets written properly to the log.
I hope now the issue is clear. Let me know if any questions.
Thanks,
Rohit