Solved

How Can I use MFC static linked DLL with Win32 Application

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Decoding 32 bit binary streams 6 37
How to create frequencies of a variable from SAS dataset? 10 121
Separate files macro - Errors on larger data set 18 65
wordappend challenge 8 145
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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 is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

911 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

16 Experts available now in Live!

Get 1:1 Help Now