wxAutomationObject in c++20

28 views
Skip to first unread message

David Connet

unread,
Jul 20, 2022, 11:35:56 AM7/20/22
to wx-u...@googlegroups.com
I decided to see how my things compile in c++20...

I have existing code that does (m_App is a wxAutomationObject):
>     wxAutomationObject book = m_App.CallMethod(L"Workbooks.Add",
xlWBATWorksheet).GetAny();

Works fine in c++17. In 20, I get "error C2440: 'initializing': cannot
convert from 'wxVariant' to 'wxAutomationObject'"

So I changed that to:
> wxAutomationObject book = m_App.CallMethod(L"Workbooks.Add",
xlWBATWorksheet).GetAny().As<wxAutomationObject>();

Now I get:
1>d:\devtools\wx\wxWidgets-3.2.0\include\wx\any.h(982,1): error C2280:
'wxAutomationObject::wxAutomationObject(const wxAutomationObject &)':
attempting to reference a deleted function

What is the trick to working with automation objects? (I'm using VS2022)

Dave

David Connet

unread,
Jul 20, 2022, 11:44:38 AM7/20/22
to wx-u...@googlegroups.com
On 7/20/2022 8:35 AM, David Connet wrote:
> I decided to see how my things compile in c++20...

As a followup to that, what's the recommended way of passing in flags
during construction now?

For instance, I have "new wxStaticText(this, wxID_ANY, text,
wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE | wxSTATIC_BORDER);

In c++20, this generates "operator '|': deprecated between enumerations
of different types" warning (and I have warnings-as-errors).

For now, I'm simply disabling that warning via a pragma, but that seems
like a "not good" idea...

Dave

Kenneth Porter

unread,
Jul 20, 2022, 1:55:27 PM7/20/22
to wx-u...@googlegroups.com
--On Wednesday, July 20, 2022 9:44 AM -0700 David Connet
<dc...@agilityrecordbook.com> wrote:

> As a followup to that, what's the recommended way of passing in flags
> during construction now?
>
> For instance, I have "new wxStaticText(this, wxID_ANY, text,
> wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE | wxSTATIC_BORDER);
>
> In c++20, this generates "operator '|': deprecated between enumerations
> of different types" warning (and I have warnings-as-errors).
>
> For now, I'm simply disabling that warning via a pragma, but that seems
> like a "not good" idea...

It looks like defs.h needs wxALLOW_COMBINING_ENUMS(wxAlignment, wxBorder)
around line 1473.

Kenneth Porter

unread,
Jul 20, 2022, 1:59:01 PM7/20/22
to wx-u...@googlegroups.com
--On Wednesday, July 20, 2022 9:35 AM -0700 David Connet
It's trying to use a copy constructor which doesn't exist. Maybe try
initialization without the assignment?

wxAutomationObject book(m_App.CallMethod(L"Workbooks.Add",
xlWBATWorksheet).GetAny());

David Connet

unread,
Jul 20, 2022, 2:27:01 PM7/20/22
to wx-u...@googlegroups.com
Changing results in the same error.

Tried breaking the statement up, and it dies on this too:
>     wxAutomationObject var2(var.As<wxAutomationObject>());

Also, your suggestion doesn't work as it can't automatically convert
from wxAny to wxAutomationObject. Specifically: "cannot convert argument
1 from 'wxAny' to 'WXIDISPATCH *'"

Looks like 'As' is invoking the copy ctor.

Dave

Kenneth Porter

unread,
Jul 20, 2022, 2:57:32 PM7/20/22
to wx-u...@googlegroups.com
--On Wednesday, July 20, 2022 12:26 PM -0700 David Connet
(I haven't used any of this and didn't know the whole OLE thing existed, so
this is based on my inspection of the code.)

It looks like Workbooks.Add is returning a WXIDISPATCH raw pointer, so
perhaps use As<WXIDISPATCH>() and then let the language pass that to the
normal wxAutomationObject ctor.

It looks like C++20 requires more explicit specification of conversions
that were once implicit. So it won't automatically call the
wxAutomationObject ctor in this case and needs the intermediate steps
broken out.

David Connet

unread,
Jul 20, 2022, 3:40:35 PM7/20/22
to wx-u...@googlegroups.com
Ah! That was the trick. I didn't think of using <WXIDISPATCH*> as the
arg to As.

Thanks!

Dave

David Connet

unread,
Jul 20, 2022, 3:49:11 PM7/20/22
to wx-u...@googlegroups.com
Just tested, yup, that works!

Kenneth Porter

unread,
Jul 20, 2022, 4:00:27 PM7/20/22
to wx-u...@googlegroups.com
--On Wednesday, July 20, 2022 1:49 PM -0700 David Connet
<dc...@agilityrecordbook.com> wrote:

>> It looks like defs.h needs wxALLOW_COMBINING_ENUMS(wxAlignment,
>> wxBorder) around line 1473.
>>
> Just tested, yup, that works!

I recommend opening an issue on GitHub for this one. Maybe even a pull
request. It looks like the current code lacks this:

https://github.com/wxWidgets/wxWidgets/blob/e9d299d92ccd9688b81a13b13ca17e53fce32fbd/include/wx/defs.h#L1473

Vadim Zeitlin

unread,
Jul 20, 2022, 6:19:01 PM7/20/22
to wx-u...@googlegroups.com
On Wed, 20 Jul 2022 12:59:56 -0700 Kenneth Porter wrote:

KP> --On Wednesday, July 20, 2022 1:49 PM -0700 David Connet
KP> <dc...@agilityrecordbook.com> wrote:
KP>
KP> >> It looks like defs.h needs wxALLOW_COMBINING_ENUMS(wxAlignment,
KP> >> wxBorder) around line 1473.
KP> >>
KP> > Just tested, yup, that works!
KP>
KP> I recommend opening an issue on GitHub for this one. Maybe even a pull
KP> request. It looks like the current code lacks this:
KP>
KP> https://github.com/wxWidgets/wxWidgets/blob/e9d299d92ccd9688b81a13b13ca17e53fce32fbd/include/wx/defs.h#L1473

Yes, I'm afraid we're going to have to add this too. It doesn't make much
sense in general, which is why I'd prefer not to do it, but it is allowed
for wxStaticText (and a couple of other controls), so I don't see a better
solution... A PR would indeed be welcome, if not I'll do it myself when I
have a bit more time.

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/

David Connet

unread,
Jul 20, 2022, 6:32:07 PM7/20/22
to wx-u...@googlegroups.com
I'm creating an issue for this now and will followup with a PR.

Dave

David Connet

unread,
Jul 20, 2022, 6:40:13 PM7/20/22
to wx-u...@googlegroups.com
I've created the issue and PR - but I think I did something wrong...
They don't appear to be tied together.

Dave

Reply all
Reply to author
Forward
0 new messages