IltmmCapture::get_TargetStream Example for C++
// This function will write the contents of the target
// data for the passed capture object to a disk file
void WriteTargetMemory(const char *lpszFileName, IltmmCapture* pCapture)
{
HANDLE hFile = NULL;
// write the data to a file
hFile = CreateFile(lpszFileName, // open file name
GENERIC_WRITE, // open for writing
FILE_SHARE_READ, // share for reading
NULL, // no security
CREATE_ALWAYS, // re-create the file
FILE_ATTRIBUTE_NORMAL, // normal file
NULL); // no attr. template
if (hFile == INVALID_HANDLE_VALUE)
{
return;
}
long fl = 0;
unsigned long lBytesWritten;
IltmmMemory *pTarget = NULL;
VARIANT varData;
unsigned char *pBuffer = NULL;
SAFEARRAY sa;
pCapture->get_TargetStream ((IUnknown**)&pTarget);
if(!pTarget)
return;
pTarget->get_BufferSize (&fl);
VariantInit(&varData);
// pass data
memset(&sa, 0, sizeof(sa));
sa.cbElements = sizeof(unsigned char);
sa.cDims = 1;
sa.fFeatures = (FADF_AUTO | FADF_FIXEDSIZE);
sa.pvData = new UCHAR[fl];
sa.rgsabound[0].cElements = fl;
V_VT(&varData) = (VT_ARRAY | VT_UI1);
V_ARRAY(&varData) = &sa;
pTarget->CopyData (0, fl, &varData);
SafeArrayAccessData(V_ARRAY(&varData), (void**)&pBuffer);
WriteFile(hFile, pBuffer, fl, &lBytesWritten, NULL);
SafeArrayUnaccessData(V_ARRAY(&varData));
VariantClear(&varData);
CloseHandle(hFile);
pTarget->Release();
}