Jump to content
  • Advertisement
Sign in to follow this  
Gumgo

Parameters with a DLL?

This topic is 4257 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!