Visual basic for windows – Measurement Computing ADLIB WIN User Manual

Page 28

Advertising
background image

Chapter 6 Memory Buffer Allocation

6-4

long FAR PASCAL_ export AdlibBufferProc (hwnd, message, wParam, 1Param)
{
LPBUFFSTRUT

1pbuff;


lpbuff = (LPBUFFSTRUCT) 1Param;

/*do something with the buffer*/

}

3. The third method involves getting a pointer to a specific buffer with the ADLIB function

AL_GetBuffPtr(LHLD, BufferNumber). Once obtained, this pointer is valid until a device is either
released or re-initialized. The user application can then monitor the actual buffer status to determine
when the buffer is complete, the number of samples available and the current error condition. The
buffer still needs to be cleared with the AL_ClearBufferDoneFlag(LHLD) when running in a
continuous mode of operation, otherwise an error will be indicated in the buffer structure when the
driver attempts to re-use the buffer.

4. The fourth method uses a CALLBACK function supported by MSC only. Each time a buffer is

completed the CALLBACK routine will be invoked, passing a pointer to the buffer structure in the
LPBUFFSTRUCT parameter. See example program adlai08.

6.4.2 Visual Basic for Windows

1. The first method involves calling the ADLIB function AL_GetBufferStatus(LHLD, lpDataBuffStat As

DATABUFFSTATUS, lBuffNum) with the lBuffNum set to the predefined Global constant
DONE_BUFFER. Specifying DONE_BUFFER fills lpDataBuffStat with the current status on the next
buffer in sequence from 0 thru n that has been completed. The programmer must check the
lpDataBuffStat status flags for a BUFFER_FULL flag. Once the buffer is full the AL_CopyBuffer
function can be called to retrieve the data. See example program adlai02.

2. The second method uses Windows Post-message handler routine installed by the user application.

Each time a buffer is completed the user routine will be called, passing the completed buffer number in
the wParam parameter. The programmer then uses the buffer number to check the status and copy the
data from the internal ADLIB buffer. See example program adlai01.

Example:

Sub MsgBlaster1_Message (MsgVal As Integer, wParam As Integer, lParam As Long, ReturnVal As
Long)

' Collect the data and display

errnum& = AL_GetBufferStatus(gblLhld&, lpDataBuffStat, DONE_BUFFER)
If errnum& < 0 Then
MsgBox "AL_GetBufferStatus Error", MB_ICONSTOP, "ADLIB Error"
Form_Unload (1)
End If

' Check the status and error flags
If lpDataBuffStat.lStatusFlags <> BUFFER_FULL Then
Msg = "Incomplete Buffer Status = "
Msg = Msg & lpDataBuffStat.lStatusFlags
MsgBox Msg, MB_ICONSTOP, "ADLIB Buffer Status"
Form_Unload (1)
End If

Advertising