I actually need an expert advice in resolving a situation regard calling InitPK.dll (C++ dll) as a service in windows 7 (Code attached). The dll is loaded successfully but PKAgentInit method is returning 0(false) on Windows 7 using windows service the same works okay in windows XP also the code works fine when exec as a console program on windows 7 . Could you please guide us why PKAgentInit method is returning 0 on Windows 7 and what is the recommended way of calling Agent under Windows 7 using windows service.**
Code:
typedef UINT (CALLBACK* INITPK)();
m_LogDebug->Log(2,nThreadId,cMethod,
"Pre-requisite applications are running so executing Agent...");
hDll = LoadLibrary(AgentPath.c_str());
if(hDll == NULL)
{
m_LogDebug->Log(0,nThreadId,cMethod,
"Failed to load [%s]",AgentPath.c_str());
return false;
}
INITPK InitPK_Func;
if((InitPK_Func = (INITPK)GetProcAddress(HMODULE(hDll), "PKAgentInit")) == NULL)
{
m_LogDebug->Log(0,nThreadId,cMethod,
"Failed to load proc address [%s]",AgentPath.c_str());
return false;
}
UINT Res = InitPK_Func();
// returning 0 which means Agent is not executed successfully.
// Ideally it should return 1.
m_LogDebug->Log(0,nThreadId,cMethod,"PKAgentInit returned [%d]",Res);
Without seeing the source to InitPK_Func()
it's hard to say but I'd guess that it's a privileges problem and the service isn't running as a user that can do what you need to do. Perhaps the code in question needs to be elevated (might be why it works on XP), or perhaps it's touching a network resource (might be why it works as a console app on Win7).
But really, you need to debug the problem function and maybe change it to return a little more information about why it failed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.