Public Group

# Parameters with a DLL?

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

## 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)();

...

{
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 on other sites

And if libholder is type HMODULE you don't need to cast it

##### 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 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 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.

1. 1
2. 2
3. 3
4. 4
5. 5
Rutin
18

• 11
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631420
• Total Posts
2999990
×