Solved

How Can I use MFC static linked DLL with Win32 Application

Posted on 1999-01-19
1
201 Views
Last Modified: 2013-11-20
I maked a win32 program like bellow

STEP 1. I have built MFC DLL in regular dll with  MFC static linked.
STEP 2. I customized Event Loop
        void checkMFCPanding()
        {
             MSG msg;

             if(GetMessage(&msg, (HWND)NULL, 0, 0)){
                  TranslateMessage(&msg);
    DispatchMessage(&msg);
              }
        }

        void EVENT_MainCustomLoop()
        {
S_Running = BOOL_TRUE;
  NDEvent::Update();
  while (S_Running) {
NDEvent::ProcessPending(); /// win32 Event Process
NDEvent::UpdateCursor();
checkMFCPanding();            /// MFC Event Process
Sleep(50);
   }
   NDEvent::Update();
          }


int main(int argc, char** argv)
{
                |
EVENT_MainCustomLoop(); /// Custom Event Loop
exit(0)
}

STEP3.: I use MFC DLL in explicit aproch.
    HINSTANCE hDll;
    void Oi_testWin1::HitPBut_Exit(void)
    {
FreeLibrary(hDll);
S_Running = BOOL_FALSE;
     }

    void Oi_testWin1::HitPBut_Call(void)
    {
typedef void (*MYPROC)();

MYPROC ProcChildShow;
BOOL fRunTimeLinkSuccess=FALSE;

hDll=LoadLibrary("dll4.dll");

ProcChildShow = (MYPROC) GetProcAddress(hDll, "Show_MyDlg");
if(fRunTimeLinkSuccess =(ProcChildShow != NULL)){
(ProcChildShow)();
}
    }

this can display MFC Dialog in DLL, but another ploblum comes.
The application killed when I call FreeLibrary(hDll) routine.

I really don't know what I made a mistake.
I think maybe step of build DLL (build MFC DLL in regular dll with  MFC static linked.).

Anybody know this, please Let me know as soon as possiblly.
please~~~
0
Comment
Question by:jbpark
1 Comment
 
LVL 31

Accepted Solution

by:
Zoppo earned 100 total points
ID: 1327995
I think your problem is your kind of 'syncronisation' with the S_Running:
In Oi_testWin1::HitPBut_Exit you try to unload the lib although the EVENT_MainCustomLoop() is still running.
Even if you set S_Running to FALSE befor freeing the DLL it's not said that EVENT_MainCustomLoop() terminates correctly in time.

You should use some of the Win32 API's syncronisation (see help).

Post if you have additional questions to syncronisation methods.

ZOPPO

0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question