timmay3141
Programmer
I've never tried to use DLLs for this before, so my mistake could be really stupid. Here's my code:
// above WinMain
typedef DWORD (CALLBACK* LPREGISTERSERVICEPROC)(DWORD,DWORD);
// in WinMain
HMODULE hDLL = LoadLibrary("kernel32.dll"
try
{
if(!hDLL)
throw 0;
LPREGISTERSERVICEPROC lpRegisterServiceProc =
(LPREGISTERSERVICEPROC)::GetProcAddress(hDLL, "RegisterServiceProcess"
if(!lpRegisterServiceProc)
{
DWORD dwError = GetLastError();
throw 0;
}
else
{
DWORD dwRet = lpRegisterServiceProc(GetCurrentProcessId(), 1);
}
}
catch(int nExit)
{
FreeLibrary(hDLL);
MessageBox(NULL, "Error registering process, the program will now abort.",
"Error", MB_OK | MB_ICONSTOP);
return nExit;
}
FreeLibrary(hDLL);
The dll loads correctly, but GetProcAddress() fails. GetLastError() returns 127, which is ERROR_PROC_NOT_FOUND. This is strange, because I think I'm doing exactly what MSDN said:
What's my mistake?
// above WinMain
typedef DWORD (CALLBACK* LPREGISTERSERVICEPROC)(DWORD,DWORD);
// in WinMain
HMODULE hDLL = LoadLibrary("kernel32.dll"
try
{
if(!hDLL)
throw 0;
LPREGISTERSERVICEPROC lpRegisterServiceProc =
(LPREGISTERSERVICEPROC)::GetProcAddress(hDLL, "RegisterServiceProcess"
if(!lpRegisterServiceProc)
{
DWORD dwError = GetLastError();
throw 0;
}
else
{
DWORD dwRet = lpRegisterServiceProc(GetCurrentProcessId(), 1);
}
}
catch(int nExit)
{
FreeLibrary(hDLL);
MessageBox(NULL, "Error registering process, the program will now abort.",
"Error", MB_OK | MB_ICONSTOP);
return nExit;
}
FreeLibrary(hDLL);
The dll loads correctly, but GetProcAddress() fails. GetLastError() returns 127, which is ERROR_PROC_NOT_FOUND. This is strange, because I think I'm doing exactly what MSDN said:
What's my mistake?