PDA

View Full Version : Late binding for DLL's


R. T. (Fortran Man)
08-11-2003, 09:04 PM
I need to be able to load a DLL at runtime, instead of binding to the DLL when I link my program. Do you have any examples of late binding and dynamically loading a DLL at runtime?

Lahey Support
08-11-2003, 11:05 PM
The attached zip file contains source code and a batch file to build a small example of how to do late binding using the LoadLibrary and GetProcAddress Windows API functions. The DLL procedure is called using the CreateProcess API function. Unfortunately, the CreateThread API only allows you to pass one argument. A single argument can contain as much data as you wish, however, if it is a derived type. The attached program demonstrates how to do this.

langbetz
02-04-2011, 11:14 AM
Thank you for the small example, however, if still possible I have a question concerning it.
I did use the example as a template to comunicate with a DLL which I would like to access at runtime. The dll was created on a Win7 64 bit machine with Matlab. I built my test executable on a Win XP 32 bit machine and when I execute the programm crashes. The interessting thing is, if I execute on a win7 64 bit machine I get the expected results and the programm runs through.

Can anybody provide me with an explanation? Are there any platform or windows version dependent matters concerning the 'CreateThread' or 'WaitForSingleObject' functions?

I also have seen a similar approach using the LoadLibrary command where however the dll is accessed using a pointer / interface / subroutine construct which I don't quite understand. Has anybody an idea of such an approach and could maybe provide me with a modified 'LoadLibrary...' example??

Any help would be reallly appreciated.