1

I have a TCL application that is intented to run on Windows only and uses twapi to access some Windows-specific functions.

Now I need to call some C function that are in a custom DLL.

I know I can load the DLL with twapi::load_library (should be the same as LoadLibraryEx()) but I can't understand how to call a function within the DLL itself!

What did I miss?

I would prefer to avoid other dependencies (like critcl, for example) and to avoid to have to transform the current dll in a tcl extension (e.g. via SWIG) so a twapi only solution would be really helpful!

3 Answers 3

2

TWAPI doesn't seem to provide any public binding of GetProcAddress (the Windows API function for getting from the name to the address of a function in a DLL).

Use ffidl for simple APIs (i.e., where there are no callbacks) or critcl (for all kinds of APIs, including those with callbacks, because it can do much more extensive code generation; more effort to use though).

3
  • 2
    Having support for GetProcAddress is not really enough as one have to marshal and unmarshal arguments when performing calls to external code. That's why complicated frameworks like ffidl do exist. Well, it's even a bit strange twapi supports loading a DLL if it can't do anything useful with it afterwards ;-)
    – kostix
    Mar 30, 2012 at 13:26
  • @kostix That's pretty much what I was thinking too. Mar 30, 2012 at 14:29
  • Yep, having load_library made me hope I had some other way of calling a general function. I could play with the source code to modify the undocumented twapi::Call function. But I probably won't.
    – Remo.D
    Mar 30, 2012 at 18:40
1

twapi's load_library command is there for manipulating the resources in a dll (string tables, icon etc.). It's not intended for calling functions in the dll since that, as Donal points out, requires marshalling and some code generation.

0

Looks like you'll have to use ffidl to do the job.

1
  • Thanks kostix, I was hoping to avoid another dependency since twapi has to deal with DLL anyway. ffidl or critcl will be my fallback.
    – Remo.D
    Mar 30, 2012 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.