Hi fellows,

How can I set a value of any type in VARIANT const pointer? I am tried my best but vain. I am facing compile time error.

Here is sample code

VARIANT *v=NULL;
        v->bstrVal = "Video.Bin";

another try

VARIANT *pValue;
//BSTR *fileName;
const char* pName;
pName = "Video.bin";
pValue = pName;

Many Thanks
Asif

Here is how to allocate a BSTR. There are a few variations of SysAllocString() -- use the one that suits the purpose of your program.

VARIANT vt;
VariantInit(&vt); // initialize the variant
vt.vt = VT_BSTR; // set to BSTR string
vt.bstr_val = SysAllocString(_TEXT("Hello World"));

Here is how to allocate a BSTR. There are a few variations of SysAllocString() -- use the one that suits the purpose of your program.

VARIANT vt;
VariantInit(&vt); // initialize the variant
vt.vt = VT_BSTR; // set to BSTR string
vt.bstr_val = SysAllocString(_TEXT("Hello World"));

Thank you so much for reply,

I which header file this function is sysAllocString() resides? Now the compiler gives me the following error.
'SysAllocateString': identifier not found, even with argument-dependent lookup

Many Thanks
Asif

See the spelling in the error message -- you spelled it wrong. For the header file, just include windows.h or see MSDN

Yup sorry sir that was my spelling mistake. But now here is another compile response...

error C2039: 'bstr_val' : is not a member of 'tagVARIANT'
: see declaration of 'tagVARIANT'
TestingDirectShowManually.cpp(312) : error C2664: 'SysAllocString' : cannot convert parameter 1 from 'const char [12]' to 'const OLECHAR *'

Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Yup sorry sir that was my spelling mistake. But now here is another compile response...

error C2039: 'bstr_val' : is not a member of 'tagVARIANT'
: see declaration of 'tagVARIANT'
TestingDirectShowManually.cpp(312) : error C2664: 'SysAllocString' : cannot convert parameter 1 from 'const char [12]' to 'const OLECHAR *'

Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

yup sir again it was my spelling mistake and now 1st error is removed but still 2nd error comes. It is saying about const OLECHAR *.... see

TestingDirectShowManually.cpp(312) : error C2664: 'SysAllocString' : cannot convert parameter 1 from 'const char [12]' to 'const OLECHAR *'

yup sir again it was my spelling mistake and now 1st error is removed but still 2nd error comes. It is saying about const OLECHAR *.... see

TestingDirectShowManually.cpp(312) : error C2664: 'SysAllocString' : cannot convert parameter 1 from 'const char [12]' to 'const OLECHAR *'

Well sir hurrah! this is now works for me

vt->bstrVal = SysAllocString(L"Video.bin");

But sir another issue now comes that after successfull comiplation of my code when it executing the function

VariantInit(vt); // initialize the variant

It gives me Access voliation error. Should we have to allocate it dynamically using malloc() or new operator?

Thanks

Well sir hurrah! this is now works for me

vt->bstrVal = SysAllocString(L"Video.bin");

But sir another issue now comes that after successfull comiplation of my code when it executing the function

VariantInit(vt); // initialize the variant

It gives me Access voliation error. Should we have to allocate it dynamically using malloc() or new operator?
Thanks

Well hurrah! Ancient Dragon sir you great, Thanks for you good help. I have solved my problem. Many Many.thanks

This question has already been answered. Start a new discussion instead.