National Instruments 320685D-01 ユーザーズマニュアル

ページ / 211
Chapter 4
Windows 3.1 Compiler/Linker Issues
©
 National Instruments Corporation
4-21
LabWindows/CVI Programmer Reference Manual
Recognizing Windows Messages Passed from a DLL 
The normal way of communicating with a DLL is to call functions in the DLL. However, 
cases exist where other communication methods are necessary. The most typical case is that 
of an interrupt service routine in a DLL that must notify the application that the interrupt 
occurred. In cases like this, you must communicate with the DLL through a callback function.
LabWindows/CVI recognizes messages posted by a DLL through the Windows SDK 
function
PostMessage
, and can initiate a user callback function. This method is useful 
for hardware interrupts, but it is subject to the latency associated with Windows messaging. 
LabWindows/CVI uses 
RegisterWinMsgCallback
UnRegisterWinMsgCallback
, and 
GetCVIWindowHandle
 to recognize Windows messages from a DLL. You can call these 
functions from a module compiled in Watcom or from source code.
For complete information on these functions, refer to the function descriptions in Chapter 4, 
User Interface Library Reference, of the LabWindows/CVI User Interface Reference Manual
To use these functions, call 
RegisterWinMsgCallback
 and 
GetCVIWindowHandle
. Pass 
their return values, the message number and the window handle, to the DLL. When the DLL 
sends a message, it calls 
PostMessage
 with these values. When LabWindows/CVI receives 
the message, it calls the callback function.
Note
LabWindows/CVI can receive the message only when it is processing events. 
LabWindows/CVI processes events when it is waiting for user input. If the 
program you run in LabWindows/CVI does not call 
RunUserInterface
GetUserEvent
, or 
scanf
, or if it does not return from a User Interface Library 
callback, events will not be processed. You can remedy this in the program by 
periodically calling the User Interface Library function 
ProcessSystemEvents
.
Creating 16-bit DLLs with Microsoft Visual C++ 1.5
Be sure to consider the following issues or project options when you create a DLL with 
Microsoft Visual C++ 1.5:
Every function you call from outside the DLL must be 
far
, exported, and must load the 
data segment into the DS register. The function must load the DS register if you want to 
use any non-local variables in a function.
Use the large or huge memory model. The savings you gain by using smaller memory 
models is not worth having to use the 
far
 keyword throughout your code. This project 
option is in Compiler»Memory Model»Segment Setup.
You can make the compiler load the data segment into the DS register automatically by 
using the SS!=DS, DS loaded on function entry project option in Compiler»Memory 
Model»Segment Setup
.
If you try to use the optimize entry code option (
/GD
), by selecting 
Compiler»Windows»Prolog/Epilog»Generate Prolog/Epilog For, it conflicts with the 
00ProRef.book : 06chap04.fm  Page 21  Monday, March 9, 1998  3:23 PM