collapse collapse

* Who's Online

  • Dot Guests: 143
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

* Board Stats

  • stats Total Members: 88
  • stats Total Posts: 11164
  • stats Total Topics: 1700
  • stats Total Categories: 4
  • stats Total Boards: 76
  • stats Most Online: 1470

Author Topic: a game that works using a dll  (Read 2297 times)

0 Members and 1 Guest are viewing this topic.

Offline edgarsb

  • Jr. Member
  • **
  • Posts: 50
  • Reputation 75
    • View Profile
a game that works using a dll
« on: March 01, 2011, 12:33:07 pm »
i want a tutorial how to make a game that works using a *.dll file, for example: there is a exe app and a .dll file, in the exe there is only the code to read from the dll and in the dll is the main information. hope you understand me :)

Offline Celestialkey

  • Administrator
  • Hero Member
  • *
  • Posts: 3962
  • Reputation 4874
  • Gender: Male
  • Its Alive!!
    • View Profile
    • www.CelestialCoding.com
Re: a game that works using a dll
« Reply #1 on: March 01, 2011, 01:40:48 pm »
I'll see what I can do... >_> It is in the queue. Almost done with the platformer one.
Created By: Eczuo
Quote
I have noticed that people who claim that everything is predestined, and we can do nothing to change it, look both ways before they cross the road.
Quote
I'd prefer to die standing, than to live on my knees - Che Guevara
Quote
If you change the way you look at something, does that something change in any way?
- Quantum Theory

Hacking
Quote
Never in the field of human conflict was so much owed by so many to so few. - Winston Churchill


Quote from: Revelations 12:4
And his tail drew the third part of the stars of heaven, and did cast them into the earth; and the dragon stood before the woman which was ready to be delivered, for to devour her child as soon as it was born.

Quote
It takes skill to build an empire. It takes an idiot to maintain it.

Offline jho

  • The flamboyant FLOSS fanatic
  • Sr. Member
  • *
  • Posts: 352
  • Reputation 1199
  • Gender: Male
    • View Profile
    • http://hajotus.net
Re: a game that works using a dll
« Reply #2 on: March 01, 2011, 04:01:24 pm »
Something like this?
(nb: not tested, I don't have a Windows box nearby. Hacked together from some old code of mine)

main.c
Code: C
  1. #include <stdio.h>
  2. #include <windows.h>
  3.  
  4. /* Name of the dll we'll load */
  5. #define DLLNAME "game.dll"
  6.  
  7. /* The name of the function that we call in the dll */
  8. #define DLLENTRY "dllEntry"
  9.  
  10. /* Defining a new "cfunc" type that act as a pointer to the function in the dll */
  11. typedef void (WINAPI *cfunc)(void);
  12.  
  13. int runLib(const char *name)
  14. {
  15.     cfunc dllEntry; /* This will act as our pointer to the function */
  16.  
  17.     /* Opening the dll */
  18.     HINSTANCE handle = LoadLibrary(name);
  19.     if(handle == NULL)
  20.     {  
  21.         fprintf(stderr, "Couldn't open %s.\n", name);
  22.         return 1;
  23.     }  
  24.  
  25.     /* Looking up the function in the dll */
  26.     dllEntry = (cfunc) GetProcAddress( (HMODULE)handle, DLLENTRY );
  27.     if (dllEntry == NULL)
  28.     {  
  29.         fprintf(stderr, "Couldn't run %s.\n", name);
  30.         FreeLibrary( (HMODULE)handle );
  31.  
  32.         return 1;
  33.     }
  34.  
  35.     /* If all went well, run the main function in the library */
  36.     dllEntry();
  37.  
  38.     /* After the dll call terminated, we'll free the library from memory */
  39.     FreeLibrary( (HMODULE)handle );
  40.     return 0;
  41. }
  42.  
  43. int main(void)
  44. {
  45.     int ret;
  46.     printf("Running " DLLNAME "...\n");
  47.     ret = runLib(DLLNAME);
  48.     if(ret)
  49.     {
  50.         fprintf(stderr, "\tSomething went wrong. Returning %d.\n", ret);
  51.     }
  52.     printf("All done.\n");
  53.     return ret;
  54. }

Then you'd build the dll like this:
Code: C
  1. #include <stdio.h>
  2.  
  3. __declspec(dllexport)
  4. void dllEntry(void)
  5. {
  6.     /* Your code goes here */
  7.     printf("Hello, world!\n");
  8. }
  9.  
« Last Edit: March 01, 2011, 04:03:08 pm by jho »
"I'm sorry, I only accept criticism in the form of sed expressions."

Offline edgarsb

  • Jr. Member
  • **
  • Posts: 50
  • Reputation 75
    • View Profile
Re: a game that works using a dll
« Reply #3 on: March 02, 2011, 02:02:42 pm »
Thanks man! I will test it!

 

Donate


* Search


* Recent Posts

I miss the chatbox by Shishka
[August 27, 2019, 11:52:39 pm]


Image Comparison by Shishka
[May 15, 2017, 01:18:02 pm]


Re: srchub - free source code hosting by Nathan
[December 14, 2015, 11:37:02 pm]


Re: srchub - free source code hosting by Celestialkey
[November 27, 2015, 08:51:42 am]


Updates by Nathan
[October 30, 2015, 08:27:36 pm]