Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem using DLL

Status
Not open for further replies.

timmay3141

Programmer
Dec 3, 2002
468
US
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?
 
Are you sure that RegisterServiceProcess() is an exported function in kernel32.dll ?

On my system (XP) it is not (Can't find it in MSDN either).

/JOlesen
 
Did you check out that link? It said:

Code:
To call RegisterServiceProcess, retrieve a function pointer using GetProcAddress on KERNEL32.DLL. Use the function pointer to call RegisterServiceProcess.

It says it's in kernel32.dll, but my program doesn't seem to think so...
 
Oh .. it is win 9x only function.

What system do you use ?

/JOlesen
 
Not sure...I use XP Pro have the latest Platform SDK if thats what you mean.
 
Well, the function only exist on Win 9x operating systems - That is it won't work on your XP.

/JOlesen
 
Oh, I see. I didn't know what Win 9x meant, that's my problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top