Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using common DLL routines...

3 views
Skip to first unread message

Kenny-Z

unread,
Jan 19, 2003, 1:03:38 PM1/19/03
to
Hi group,

I want to use a couple of functions from SHLWAPI.DLL. I am unsure how to make
these available to my .c source without having to link in import libraries
(Using Run-Time Dynamic Linking). The example in SDK docs is not helping in my
situation... ultimately I just need to be able to call a couple of functions
at run-time.

thanks for any advice,

kz


Barry S. Kyker

unread,
Jan 19, 2003, 1:35:14 PM1/19/03
to
"Kenny-Z" <re...@group.please> wrote in message
news:zLBW9.26$pa1....@news.uswest.net...

Use LoadLibrary to load SHLWAPI.DLL and then use GetProcAddress
to get the address of procedures that you want to call, then use the
returned
addresses to call the functions.

typedef WINSHELLAPI void (WINAPI *dfSHAddToRecentDocs)(UINT uFlags, LPCVOID
pv);

void callRunTimeFunc()
{
HMODULE hLib = LoadLibrary("SHLWAPI.DLL");
dfSHAddToRecentDocs func;

if(!hLib) return;

func = (dfSHAddToRecentDocs)GetProcAddress(hLib, "SHAddToRecentDocs");
if(func) func(SHARD_PATH, "MyDocument");

FreeLibrary(hLib);
}

Best regards,

Barry S. Kyker

Kenny-Z

unread,
Jan 20, 2003, 10:30:38 PM1/20/03
to

Thanks, Barry. I was able to achieve run time linking by using your example as
a model, although, 1) I don't entirely understand the use of typedef, etc.,
and, 2), I was only able to compile by removing the WINSHELLAPI identifier
from the typedef line...

thanks for the help,

kz

"Barry S. Kyker" <bsk...@bellsouth.net> wrote in message
news:sZBW9.17949$F_3....@news.bellsouth.net...

Jugoslav Dujic

unread,
Jan 21, 2003, 6:20:09 AM1/21/03
to
"Kenny-Z" <re...@group.please> wrote in message
news:593X9.455$k43....@news.uswest.net...

|
| Thanks, Barry. I was able to achieve run time linking by using your example as
| a model, although, 1) I don't entirely understand the use of typedef, etc.,
| and,

1) From the viewpoint of just occasional user of C(++): I think
that syntax of pointers-to-functions is just plain ugly, tough
to remember and tough to comprehend. I do understand it when
I see it, but I always have to take a look back when I have
to write it myself.

Obviously,

typedef void (WINAPI *dfSHAddToRecentDocs)(UINT uFlags, LPCVOID pv);

declares that dfSHAddToRecentDocs is a type which is a
pointer to void __stdcall function with given arguments.

There are language rules behind that particular syntax, but
IMO it's easier to just look back at a sample than to try
to remember them ;-). So, if you feel frustrated about
that, at least feel consoled that you're not alone :-)

| 2), I was only able to compile by removing the WINSHELLAPI identifier
| from the typedef line...

2) I think it's just a Barry's copypasto. WINSHELLAPI evaluates
to __declspec(dllimport), which doesn't make sense if you
do GetProcAddress.

--
Jugoslav
___________
www.geocities.com/jdujic


0 new messages