I have tried this, and I find that I am able to successfully invoke a C++ DLL that invokes Framework to load and display a model, exactly as you describe, from Python. Using ctypes works perfectly.
This is running with the same build of Panda that I produced locally: this is the Panda DLL’s that Python loads, and it was also used to produce my DLL at the same time, ensuring that my compilation settings were exactly the same in both cases. I used the ppremake build system, not makepanda.
That said, I find the following difficulties in embedding my DLL in a p3d file:
(1) Our development build of Panda3D is built using OPTIMIZE 3, which is to say, a “Release” build with NDEBUG not defined.
(2) The production build of Panda3D that is used to power the runtime, however, is built using OPTIMIZE 4: a “Release” build with NDEBUG defined. This makes it fundamentally incompatible with (1), since the presence of NDEBUG shortens a few low-level structures (removing some debug-only constructs).
Thus, in order to produce a DLL that is compatible with a p3d file, I will need to build it with an appropriate dtool_config.h that matches (2). But then I won’t be able to run this DLL, unless I also obtain a libpanda.dll etc. that matches (2).
I don’t think this is related to your problems–it doesn’t seem like you got to this point yet. If I’m not misunderstanding, you were having difficulty getting (1) to work–you were unable to produce a DLL that was compatible with the development build of Panda3D and which could be run from Python interactively.
Overcoming this (1)/(2) build dichotomy will be a bother, but it is not insurmountable. It means a developer will need to compile in mode (1) during development, then rebuild in mode (2) for packaging into a p3d file. I don’t think this is unreasonable, especially if we make it easy to switch between the two modes.
There is another problem I ran into:
(3) A DLL embedded into a p3d file is not automatically extracted to disk when running. Thus, the application DLL cannot be invoked when packaged this way. This is clearly just a bug in the Panda3D runtime system. (For the record, it does unpack a DLL from a .mf package, just not from a p3d file.)
I can easily fix (3) for the future.
As to (1), maybe the next thing I need to do is see if I can build a DLL that is compatible with the development libpanda.dll that we distribute.
David