SDL and MFC

The following code does not put SDL within the main MFC frame. Instead,
it puts the SDL surface in its own window. What must I do to make it
work as intended?

char windowid[100];
strcpy(windowid, “SDL_WINDOWID=”);
_ltoa((long)AfxGetMainWnd( ), windowid+13, 10);
_putenv(windowid);

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???

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.cretegny@cpnv.ch (Jeremie)
To:
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???


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

Carlos Alvarez <citrouille 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 cpnv.ch>
To: <sdl 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???


SDL mailing list
SDL 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…)

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;

}

Carlos Alvarez <citrouille 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 cpnv.ch>
To: <sdl 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???


SDL mailing list
SDL 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

Carlos Alvarez <citrouille 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 cpnv.ch>
To: <sdl 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 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