Solved

How Can I use MFC static linked DLL with Win32 Application

Posted on 1999-01-19
1
199 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 30

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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 …
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.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now