user3161924
user3161924

Reputation: 2275

VS2022 - Enabling C++ Language Standard 20 and using CComPtr gives Cannot Convert error?

I enabled language standard ISO C++ 20 Standard (needed for a new c++ source module) and received errors with some ATL items such as CComPtr and CA2W, I enabled /permissive but it still gives the errors. I'm not sure how I fix the following:

CComPtr<IMsRdpDriveCollection>pdrivecolleciton=pnonscriptable->GetDriveCollection();

error C2440: 'initializing': cannot convert from 'IMsRdpDriveCollectionPtr' to 'ATL::CComPtr<IMsRdpDriveCollection>'
message : No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

And:

CString fn=CA2W(filename, CP_UTF8);

error C2440: 'initializing': cannot convert from 'ATL::CA2W' to 'ATL::CStringT<wchar_t,StrTraitMFC<wchar_t,ATL::ChTraitsCRT<wchar_t>>>'
message : No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

How is this fixed?

TIA!!

Upvotes: 1

Views: 240

Answers (1)

user3161924
user3161924

Reputation: 2275

The answer is to do it this way:

IMsRdpDriveCollection* prdpdcpptr=pnonscriptable->GetDriveCollection();
CComPtr<IMsRdpDriveCollection>pdrivecolleciton=prdpdcpptr;

and

CString fn;
fn=CA2W(filename, CP_UTF8);

The reason was posted in comments: allowing construction through two user-defined conversions

Upvotes: 0

Related Questions