wxWidgets help

I am trying to learn wxWidgets. I followed a tutorial on youtube to get started. The tutorial is for VS2017, I am using VS2019 and having trouble. When I try to build the example program from the wxwidgets website. I get this error...


Warning C26495 Variable 'wxAny::m_buffer' is uninitialized. Always initialize a member variable (type.6).

Since it is not my code and just an example, I figure I must have configured something wrong. But I followed the youtube video. The only difference was VS versions. Any help?
There was another thread where you had an issue, but we weren't able to solve the issue until you posted the code relevant to the issue. The same thing applies here :)
You should either link the tutorial w/ timestamp, or post the code here.
[I'm not promising that means we'll have a solution, but it's a start. I personally don't have VS 2019 so I can't directly reproduce the steps.]

It might be that the default warning levels for VS 2019 are more zealous than VS 2017. You might be able to use some #pragma warning disabling around the particular part of the code causing the issue, if it's part of a header file causing the issue.

In other words, if you're sure the warning is benign... you can do something like:
e.g. https://stackoverflow.com/a/18461418/8690169
1
2
3
4
#pragma warning ( push )
#pragma warning ( disable: ThatWarning )
// one single line with ThatWarning
#pragma warning ( pop ) 

https://stackoverflow.com/questions/4193476/is-using-pragma-warning-push-pop-the-right-way-to-temporarily-alter-warning-lev

1. Also, is it an error or a warning?
2. Is the build still succeeding?
3. If you go into Project --> [Project Name] Properties --> C/C++ --> General --> Warning Level, what is it?
4. What is your setting for "Treat Warnings As Errors", located below Warning Level?

If this is an issue that will affect other VS 2019 users, it might be worth telling wxWidgets devs. There are other places in their code base where they manually disable some VS warnings.

The warning appears to original inside https://github.com/wxWidgets/wxWidgets/blob/master/include/wx/any.h


...in other words... one thing you could do is try editing wx/any.h, and add something along the lines of:
1
2
3
4
5
6
7
8
9
10
union wxAnyValueBuffer
{
    // ...

    void*   m_ptr;
#pragma warning ( push )
#pragma warning ( disable: 26495)
    wxByte  m_buffer[WX_ANY_VALUE_BUFFER_SIZE];
#pragma warning ( pop )
};

(just a guess)
Last edited on
https://www.youtube.com/watch?v=EI2taYkErRg

That is the video I followed.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// wxWidgets "Hello World" Program
// For compilers that support precompilation, includes "wx/wx.h".
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
class MyApp : public wxApp
{
public:
	virtual bool OnInit();
};
class MyFrame : public wxFrame
{
public:
	MyFrame();
private:
	void OnHello(wxCommandEvent& event);
	void OnExit(wxCommandEvent& event);
	void OnAbout(wxCommandEvent& event);
};
enum
{
	ID_Hello = 1
};
wxIMPLEMENT_APP(MyApp);
bool MyApp::OnInit()
{
	MyFrame* frame = new MyFrame();
	frame->Show(true);
	return true;
}
MyFrame::MyFrame()
	: wxFrame(NULL, wxID_ANY, "Hello World")
{
	wxMenu* menuFile = new wxMenu;
	menuFile->Append(ID_Hello, "&Hello...\tCtrl-H",
		"Help string shown in status bar for this menu item");
	menuFile->AppendSeparator();
	menuFile->Append(wxID_EXIT);
	wxMenu* menuHelp = new wxMenu;
	menuHelp->Append(wxID_ABOUT);
	wxMenuBar* menuBar = new wxMenuBar;
	menuBar->Append(menuFile, "&File");
	menuBar->Append(menuHelp, "&Help");
	SetMenuBar(menuBar);
	CreateStatusBar();
	SetStatusText("Welcome to wxWidgets!");
	Bind(wxEVT_MENU, &MyFrame::OnHello, this, ID_Hello);
	Bind(wxEVT_MENU, &MyFrame::OnAbout, this, wxID_ABOUT);
	Bind(wxEVT_MENU, &MyFrame::OnExit, this, wxID_EXIT);
}
void MyFrame::OnExit(wxCommandEvent& event)
{
	Close(true);
}
void MyFrame::OnAbout(wxCommandEvent& event)
{
	wxMessageBox("This is a wxWidgets Hello World example",
		"About Hello World", wxOK | wxICON_INFORMATION);
}
void MyFrame::OnHello(wxCommandEvent & event)
{
	wxLogMessage("Hello world from wxWidgets!");
}


That is the code copied from wxwidgets website.

I also get 2 errors...

Error LNK2019 unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)

and...

Error LNK1120 1 unresolved externals

Are you building as a console application?

You should build as Windows

Project settings -> Linker -> System -> Subsystem: Windows

Now I did that but still same errors.
Strange, but when I build solution in debug mode it succeeds. Then when I try in release mode, I get the errors...
That's a good clue. Only other idea I had was to download a sample VS project that already exists for wxWidgets.

Look in your .*proj (.vcxproj) file and compare the ItemDefinitionGroup with "Debug" in it to the ItemDefinitionGroup with "Release" in it. Note any differences especially in the <Link> section.
Last edited on
Check options for linker, system, subsystem - make sure it's Windows

The entry function for a Windows program is usually WinMain, not main as the error indicates
Last edited on
Yes! That was the problem. I had it switched to windows in debug mode but not release mode. Thank you both for you patience and help.
Topic archived. No new replies allowed.