Hello world with vc++ 2019 & mfc? Trying to make a project running + share experience

firstly: big thank you for this outstanding 3d engine!
background: we would like to add 3d features to a legacy mfc/c++ (mdi) industrial application. This application has a rich mfc gui => it would be too expensive to redevelop everyting with panda 2D & 3D…
The application has basic 3d opengl rendering features, but opengl apis are circonvoluted compared to panda3d apis (!!!).
=> panda3d looks like a great solution!

So we are currently working on a POC (Proof Of Concept) to ensure mfc/c++ + panda3d works well as claimed in the docs… but we are facing several issues

POC goal : create a MFC mdi application with hello world walking Ralf in each mdi window, release & debug mode (seems possible)

Environment: Visual Studio/VC++ 14.2 & mfc 2019 - windows sdk 10 - python 3.8.6 - panda3d 1.10.7 - windows 10 - 64 bits

  1. Succesfully tested: rebuild “hello world” in release & debug mode (it rocks! breakpoints can be set)
    This build uses Panda3d on-the-shelves SDK

  2. wizard created MDI MFC application + pandatest.cpp with subsequent modifications:
    int main(int argc, char* argv[]) replaced by: int test_main()
    test_main() is now “hello world” core in a c function. It’s called in a dedicated thread when a mdi child view is created to keep the main loop in background:

UINT MyThreadProc(LPVOID pParam)
// do something with ‘pObject’
//run_panda3d((unsigned long)pParam);
return 0; // thread completed successfully

afx_msg int CMFCPanda3dView::OnCreate(LPCREATESTRUCT lpCreateStruct)
// TODO: Modify the Window class or styles here by modifying
afx_msg int res = CView::OnCreate(lpCreateStruct);

AfxBeginThread(MyThreadProc, NULL);
return res;


release build and run: works like a charm!

debug: we rebuilt panda3d + python 3.8.6 in debug mode =>

  • change included libraries in solution properties:
    libp3direct.lib => this one is not rebuilt by the makepanda.bat
  • copy corresponding dlls from panda3d debug rebuilt folder to application debug folder

We’re currently stucked with:

  1. Exception thrown: read access violation. this was 0x50.

Call stack:

libpanda_d.dll!PointerToWindowHandle::OSHandle::operator WindowHandle::OSHandle *() Line 138 C++
libpanda_d.dll!EventParameter::is_empty() Line 96 C++
libp3framework_d.dll!WindowFramework::get_camera_group() Line 226 C++
MFCPanda3d.exe!test_main() Line 146 C++
MFCPanda3d.exe!MyThreadProc(void * pParam) Line 75 C++


  • We also have the typecast operator to automatically convert PointerTo’s to
  • the required kind of actual pointer. This introduces ambiguities which the
  • compiler will resolve one way or the other, but we don’t care which way it
  • goes because either will be correct.
    constexpr PointerTo::
    operator T * () const noexcept {
    return (To *)(this->_void_ptr); => Exception

For information (to be diScussed later in details)
2) we tried to move forward in release mode to put the main panda3d window in the mdi view
=> memory error :frowning: Access violation exception

  1. we tried to move forward in release mode. We put the “hello world” main loop core (CIntervalManager::get_global_ptr()->step():wink: in a view timer called method instead of a thread.
    => memory error :frowning: Access violation exception

Do you faced similar issues???

update: we have to rebuild panda3d as follow:
makepanda\makepanda.bat --everything --threads=4 --optimize=1 --windows-sdk=10 --msvc-version=14.2
Fix link workaround, but:
Unhandled exception at 0x00007FFA09DC3E49 in MFCPanda3d.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0000008F52BFF4F0.
code: framework.set_window_title(“My Panda3D Window”);
Seems described here: Bad memory allocation (C++)
After in depth investigations: we went rid off debug stuff and debug in release mode as describeed here:
Next steps: use MFC!!!

Hum… MFC/Panda3d include conflicts!
I want to share a global PandaFramework global variable between sources:
PandaFramework gFramework;;

Here are the application app main class includes:
//#include “pch.h” -> panda3d does not manage precompiled headers
#include “pandaFramework.h”
#include “framework.h”
#include “afxwinappex.h”
#include “afxdialogex.h”
#include “MFCPanda3d.h”
#include “MainFrm.h”

#include “ChildFrm.h”
#include “MFCPanda3dDoc.h”
#include “MFCPanda3dView.h”

Compilation raised a nice:
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.27.29110\atlmfc\include\afxv_w32.h(16,1): fatal error C1189: #error: WINDOWS.H already included. MFC apps must not #include <Windows.h>
… as Panda3d manages Windows windows here
Any idea how it could be cleverly fixed?

I thought about sharing a LPVOID on the global variable gFramework between sources, and cast it to PandaFramework* in panda3d specific sources… Any recommandations? Ex: create interface classes between panda3d specific’s and MFC app core code?

after hours of investigation:
WindowFramework* window = gFramework.open_window();
WindowProperties props = window->get_graphics_window()->get_properties();

where wndparent is the mdi child window content… still failing! It seems unpossible to achieve this stuff! Any suggest is welcomed!

some progress: Ralf walks in x1 mfc mdis over 3!

x2 Pandas in 2x mdi with displayed options selected by MFC! (more mdi can be created)