Thread: How to create a DLL wrapper.

  1. #1
    Registered User
    Join Date
    Nov 2006
    Location
    82.192.160.50
    Posts
    17

    How to create a DLL wrapper.

    Hey,

    I'm new to this forum, and new to programming in c. I'm currently using Borland Commandline Compiler 5.5, i don't know if it's any good, but it's been able to do what i needed.

    Now, to my actual question, i'm using Game Maker, and i need to make a wrapper for a dll of mine, since Game Maker is designed to only use "double" for real values and "PCHAR (char* or LPSTR)" for string values, the dll i have doesn't work, since it's using longs, so i'm trying to make a dll wrapper for the functions in the dll, my wrapper should convert from long to double, and allow Game Maker to read the dll correctly.

    I would like your help on how to do this, maybe provide me some tutorials on dll creating in c/c++, or if possible, an example, i do know the basics of c and some c++ from the tutorials on this site.

    - MindWorX

    Btw, if this is the wrong forum, feel free to move the topic.

    EDIT:
    I forgot to mention, i would like to avoid using alot of dev tools, i'd rather stick to notepad/scite, since it's more simple to work with.

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Quote Originally Posted by MindWorX
    i need to make a wrapper for a dll of mine, since Game Maker is designed to only use "double" for real values and "PCHAR (char* or LPSTR)" for string values, the dll i have doesn't work, since it's using longs, so i'm trying to make a dll wrapper for the functions in the dll, my wrapper should convert from long to double, and allow Game Maker to read the dll correctly.
    I don't think a "DLL Wrapper" is the answer, though you can make a library if you want. A much cleaner solution I think is to recognize that
    - C is a typed language
    - you need to write something that Game Maker can use, or not use C to do this.
    Anything else, like changing longs to doubles and whatever else is probably a hack because you aren't using the correct type in the first place.
    Quote Originally Posted by MindWorX
    I would like your help on how to do this, maybe provide me some tutorials on dll creating in c/c++, or if possible, an example, i do know the basics of c and some c++ from the tutorials on this site.
    You can search the Internet for information on dynamically linked libraries and find some good stuff. But, like I said before I don't think the library is needed for what you're doing (at least the way you described what you're doing). Also, knowing the stuff on C Prog is not a good programming litmus test. Do you have a book?

  3. #3
    Registered User
    Join Date
    Nov 2006
    Location
    82.192.160.50
    Posts
    17
    Quote Originally Posted by citizen
    I don't think a "DLL Wrapper" is the answer, though you can make a library if you want. A much cleaner solution I think is to recognize that
    - C is a typed language
    - you need to write something that Game Maker can use, or not use C to do this.
    Anything else, like changing longs to doubles and whatever else is probably a hack because you aren't using the correct type in the first place.
    A DLL Wrapper should be the solution, i got a friend to make one using Assembly, and it worked just as i needed, so i'm pretty sure this is what i need. The reason i wanna make my own, is because i wanna learn how to do it myself.

    Quote Originally Posted by citizen
    You can search the Internet for information on dynamically linked libraries and find some good stuff. But, like I said before I don't think the library is needed for what you're doing (at least the way you described what you're doing). Also, knowing the stuff on C Prog is not a good programming litmus test. Do you have a book?
    A book? I've found some guides on explicit linking and implicit linking and stuff, problem is, most tutorials insist on using Microsoft Visual C++, and that's pricey, i need to make something that i can make for free.

    Please remember i'm very new to this, so if i say something stupid, please forgive me.

  4. #4
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    I really don't care what your friend did. You misinterpreted my point. If you start having trouble with typing your variables, most likely, you need to write whatever you are doing again, using the right typing. No amount of hacking is going to change the fact that Game Maker uses doubles for real values (as they should if you have any idea what a real value is), and making the machine think you're using doubles is even worse.

  5. #5
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    If you really want help, you should not say that that advice is wrong when it is given.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  6. #6
    Registered User
    Join Date
    Nov 2006
    Location
    82.192.160.50
    Posts
    17
    Quote Originally Posted by citizen
    I really don't care what your friend did. You misinterpreted my point. If you start having trouble with typing your variables, most likely, you need to write whatever you are doing again, using the right typing. No amount of hacking is going to change the fact that Game Maker uses doubles for real values (as they should if you have any idea what a real value is), and making the machine think you're using doubles is even worse.
    Eh, i think i might not be clear, what i'm trying to do is make a dll that wraps another dlls calls, so that Game Maker can use them.

    Like this:
    I have a dll "K8055.dll" It uses longs both as returns and arguments.
    - Example Function: "long SearchDevices(void)"
    This is the dll my friend made: "GM_K8055.dll"
    - Example Function: "double GMSearchDevices(void)" which basicly just calls the "SearchDevices" from the "K8055.dll". And converts the types from long to double.

    Am i being more clear now then...?

    Btw. I didn't write the dll i'm trying to wrap, so i can't rewrite that one.

  7. #7
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    You might try these links which in turn have some links to creating a DLL:
    http://cboard.cprogramming.com/showt...ght=dll+create
    http://cboard.cprogramming.com/showt...light=dll+make

    To return a double, in GMSearchDevices you would have the line:
    Code:
    return (double) SearchDevices();
    Depending on what compiler you are using, there will be a project option to build a DLL (versus console application or windows application).

  8. #8
    Registered User
    Join Date
    Nov 2006
    Location
    82.192.160.50
    Posts
    17
    Quote Originally Posted by swoopy
    You might try these links which in turn have some links to creating a DLL:
    http://cboard.cprogramming.com/showt...ght=dll+create
    http://cboard.cprogramming.com/showt...light=dll+make

    To return a double, in GMSearchDevices you would have the line:
    Code:
    return (double) SearchDevices();
    Depending on what compiler you are using, there will be a project option to build a DLL (versus console application or windows application).
    Ah, thanks... I didn't even know about the "return (double)" part, i just returned the value without the double conversion. I have found out how to compile it as a dll, so that's not a problem. Hmm, i tried this:
    Code:
    #include <windows.h>
    
    #ifdef __cplusplus
    extern "C" {
    #endif
    
    __declspec( dllexport ) double Test(double i)
    {
       return i*i;
    }
    
    #ifdef __cplusplus
    }
    #endif
    What's wrong with that?

  9. #9
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >What's wrong with that?
    It looks fine to me. What error did you get?

  10. #10
    Registered User
    Join Date
    Nov 2006
    Location
    82.192.160.50
    Posts
    17
    Quote Originally Posted by swoopy
    >What's wrong with that?
    It looks fine to me. What error did you get?
    An error that "Game Maker" can't load it... Do i need anything else, the only working dll i've ever made had a .def file with it...

  11. #11
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >__declspec( dllexport ) double Test(double i)
    Actually I think you need to put double first:
    Code:
    double __declspec( dllexport ) Test(double i)

  12. #12
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Quote Originally Posted by MindWorX
    An error that "Game Maker" can't load it... Do i need anything else, the only working dll i've ever made had a .def file with it...
    No clue ... maybe the DLL has to have something special for Game Maker to use it.

  13. #13
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    In your examples, you weren't passing a double, it was just void. Probably doesn't matter, but just a thought.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DLL Wrapper
    By vampirekiss in forum C Programming
    Replies: 4
    Last Post: 01-08-2008, 10:24 AM
  2. Create a DLL
    By cosmo1996 in forum C Programming
    Replies: 0
    Last Post: 08-27-2007, 09:29 AM
  3. dll communicating between each other
    By cloudy in forum C++ Programming
    Replies: 5
    Last Post: 06-17-2005, 02:20 AM
  4. Making a LIB file from a DEF file for a DLL
    By JMPACS in forum C++ Programming
    Replies: 0
    Last Post: 08-02-2003, 08:19 PM
  5. create C dll for other programming languages
    By corn in forum Windows Programming
    Replies: 6
    Last Post: 06-19-2003, 01:11 AM