• C

Calling functions from another module

 Hi there. I'm writing a sort of a strategy game in which every player writes his own client and they all compete in battles hosted by a server. My problem is that I want the clients to be written in c or pascal and the contestants will submit their source codes. So, I'll have to compile the .c and .pas files on my server. I heard that's possible to compile them into .obj files and then call some functions from the server. How do i use the linker to do that ? I'm using djcpp.

                               Thanks, Onu
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You need dynamic library. Rather than DJGPP, I suggest you to use Visual C++ or Borland C++ or Delphi that support DLL/ ActiveX.

onu0roAuthor Commented:
 I also thought of this. But I can't tell the people to write dll's for clients. Nobody does that. I need to find a way to call the function from the .obj. I'm rather new to this, so I don't  even know if it's possible or not. Anyway, it's the .obj way that it's got to be.
It is possible if you have them write it in C.  Just as you can have your code in separate modules, compiled into objs and then linked together, so can other people - especially if they are going to give you source code.  

However, a DLL makes things much easier for you, as it defines the exact method of interface between you and the other modules.  

You will need to define function prototypes in a header file for people to include in their project.  They should be told to NOT change the header file.  Expect to do ALOT of debugging...
Kent OlsenData Warehouse Architect / DBACommented:
Do you envision all of the code running on your server with just status and control information being exchanged with the client or will the client software play an active part in the game?

In general, these steps should get you close.

Write a client program that fits into your game.  For now, it doesn't have to do much.  Compile it and all of the related modules.

Now take all of the compiled modules EXCEPT the client module that is "your player" and put them into a library.

Write a second client program.  Compile it, and link it with the standard (C/C++) libraries and your new library.

If this process works and you're able to successfully build a second client program you will have succeeded in building a library that will be the "core" for all of your player's clients.

Good Luck,

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Of course, if they are sending you source code, and you've predefined the function prototypes, nothing is preventing you from compiling them into a DLL - they don't have to do anything special except use your function prototypes.  A DLL and a static lib are not that different...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.