cplau
asked on
BSTR Problem!
Hi,
I am using an automation component which was developed by someone else?
After importing the corresponding *.tlb file,
the complier will genearte one *.tlh file which contain the following code!
__declspec(implementation_ key(191))
HRESULT IFnVersionableDual::Checko ut ( BSTR * CheckoutPath, _bstr_t Directory, _bstr_t FileName, const _variant_t & Options );
When I use the Checkout method,
I want to know how can I enter the paramter correctly.
I have tried this:
MyObject->Checkout("c:\\te st.txt", "c:\\", "test.txt");
But it cannot be complied
The erros is cannot convert parameter 1 from 'char [1]' to 'unsigned short ** '.
How can I correct this problem?
Thanks!
I am using an automation component which was developed by someone else?
After importing the corresponding *.tlb file,
the complier will genearte one *.tlh file which contain the following code!
__declspec(implementation_
HRESULT IFnVersionableDual::Checko
When I use the Checkout method,
I want to know how can I enter the paramter correctly.
I have tried this:
MyObject->Checkout("c:\\te
But it cannot be complied
The erros is cannot convert parameter 1 from 'char [1]' to 'unsigned short ** '.
How can I correct this problem?
Thanks!
use AllocSysString():
CString str("Hockey is Best!");
BSTR bstr = str.AllocSysString();
good luck
CString str("Hockey is Best!");
BSTR bstr = str.AllocSysString();
good luck
sorry, for the first parameter you should do the following:
_bstr_t CheckOutPath ( _T("c:\\test.txt") );
MyObject->Checkout(
CheckOutPath,
_T("c:\\"),
_T( "test.txt") );
_bstr_t CheckOutPath ( _T("c:\\test.txt") );
MyObject->Checkout(
CheckOutPath,
_T("c:\\"),
_T( "test.txt") );
BSTR was defined as unsigned short* . So please use unsigned short** in the place of BSTR*. I hope this will solve your problem.
BSR
BSR
>> CString str("Hockey is Best!");
>> BSTR bstr = str.AllocSysString();
If you use this code, you have to add an ::SysFreeString(bstr); later!
Instead of allocating a BSTR this way, you can also
1. #include <afxpriv.h>
2. Place an USES_CONVERSION; as the first line of the function.
3. Use T2OLE() to convert from the TCHAR to BSTR/OLECHAR.
->
#include <afxpriv.h>
void doit()
{
USES_CONVERSION;
MyObject->Checkout(T2OLE(_ T("c:\\tes t.txt")), T2OLE(_T("c:\\")), T2OLE(_T("test.txt")));
}
>> BSTR bstr = str.AllocSysString();
If you use this code, you have to add an ::SysFreeString(bstr); later!
Instead of allocating a BSTR this way, you can also
1. #include <afxpriv.h>
2. Place an USES_CONVERSION; as the first line of the function.
3. Use T2OLE() to convert from the TCHAR to BSTR/OLECHAR.
->
#include <afxpriv.h>
void doit()
{
USES_CONVERSION;
MyObject->Checkout(T2OLE(_
}
ASKER
Hi All,
In the tlh file, I also found this code,
__declspec(property(get=Ge tNumber))
_bstr_t Number;
When I try to read this object's properties like this
MyObject->Number
Do I need to do any coversion to get the correct value?
Thanks!
In the tlh file, I also found this code,
__declspec(property(get=Ge
_bstr_t Number;
When I try to read this object's properties like this
MyObject->Number
Do I need to do any coversion to get the correct value?
Thanks!
i still think that it better that u maintain your allocation and free instead of rely on the systme
_bstr_t is a wrapper-class for BSTR, so you can read the Number-property like you suggest. There is no conversion needed.
first of all is CheckoutPath an [in],[out],[in,out] parameter - what is in the idl?
this will determine how we deal with it - because it is a BSTR* then I suspect it is an [out] or [in,out] - however it could have just been defined incorrectly
if [out]
_bstr_t bstrCheckout;
MyObject->Checkout(&bstrCh eckout, "c:\\", "test.txt");
if [in,out]
_bstr_t bstrCheckout(_T("c:\\test. txt"));
MyObject->Checkout(&bstrCh eckout, _T("c:\\"), _T("test.txt"));
I hope this helps
this will determine how we deal with it - because it is a BSTR* then I suspect it is an [out] or [in,out] - however it could have just been defined incorrectly
if [out]
_bstr_t bstrCheckout;
MyObject->Checkout(&bstrCh
if [in,out]
_bstr_t bstrCheckout(_T("c:\\test.
MyObject->Checkout(&bstrCh
I hope this helps
however you may have to do it like this if _bstr_t doesn't support & operator to return a pointer to its internal BSTR (which I know CComBSTR does)
if [out]
BSTR bstrCheckout=NULL;
MyObject->Checkout(&bstrCh eckout, "c:\\", "test.txt");
::SysFreeString(bstrChecko ut);
if [in,out]
BSTR bstrCheckout=::SysAllocStr ing(T2W((_ T("c:\\tes t.txt")))) ;
MyObject->Checkout(&bstrCh eckout, _T("c:\\"), _T("test.txt"));
::SysFreeString(bstrChecko ut);
if [out]
BSTR bstrCheckout=NULL;
MyObject->Checkout(&bstrCh
::SysFreeString(bstrChecko
if [in,out]
BSTR bstrCheckout=::SysAllocStr
MyObject->Checkout(&bstrCh
::SysFreeString(bstrChecko
ASKER
Dear All,
At my first question,
__declspec(implementation_ key(191))
HRESULT IFnVersionableDual::Checko ut ( BSTR * CheckoutPath, _bstr_t Directory, _bstr_t FileName, const
_variant_t & Options );
The fourth paramter is the optional paramter
CString str("c:\\yyee.txt");
BSTR bstr = str.AllocSysString();
CString str1("c:\\");
BSTR bstr1 = str1.AllocSysString();
CString str2("yyee.txt");
BSTR bstr2 = str2.AllocSysString();
COleVariant name(1);
Temp->Checkout(&bstr,bstr1 ,bstr2,nam e);
But the following error :
COleVariant::COleVariant' : ambiguous call to overloaded function
I've also tried using this
ColeVairant name("%d", 1);
But the program crash while running!
What mistake had I made?
How can I input the fourth parameter with a value of 1?
Thanks!
At my first question,
__declspec(implementation_
HRESULT IFnVersionableDual::Checko
_variant_t & Options );
The fourth paramter is the optional paramter
CString str("c:\\yyee.txt");
BSTR bstr = str.AllocSysString();
CString str1("c:\\");
BSTR bstr1 = str1.AllocSysString();
CString str2("yyee.txt");
BSTR bstr2 = str2.AllocSysString();
COleVariant name(1);
Temp->Checkout(&bstr,bstr1
But the following error :
COleVariant::COleVariant' : ambiguous call to overloaded function
I've also tried using this
ColeVairant name("%d", 1);
But the program crash while running!
What mistake had I made?
How can I input the fourth parameter with a value of 1?
Thanks!
cplau: initialaize the 'name' like this:
COleVariant name(1.0);
and it will work... :)
COleVariant name(1.0);
and it will work... :)
cplau: initialaize the 'name' like this:
COleVariant name(1.0);
and it will work... :)
COleVariant name(1.0);
and it will work... :)
or even better:
COleVariant name((short)1); !!!
since there's no constructor for int...
cheer
COleVariant name((short)1); !!!
since there's no constructor for int...
cheer
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
great, using my comment to get the points
Isn't this the point there was a quite lengthy discussion about a short time ago?
:-/
:-/
whatever
MyObject->Checkout(
_T("c:\\test.txt"),
_T("c:\\"),
_T( "test.txt") );