C++ Addtarget problem

All you've ever wanted to know about the ActiveX, Mozilla plugins, the web interface and various PHP extensions
bill585

C++ Addtarget problem

Postby bill585 » 17 Apr 2006 14:55

I have problem adding options to the addtarget function.
When I run the following code it works OK when run from the exe file,
When it’s run inside the Visual Studio 7 environment it stops with these messages.

Heap block at 001BEF48 modified at 001BEF50 past requested size of 0
Unhandled exception at 0x7c901230
Invalid Address specified to RtlFreeHeap( 00150000, 001B6908 )

What am I doing wrong?

const int VLCPlayListGo = 0x8;
VARIANT v;
long pos=0;

LPSAFEARRAY m_pSA = SafeArrayCreateVector(VT_VARIANT, 0, 1);
_variant_t var(_bstr_t(":audio-track=2"));
SafeArrayPutElement(m_pSA, &pos, (void FAR*)&var);
v.parray = m_pSA;
v.vt = VT_ARRAY;

vlc.addTarget(streamInfo, v, VLCPlayListGo, -666);

Quovodis
Cone that earned his stripes
Cone that earned his stripes
Posts: 271
Joined: 16 Jun 2004 11:13
Location: Cork, Ireland

Postby Quovodis » 18 Apr 2006 12:24

are you using vlc 0.8.5-test2 ? there is a problem with 0.8.4 regarding bounds checking

bill585

Postby bill585 » 18 Apr 2006 19:02

I have tried with .84 but it’s the same.

I have looked at source code "vlccontrol.cpp: ActiveX control for VLC".

There seem to be bugs in the function createTargetOptions.
I have marked the code where the bug are.


static HRESULT createTargetOptions(int codePage, VARIANT *options, char ***cOptions, int *cOptionCount)
{
HRESULT hr = E_INVALIDARG;
if( VT_ERROR == V_VT(options) )
{
if( DISP_E_PARAMNOTFOUND == V_ERROR(options) )
{
// optional parameter not set
*cOptions = NULL;
*cOptionCount = 0;
return NOERROR;
}
}
else if( (VT_EMPTY == V_VT(options)) || (VT_NULL == V_VT(options)) )
{
// null parameter
*cOptions = NULL;
*cOptionCount = 0;
return NOERROR;
}
else if( VT_DISPATCH == V_VT(options) )
{
// collection parameter
VARIANT colEnum;
V_VT(&colEnum) = VT_UNKNOWN;
hr = GetObjectProperty(V_DISPATCH(options), DISPID_NEWENUM, colEnum);
if( SUCCEEDED(hr) )
{
IEnumVARIANT *enumVar;
hr = V_UNKNOWN(&colEnum)->QueryInterface(IID_IEnumVARIANT, (LPVOID *)&enumVar);
if( SUCCEEDED(hr) )
{
long pos = 0;
long capacity = 16;
VARIANT option;

*cOptions = (char **)malloc(capacity*sizeof(char *));
if( NULL != *cOptions )
{
ZeroMemory(*cOptions, sizeof(char *)*capacity);
while( SUCCEEDED(hr) && (S_OK == enumVar->Next(1, &option, NULL)) )
{
if( VT_BSTR == V_VT(&option) )
{
char *cOption = CStrFromBSTR(codePage, V_BSTR(&option));
(*cOptions)[pos] = cOption;
if( NULL != cOption )
{
++pos;
if( pos == capacity )
{
char **moreOptions = (char **)realloc(*cOptions, (capacity+16)*sizeof(char *));
if( NULL != moreOptions )
{
ZeroMemory(moreOptions+capacity, sizeof(char *)*16);
capacity += 16;
*cOptions = moreOptions;
}
else
hr = E_OUTOFMEMORY;
}
}
else
hr = E_OUTOFMEMORY;
}
else
hr = E_INVALIDARG;

VariantClear(&option);
}
*cOptionCount = pos;
if( FAILED(hr) )
{
// free already processed elements
freeTargetOptions(*cOptions, *cOptionCount);
}
}
else
hr = E_OUTOFMEMORY;
enumVar->Release();
}
}
}
else if( V_ISARRAY(options) )
{
// array parameter
SAFEARRAY *array = V_ISBYREF(options) ? *V_ARRAYREF(options) : V_ARRAY(options);

if( SafeArrayGetDim(array) != 1 )
return E_INVALIDARG;

long lBound = 0;
long uBound = 0;
SafeArrayGetLBound(array, 1, &lBound);
SafeArrayGetUBound(array, 1, &uBound);

// have we got any options
if( uBound > lBound )
{
VARTYPE vType;
HRESULT hr = SafeArrayGetVartype(array, &vType);
if( FAILED(hr) )
return hr;

long pos;

// marshall options into an array of C strings
if( VT_VARIANT == vType )
{
*cOptions = (char **)malloc(sizeof(char *)*(uBound-lBound));
if( NULL != options )
return E_OUTOFMEMORY;


for(pos=lBound; SUCCEEDED(hr) && (pos<uBound); ++pos )
{
VARIANT option;
hr = SafeArrayGetElement(array, &pos, &option);
if( SUCCEEDED(hr) )
{
if( VT_BSTR == V_VT(&option) )
{
char *cOption = CStrFromBSTR(codePage, V_BSTR(&option));
(*cOptions)[pos-lBound] = cOption;
if( NULL == cOption )
hr = E_OUTOFMEMORY;
}
else
hr = E_INVALIDARG;
VariantClear(&option);
}
}
}
else if( VT_BSTR == vType )
{
*cOptions = (char **)malloc(sizeof(char *)*(uBound-lBound));
if( NULL != options )
return E_OUTOFMEMORY;


ZeroMemory(cOptions, sizeof(char *)*(uBound-lBound));
for(pos=lBound; SUCCEEDED(hr) && (pos<uBound); ++pos )
{
BSTR option;
hr = SafeArrayGetElement(array, &pos, &option);
if( SUCCEEDED(hr) )
{
char *cOption = CStrFromBSTR(codePage, option);
(*cOptions)[pos-lBound] = cOption;
if( NULL == cOption )
hr = E_OUTOFMEMORY;
SysFreeString(option);
}
}
}
else
// unsupported type
return E_INVALIDARG;

*cOptionCount = pos-lBound;
if( FAILED(hr) )
{
// free already processed elements
freeTargetOptions(*cOptions, *cOptionCount);
}
}
else
{
// empty array
*cOptions = NULL;
*cOptionCount = 0;
return NOERROR;
}
}
return hr;
};

Quovodis
Cone that earned his stripes
Cone that earned his stripes
Posts: 271
Joined: 16 Jun 2004 11:13
Location: Cork, Ireland

Postby Quovodis » 21 Apr 2006 11:19

this has been fixed, please try 0.8.5-test3 (http://downloads.videolan.org/pub/video ... .8.5-test3)

Guest

Postby Guest » 21 Apr 2006 14:13

I want to control vlc automatically and set it parameters automatically but do not exactly how to do. Is this the thing is close to what I want to do.
Please reply.
Thanking you.
nadz


Return to “Web and scripting”

Who is online

Users browsing this forum: No registered users and 28 guests