Chapter 4 Windows3.1 Compiler/Linker Issues
©
National Instruments Corporation 4-13 LabWindows/CVI Programmer Reference Manual
You cannot pass pointers to 32-bit functions directly into 16-bit DLLs. The Windows SDK
interface for this is very complex. Generate DLL Glue Source does not generate this code
for you. You must write your own glue code for passing function pointe rs to and fro m a DLL,
and add it to the file that Generate DLL Glue Source generates.
Suppose a DLL contains the following functions:
long (FAR*savedCallbackPtr) (long);
long FAR InstallCallback(long (FAR*callbackPtr) (long))
{savedCallbackPtr = callbackPtr;
}
long InvokeCallback(long data)
{return (*savedCallbackPtr)(data);
}
After you use the Generate DLL Glue Source command to generate the glue code for these
functions, you must modify the code as follows.
Note Because direct callbacks must be declared far, and LabWindows/CVI cannot
compile far functions, you must declare a far function in the glue code and pass
it to the DLL. This far function calls the actual user function.
#undef MakeProcInstance /* Use version that does not */
/* convert pointer. */
#undef FreeProcInstance /* Use version that does not */
/* convert pointer. */
typedef struct { /* Holds resources required to register*/
/* the callback. */
int UserDefinedProcHandle;
CALLBACKPTR proc16;
FARPROC proc16Instance;
} CallbackDataType;
static CallbackDataType CallbackData;
static long (*UsersCallback)(long);
/* Define a 32-bit far callback whose address is passed to */
/* the DLL. It calls your function using function pointer */
/* stored in UsersCallback. */
00ProRef.book : 06chap04.fm Page 13 Monday, March 9, 1998 3:23 PM