Sign in to follow this  
Muzlack

Seperating Engine logic from game

Recommended Posts

Hi, I've been working on a new project for a little bit now, and I want to do something that I never learned how to do with previous projects. I'd like to seperate my engine from the actual game that I'm developing. I have all this code that could be shared. So what I've done so far is take all the engine related files and headers and whatnot and put them into another project, and set the output type to be a dll. I have managed to get a .dll file, and also a .lib file (I've tried both). Now, I'm not quite sure how to USE a dll file in c. I do know how to attatch a .lib file in the project dependencies, so going down that road, I copied all of the header files from the engine, and added the engine.lib file that I created to the dependencies, and it builds... all the way to the linker where I get one simple error. Game error LNK2019: unresolved external symbol _WinMain@16 referenced in function _WinMainCRTStartup I found a "fix" online where you put wWinMainCRTStartup as the entry point, and that does no good, because I get Game error LNK2019: unresolved external symbol _wWinMain@16 referenced in function _wWinMainCRTStartup I probably sound like an idiot for not knowing this, but the linker features of Visual Studio always eluded me, and I've never really understood them. I do this sort of stuff with managed projects all the time (C#, vb.net), where I'll design controls and other utilities that won't change, and implement them on other projects. For the record, I'm using Visual Studio .NET 2003. I'd appreciate any help I can get. Thanks! Bryce [Edited by - Muzlack on February 13, 2005 6:45:19 PM]

Share this post


Link to post
Share on other sites
If you are using Visual Studio you can use the following to include a library:
#pragma comment(lib, "libname.lib")
You will need to put the DLL file in the same directory as well as all the header files you will need. Don't forget to use the __declspec(dllimport) keyword in the files that use stuff from a homemade DLL ;-)

Share this post


Link to post
Share on other sites
Wait... I think I understand.

I need all three. I need all my header files from the classes, the dll, and a lib file.

Am I better off rewriting some of the parts of the engine so that I don't have to share variables between the DLL and the application? Is that essentially where my linker problems are coming from?

Share this post


Link to post
Share on other sites
Looks to me like one of three things:

1. You're trying to build a Windows application but accidently specified Windows Console.
2. You're trying to build a Console application but accidently specified Windows application.
3. Your library has an int main() function in it.

I'm not sure which.

Share this post


Link to post
Share on other sites
I'm doing something similar, and what you are trying to do should work. This is what I did:

Using Visual Studio .NET, I created two projects and added both to the same solution. The first project is the shared code, and it is being compiled as a .lib file. The second project is my game. I added the name of the first project's .lib file to my list of libraries to link to. I then added the first project's output directory as an additional library directory of the game project. This way, when I make a change to the .lib file, it is automatically built into the game exe. Finally, I added the source code directory of the first project to the game's additional include directories, so that it can automatically find any of the .h files that are needed for from the library.

Its not an ideal solution, but it works pretty well. I can't say what exactly your problem is without seeing your project, but most likely you are missing your main function, or you are trying to put it in the library. You must have the main function in your main project. If you want your entrypoint to be defined in your library, make a simple main function in your main project that calls your entrypoint function defined in the library.

Share this post


Link to post
Share on other sites
That's exactly what i'm trying to do/have done.

It is a windows application, and is being built as such. And the main isn't in the dll. I'm not sure why i'm getting this linker error.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Muzlack
That's exactly what i'm trying to do/have done.

It is a windows application, and is being built as such. And the main isn't in the dll. I'm not sure why i'm getting this linker error.


You are trying to build Win32 _CONSOLE_ application instead of Win32 Application... Just create new project with your current source files in it and remember to choose "Win32 Application", instead of "Win32 Console Application"...

Share this post


Link to post
Share on other sites
No, I understand that. As I've said, it is being built as a win32 application, NOT a console application.

All of my code worked before putting the engine code in the DLL file, which does not include a main function.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Unless you have completed at least one full game (preferably two), I strongly recommend finishing your game first and then refactoring out an "engine" component. Otherwise, the odds are very strong you will spin your wheels working on the just the engine and eventually abandon the project. At least this is my observation after programming games for 15 years...

Share this post


Link to post
Share on other sites
.. I have. And I work as a software development engineer for an IT company, and have been programming for around 10 years. Although I'll admit I've mostly used VB and .NET languages, I'm really trying to learn (more in depth) the lower level languages.

I've completed several game projects, including an RPG engine that has a scripting language, battles, etc, and significant work on an adventure game engine (similiar to Sierra style adventures).

I've spent most of my time the past 1 1/2 years in managed languages. My coding & commenting style in general has vastly improved having a job in the real field, and I'm trying to come back and take what I've learned and apply the concepts to develop what I'd now call a "clean" engine.

I'm pretty sure I know what I'm getting into. :)

Thanks, any ideas on the errors?

Share this post


Link to post
Share on other sites
Hmm, I managed to get this working. My entry point was APIENTRY _tWinMain(). What exactly is the difference between _tWinMain, wWinMain, and WinMain? I think the _tWinMain was set by Visual Studio when I created the project, because I would normally use just WinMain.

.. But I got it to work! So now I'm off to continue work on the game.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The 't' in tWinMain is probably referring to TCHAR, which is basically a character string which can be used to describe ANSI, DBCS and Unicode strings. On ANSI/DBCS platforms, TCHAR just represents a standard char, while for unicode platforms, it instead represents a WCHAR. The 'w' in wWinMain is probably just for WCHAR, which would be for programs designed for Unicode only platforms. WinMain is just the stock standard user-defined entry point, and, for reference, WinMainCRTStartup is the compiler generated entry point.

Share this post


Link to post
Share on other sites
You might find some useful information in the article Striving for Graphics API Independence. Ignore the title, the article is about using interfaces with DLLs and teaches you how to create an interface (eg IGame orIEngine, whichever way you do it) and load a DLL with this interface at runtime.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this