Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Using imgDisposeBuffer with C++ CLR

I'm using IMAQ in VisualStudio 2005, writing C++ (using MS' CLR). Things work fine until I attempt release an IMAQ buffer using the imgDisposeBuffer function. When I do that, it returns status xbff600a0 which I believe means "The given buffer wan't created by the NI-IMAQ driver."

What are the possible causes for imgDisposeBuffer to return that status?

TIA -

James Crain

Code follows ----------------------
I allocate 6 or 7 buffers using imgCreateBuffer, fill them with calls to imgSnap, and then call imgDisposeBuffer. There are no buffer lists, rings or other advanced features being used. It's a very plain vanilla use of IMAQ.

Buffer allocation:

typedef uInt16*                PWORD;

mpBuffers = new PWORD[mBandCount];
for (i = 0; i < mBandCount && imgStatus == IMG_ERR_GOOD; i++)    {
    imgStatus = imgCreateBuffer (mSID, IMG_HOST_FRAME,
                                         lSize, (void **) &mpBuffers[i]);
}


Buffer use:

IMAQ_STATUS snapFrame (int Band)        {
    System::Int32    imgStatus = IMG_ERR_GOOD;

    imgStatus = imgSnap (mSID, (void **) &mpBuffers[Band]);
    return imgStatus;
}

Buffer disposal:

for (i = 0; i < mBandCount; i++)    {
    imgStatus = imgDisposeBuffer (mpBuffers[i]);
}
delete [] pBuffers;

0 Kudos
Message 1 of 3
(3,785 Views)

Hello James,

It looks like you might be passing the pointer to the array of buffers instead of the actual buffers that you created.

Take a look at the LL Ring example:

C:\Program Files\National Instruments\NI-IMAQ\Sample\MSVC\Ring\LL Ring

This example is essentially a “bare bones” Ring that uses imgDisposeBuffer to dispose of an array of buffers after the image acquisition is complete.   

Regards,
Luke H

0 Kudos
Message 2 of 3
(3,763 Views)

Luke

Thanks for the reply. What it turned out to be was a type difference between the way I had declared the function in my header file and the way I was calling it at runtime.

In case anyone else is interested, here are the details:

1. Function declaration:

typedef long  IMAQ_STATUS;

#define IMAQ_PREFIX [DllImport("Imaq.dll")]

IMAQ_PREFIX IMAQ_STATUS imgDisposeBuffer(void* bufferPtr);

2. Invocation that returns error (and does not release memory):

 imgStatus = imgDisposeBuffer (pBuffers[i]);

3. CAST, then invocation doesn't return error (and does release memory):

imgStatus = imgDisposeBuffer ((void *) pBuffers[i]);

 

0 Kudos
Message 3 of 3
(3,717 Views)