[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.interop

Marshalling CComBstr to System.String

akumaramar

3/1/2007 1:32:00 PM

Hi,

I have below declaration in C#

void
UpdateSpousePayrollDetails([MarshalAs(UnmanagedType.IUnknown)]Object
termlf, [MarshalAs(UnmanagedType.IUnknown)]Object dpyCdh,
[MarshalAs(UnmanagedType.BStr)]String SD04);

and want to call this function from C++. The code to call this
function is

CComBSTR SD04;
SD04 = L"N";
pTermlfRules->UpdateSpousePayrollDetails(pObj,pUnkPydCdh,SD04);

While compilation, I am getting following error.

cannot convert parameter 3 from 'ATL::CComBSTR' to '_bstr_t' . No user-
defined-conversion operator available that can perform this
conversion, or the operator cannot be called.

I can not use SD04 as _bstr_t instead of CComBSTR. Since, it is being
used lots of places and I need to change lots of VC++ code. Initial 2
parameters are working properly.

How can we resolve this issue?

Thanks

Ajay

1 Answer

(Mattias Sjögren)

3/1/2007 9:45:00 PM

0

>cannot convert parameter 3 from 'ATL::CComBSTR' to '_bstr_t' . No user-
>defined-conversion operator available that can perform this
>conversion, or the operator cannot be called.

This is a C++ problem that isn't really related to the fact that the
method you're calling is implemented in C#. So you may want to turn to
the microsoft.public.dotnet.languages.vc groups for a better answer.

That said, try something like this

_bstr_t tmp((BSTR)SD04, true);
pTermlfRules->UpdateSpousePayrollDetails(pObj,pUnkPydCdh,tmp);



Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.n... | http://www.dotneti...
Please reply only to the newsgroup.