` Printed Icetips Article

Icetips Article



Windows API: Using LoadLibrary and FreeLibary to dynamically call external procedures
2004-03-04 -- Andy Ireland
 
Newsgroups: softvelocity.public.clarion6

Hi Robert,

> Can you  help me do that, or point me to the right direction on how to do
> that?

Yeah load the DLL using LoadLibrary / FreeLibrary
Get the addresses to the functions using GetProcAddress

Bind to functions like so....

  map
    module('typedefs') ! This would be the API declarion for each function
      TestFunc::type(),long,type,pascal
    end
    module('aliases') ! a long ptr alias over the Func type decl below
      TestFunc(long pf, ),long,name('__TestFunc'),pascal
    end
    module('mymodule')
      TestFunc(TestFunc::type pf, ),long,name('__TestFunc'),pascal
    end
  end


TestFunc procedure(TestFunc::type pfTestFunc, )

  code
    return pfTestFunc()


  compile('Unicode', _Unicode_)
    pf = __GetProcAddress(hModule, szFuncW)
  Unicode
  omit('Ansi', _Unicode_)
    pf = __GetProcAddress(hModule, szFuncA)
  Ansi

?   assert(pf)
    if ~pf
      return 0.

    fSuccessful = true
    return TestFunc(pf, )

The two overloaded defs allow you to pass the function address instead of a
clartion function type to the stub that makes the actual call to the
function in the Mapi32 DLL.

Regards

Andy



Printed November 23, 2024, 2:22 am
This article has been viewed/printed 35303 times.
Google search has resulted in 159 hits on this article since January 25, 2004.