Googles appar
Huvudmeny

Post a Comment On: cbloom rants

"07-27-11 - CALL_IMPORT"

1 Comment -

1 – 1 of 1
Anonymous Anonymous said...

For a header-file library I'm wrting I need to do a bunch of windows functions, and I don't want to include windows.h and I don't want to rely on the functions being available, so my code looks like this:

extern __declspec(dllimport) int (__stdcall * __stdcall GetProcAddress (struct HINSTANCE__ *module, const char *procname))();

...

struct HINSTANCE__ *net = LoadLibraryA("NETAPI32.DLL");

#define STB__GETPROCA(dll, name, var, rtype, args) \
rtype (__stdcall *var) args = (rtype (__stdcall *) args) (dll ? GetProcAddress(dll, name) : 0)

STB__GETPROCA(net, "NetStatisticsGet" , netstatget , unsigned long, (stbc_u16 *, stbc_u16 *, stbc_u32, stbc_u32, stbc_u8 **));
STB__GETPROCA(net, "NetApiBufferFree" , netfree , unsigned long, (stbc_u8 *));

if (netstage && netfree) {
...
}

if (adv) FreeLibrary(adv);

which isn't too bad since I have like 4 DLLs and 10 functions -- in the end the boilerplate doesn't drown things out too much.

July 30, 2011 at 2:50 AM

You can use some HTML tags, such as <b>, <i>, <a>

This blog does not allow anonymous comments.

Comment moderation has been enabled. All comments must be approved by the blog author.

You will be asked to sign in after submitting your comment.