[SDL] Re: SDL and MFC

contact access-dev contact at access-dev.com
Wed Jun 7 10:45:31 PDT 2006


   Carlos Alvarez <citrouille <at> wanadoo.fr> writes:

> 
> Yes you can use SDL within MFC project.
> 
> Did you set the projet as a Multithreaded DLL project (Multithreaded Debug
> DLL for debug configuration) ?
> 
> cya
> Carlos
> 
> ----- Original Message -----
> From: "Jeremie" <jeremie.cretegny <at> cpnv.ch>
> To: <sdl <at> libsdl.org>
> Sent: Monday, January 10, 2005 10:39 AM
> Subject: [SDL] SDL and MFC
> 
> > Hello,
> > I try to use SDL with MS-Visual C++ and MFC.
> >
> > When I compile the project, I have an unresolved external symbol for the
> main
> > function.
> >
> > The problem is that SDL will a main function and the main function is a
> "hidden
> > function" from MFC...
> >
> > How Can I use MFC AND SDL in the same project???????
> >
> >
Hi,

you can add this code to your program, it works but unfortunalety your program would quit when you close the MFC main windows


int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
					  LPTSTR lpCmdLine, int nCmdShow) {

    int nReturnCode = -1;
    CWinThread* pThread = AfxGetThread();
    CWinApp* pApp = AfxGetApp();

    if (!AfxWinInit(hInstance, hPrevInstance, lpCmdLine, nCmdShow))
        goto InitFailure;

    if (pApp != NULL && !pApp->InitApplication())
        goto InitFailure;

    if (!pThread->InitInstance())
    {
        if (pThread->m_pMainWnd != NULL)
        {
            TRACE0("Warning: Destroying non-NULL m_pMainWnd\n");
            pThread->m_pMainWnd->DestroyWindow();
        }
        nReturnCode = pThread->ExitInstance();
        goto InitFailure;
    }
    nReturnCode = pThread->Run();

InitFailure:

    AfxWinTerm();
	SDL_Quit();
    return nReturnCode;


}

> >

> > _______________________________________________
> > SDL mailing list
> > SDL <at> libsdl.org
> > http://www.libsdl.org/mailman/listinfo/sdl
> >
> 

Yes the project is Multithreadad DLL and the MFC is in shared DLL too.

Since we include SDL library, when we build the project we have this error
during the linking operation:

sdlmain.lib(SDL_win32_main.obj) : error LNK2001: unresolved external symbol
_SDL_main

It's normal because we don't have main or WinMain function, it's the MFC who run
the classes.

If we put a main or a WinMain function, we don't have error but it's this main
function that starts the program!

So the question is:
Can we say to SDL that our main function IS the MFC main function?
or
What must we put in the main function for the program boot normally (i think
something like the code of the MFC main function but i'm not sure and i'm not a
pro in MFC...)



Access-Dev.Com
http://www.access-dev.com
Montpellier - France
Tél       : +33 (0) 4 67 58 37 90
Fax      : +33 (0) 4 67 58 37 90
Mobile  : +33 (0) 6 08 16 61 11
SIRET :  482 737 889 00014 


More information about the SDL mailing list