1
votes

what I want to achieve:

I have a big existing project which is non mfc.

I created a static library in which cdialogs are defined.

I already read, that it's possible to use this lib in a non mfc application but I don't know how.

I read a lot about mfc entrypoint and initialization, which happens in afxwinmain(), InitInstance, run(), etc. So, apparently, this stuff is never done in my application.

Can anyone suggest a method to use the cdialogs from my lib in the main application?

1
Try putting all the necessary initializations in an exported wrapper procedure inside your MFC lib, call it void InitMFC() for example, which you then call from your non-MFC main project. If that's possible (doing the init from inside the static library), then your main project can initialize MFC without really knowing anything about it.sashoalm
So, you mean, I should export my own function, initializing the stuff, usually done in afxwinmain(). Is this just an assumption or do you know, it works this way?sir_neromani
Just an assumption. But it shouldn't be too hard to test it, you can create a sample static library that initalizes MFC, creates a CDialog, and calls its DoModal(), all in an exported function, and a sample non-MFC Win32 project that links against it and calls that function. How do you link MFC against your static lib? Is it linked as DLL, or staticly?sashoalm

1 Answers

1
votes

Your assumption worked so far, thanks to @satuon.

I actually copied the mfc code inside afxwinmain() function into a function in my static lib (in my case, an cwinapp method).

In my main-application I declared the cwinapp object as external. Then, I just call the theApp.InitMFC() and it works.

Example:

extern MyCWinApp theApp;
theApp.InitMFC();

In my case, theApp is global.