Sign in to follow this  
guillermoro

Object File Libraries

Recommended Posts

Im trying to make an engine that is completely seperate from my game that im creating using it. I want the game to link the engine in a lib file. How do i create a .lib file using microsoft visual c++ express edition. Also im having some intellisense problems with my engine, i might be doing something wrong but ive heard other people having this problem also. Any info on either of these topics would be appreciated. Thank you :-)

Share this post


Link to post
Share on other sites
I'm not too sure about using a .lib, but I do know a fair ammount about creating a .dll. The least I know about a .lib is how to make a project. In VC++, you need to make a .lib project. You can do this by creating a project, and selecting it to be a Win32 Static Library. For a .dll, you need to make a Win32 Dynamic Link-Library. In the DLL, you create various functions you wish to use in your project. In order for someone to access them though, you need to mark all exported functions as "C functions." This enables use of the function across multiple languages. If you've ever read the code "extern C { ... }," this is how you would do that. Next, if you're going to be using other languages than just C/C++, you should put every exported function in the '__stdcall' calling convention. Next, for any functions to be exported, you need to put the __declspec(dllexport) macro infront of it. This signals to the compiler to make the function open to calling. I find making a macro for this helps save a little bit of time.

One last tid-bit. If you're making this DLL for non Visual C++ projects, you need to include a .def file. I'm not going to go into much detail about this, as it can get complicated. Some basic information can be found here.

Some code to help you chomp this down:


//My little cheat
#define __dllexport __declspec(dllexport)

extern "C"
{
__stdcall _dllexport void MyFunc(void)
{
//Do stuff...
}
}





EDIT:

Ah! I forgot to tell you how to import functions!

In your game, you need to make a header file for all structures/functions you created in your .dll. In order to import a function, you simple have to change the declspec to dllimport. For example:


#define __dllimport __declspec(dllimport)

__dllimport void MyFunc(void);


One last tid-bit. If you're using Visual C++, you can use __dllimport/__dllexport for functions, variables, and objects. However, if you're going to import/export options, drop the __stdcall & extern "C" part of the code.

If you have anymore questions, feel free to ask!

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