Parameters with a DLL?

Started by
3 comments, last by LessBread 17 years ago
Hi, I'm using a dll in my project and I need to know how to be able to use the parameters for the functions. Here is the DLL "initialization" code:

typedef void (WINAPI*cfunc)();

...

bool NetworkClass::LoadDLL()
{
	libholder = LoadLibrary( "39dll.dll" );
	if (libholder == NULL)
		return 0;
	writebyte = (cfunc)GetProcAddress( (HMODULE)libholder, "writebyte" );
	writestring = (cfunc)GetProcAddress( (HMODULE)libholder, "writestring" );
	writeshort = (cfunc)GetProcAddress( (HMODULE)libholder, "writeshort" );
... many lines later...
	iptouint = (cfunc)GetProcAddress( (HMODULE)libholder, "iptouint" );
	uinttoip = (cfunc)GetProcAddress( (HMODULE)libholder, "uinttoip" );
	netconnected = (cfunc)GetProcAddress( (HMODULE)libholder, "netconnected" );
	return 1;
}
Anyways, I know that the problem is in typedef void (WINAPI*cfunc)(); because that line defines all of the cfunc's to have no parameters. How can I make it so that each function is able to have its own parameters? Either manually defining, or even better would be loading directly from the DLL (though I doubt I could do that). EDIT: Alternatively, is there a way to just merge the DLL's functions into the project? How to link them in VC++? That'd be even more useful, and I have the source code of the DLL if that would help. That way I wouldn't have to define all the functions again. Basically, some way to get the DLL's functions into my project, without (if possible) copying all the source files in. [Edited by - Gumgo on April 19, 2007 10:33:56 PM]
Advertisement
Have you tried casting the result from GetProcAddress to void* instead?

writebyte = (void*)GetProcAddress(libholder, "writebyte" );

And if libholder is type HMODULE you don't need to cast it
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
If you dont want to dynamically get the function pointers using GetProcAdress, then just add the DLLs headers and lib file to your project, then you can call the DLL functions just like any other function.
Thanks for the responses. "libholder" is HINSTANCE. But it doesn't really matter, I'm just going to do what Hodgman said. The reason I tried this is because I'm having trouble getting the DLL to compile (I only have the DLL and source, not the lib), it seems to be not recognizing printf_s and cpystr_f (but that's a different problem, which hopefully the creator will get back to me on). Anyways, once I figure it out I'll do the easier way.
Just so you know, a HINSTANCE and an HMODULE are the same thing. They both devolve into a void pointer. They both hold the address where the module has been loaded into the virtual address space of the process. HINSTANCE is a throw back to Windows 3. HMODULE came in with 32 bit windows, NT 3.5 and Win95 etc. Just the same, LoadLibrary returns an HMODULE and GetProcAddress expects one. If merging the code doesn't work and you go back to using a dll, you might consider changing the "libholder" type to HMODULE.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man

This topic is closed to new replies.

Advertisement