Cefsharp CLR initialization crash in MFC project - mfc

I created a CLR class as DLL and loaded cefsharp,cefsharp winforms,cef core through Nuget package in vs 2015.When I run it in a sample MDI CFormView application it works.But when I try to run it in my main MDI application which loads COM DLL it crashes without any errors.The code never executes and crashes even before initialisation.I am using it like below
using namespace cefsharp;
using namespace cefsharp::winforms:
Cef:: Initialize (gcnew CefSettings());
The debugger never comes to this place and application crashes.I am really unable to debug since it doesn't even hit initinstance if I write that line but if I don't write that line the app runs.

The problem somehow resolved when I created a CLR inside my project and added the needed dependencies for it.Now I am able to load my MDI applications with different views and also Initialize the COM dll without encountering any crash.

Related

OpenGL GLFW GLAD shared between projects Visual C++

Under Visual C++ 2017, I have a on a side a project DLL, with the core GLFW 3.2.1 routines (like glfwInit(), glfwWindowShouldClose(), glfwTerminate()...). Theses methods are encapsulated in a static class named RenderLoop. It uses GLAD and GLM too.
On the other side I have an EXE project application which calls the RenderLoop methods, in the same solution.
Everything works fine, I launch the exe, the window is created, the loop is running etc...
Yet I try to call within my EXE some gl function (like glGenVertexArrays), after Initialization. I can't get rid of Access Violation Exception.
If I put this gl function in the DLL, everything works fine. If I put it in the EXE, it crashes. Is there a "trick" to share OpenGL between the DLL and EXE ?
As suggested Robinson, I added a call to gladLoadGLLoader in the dll after Initialization

AFX_MANAGE_STATE(AfxGetStaticModuleState()) in DLL causes EXE to not exit?

I have a project that consists of a DLL and a windows console application .exe.
The .exe calls the DLL. In the DLL I am creating a Dialog box.
AFX_MANAGE_STATE(AfxGetStaticModuleState());
MyDlg* dlg = new MyDlg;
dlg->Create(IDD_DIALOG1);
I had to add AFX_MANAGE_STATE(AfxGetStaticModuleState()) so it knew to look in the DLL for the resources. However this seems to be causing a problem when control is returned to the EXE.
When I "return 0" in the main() function of the EXE the console window does not go away. I have to physically close it in order for the EXE to stop running. If I remove AFX_MANAGE_STATE(AfxGetStaticModuleState()) from the DLL (along with all references to MyDlg since they won't work without it) everything works fine when control is passed back to the EXE.
Why would this be happening?
Fixed. My DLL is using DAO. I had to add AfxDaoTerm(); before exiting. Thank you

MFC DLL calls AfxWinInit and crashes application

I have an MFC .exe application, and I created another project for a DLL with MFC dynamically linked to it.
Now, when I import that DLL through LoadLibrary, it crashes my application, because when the importing is done, the DLL calls AfxWinInit().
Should the DLL call AfxWinInit()? How do I avoid it? Or is something else wrong?
In your MFC application WinMain() calls AfxWinMain(). The AfxWinInit() is called at the beginning of AfxWinMain(). So the initialization is done by framework for you. There is no need to initialize it again.
MFC DLLs provide their own entry point, so you're not supposed to write one yourself. If you plan to write a DLL with MFC support, I'd suggest you start with a fresh MFC DLL created by the app wizard and then move your code there.
For MFC applications that load extension DLLs, use AfxLoadLibrary instead of LoadLibrary.

GUI harness for MFC DLL?

I have a CWinApp-based application that is built as a DLL that is loaded by another 3rd party application as a plugin. My app exposes an exported StartPlugin() method that creates a CDialog derived dialog. This exported function is somehow called by the 3rd party application. I'd like to be able to run my DLL outside of the 3rd party application so I can test and play around with UI stuff (not for unit testing).
How can I create a test harness that will allow me to run my dll code? I'm not sure how the main application launches my dll plugin, but I'm speculating that it's creating a User-Interface thread? So would I just need to create a simple exe that can somehow load my dll and create a new thread or something. Any links to tutorials or articles that explain something like this.
Use the Visual Studio wizard to create a MFC application, probably Dialog based. Have a button on the dialog to run your plugin. In the button code do a LoadLibrary with the name of your DLL, then call GetProcAddress to get a pointer to the StartPlugin function. Then you can call StartPlugin.

How to disable WinMain entry point for a MFC application?

I understand that is not possible to have applications with multiple entry points under Windows.
I have a MFC application and I added code for making it running as a service (main() entry point and other required stuff) but it looks that Windows will always run the WinMain() from MFC instead of my main.
The question is how can I disable the WinMain() from MFC in order to be able to run my own main().
Probably the same problem would apply if you want to run the same application as a console application.
What do I have to change in project properties in order to build it as a console application (main instead of WinMain)?
Is commenting my CWinApp the only solution?
If you look at the linker settings you can change the entry point. This is where you want to be looking.