Making DLL for other programs(Basic question)

This is a discussion on Making DLL for other programs(Basic question) within the C Programming forums, part of the General Programming Boards category; Hey! My code has a MAIN() function as in nearly all of C codes have. And also some functions I ...

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    19

    Making DLL for other programs(Basic question)

    Hey!

    My code has a MAIN() function as in nearly all of C codes have. And also some functions I customized on my own. So it seems just like this;


    Code:
    void function(......){
    ...
    }
    
    double function1(......){
    ...
    return ..;
    }
    
    int Main(){
    //All the main codes here
    ...
    //some function calls
    
    ...
    
    }
    Now I want to turn into a DLL file. This program gets a STRING with gets(); function from user, and gives you a DOUBLE value by passing through some algorhytims. So I will enter a STRING in a game editor (named gamemaker; supports DLL) and then It will send this string to my DLL code, and after this DLL code, it returns a double value to game editor.

    So questions are here;
    1- Should I change the type of int MAIN() into DOUBLE or CHAR or something?
    2- Should I remove MAIN() function and replace it with another function, for example function3? ( I mean, there will be no Main() function in my codes, only usual functions that I created)
    3- If MAIN() function is OK, when I try to return a double value in MAIN, it gives me a warning, "possible loss of data; converting double to integer", that is, as main() function is an integer type, it cant return a double, but the time I try changing main() function into a "double main()", it doesn't accept.
    4- Any suggestions

    Thanks in advance, any helps appreciated so much. (Using Visual Studio 2010)

  2. #2
    Registered User ledow's Avatar
    Join Date
    Dec 2011
    Posts
    435
    DLL's don't really have a main. That's only for standalone applications.

    They have a DLL_Main but that has a lot of restrictions on what it can do and often it's nothing but an empty function (which is why most DLL's also provide an "Init" function in them, e.g. SDL_Init, or Allegro_Init or whatever) that you're expected to call before actually using anything else in the DLL.

    In this case, you would just provide an exported function, e.g. "read_in_double" that did what you wanted. That would return whatever you felt it needed to return (in this case, a double).

    Then the calling application would load your DLL (which would execute DLL_Main, which would effectively do nothing because it's a very simple DLL). Then it would call "read_in_double" directly and get a double back.

    But the worrying thing for me is that you're trying to make a gamemaker DLL (which I assume is a particular program). That means that the program gamemaker will be expecting a VERY specific type of DLL, most probably, with a very strict API governing what the functions are in them, what they can return, how they interact with the main program, etc. Just a quick google found: YoYo Games | Extension Maker and Game Maker Manual - Game Maker.info which seem to describe the DLL API.

    DLL's aren't a magic self-contained library of generic code that just works for everything. They are merely portions of a program pushed out to separate files. Sometimes they are interchangeable but more often than not they are very tied into what the calling program expects and does with them (i.e. you can't just replace an SDL 1.2 DLL with a 1.3 DLL, it won't work except in very specific cases). In this case, I expect gamemaker to have a very specific idea of what the DLL should do and what "Init" function it should contain, etc. and that's where your answers really lie.

    There's also a very specific disclaimer at the bottom of one of those pages: "Using external DLLs is an extremely powerful mechanism. But please only use it if you know what you are doing." I would add the proviso that MAKING a DLL for it would require you even more to "know what you're doing" with DLL's already.

    - Compiler warnings are like "Bridge Out Ahead" warnings. DON'T just ignore them.
    - A compiler error is something SO stupid that the compiler genuinely can't carry on with its job. A compiler warning is the compiler saying "Well, that's bloody stupid but if you WANT to ignore me..." and carrying on.
    - The best debugging tool in the world is a bunch of printf()'s for everything important around the bits you think might be wrong.

  3. #3
    Registered User
    Join Date
    Mar 2012
    Posts
    19
    Thanks for your interest. I've read you carefully. Yes Gamemaker has very restricted DLL method. But I prepared a DLL which calculates a+b those variables taken from Gamemaker, and returns to gamemaker after calculating.

    And My codes are very simple as a+b is. It has only for loops, if elses, and some functions. So I think, if Gamemaker support A+B.dll, it should support mine too. Am I wrong?

    So as much as I understand, I will remove Main() function, and replace it with

    Code:
    char read_in_double(args,args...){//This function retreives a STRING
    
    ...
    ..
    Return double a+b;
    }
    And I will call this function from Gamemaker. Is there anything that I am wrong with?

    (Sorry for any misunderstanding or unable-to-understanding, as I'm a basic traniee on it )
    Last edited by ilerleartik; 03-26-2012 at 06:00 AM.

  4. #4
    Registered User ledow's Avatar
    Join Date
    Dec 2011
    Posts
    435
    If you are returning a double, why would you prototype the function as "char read_in_double"?

    But otherwise, yes. Probably. You'll have to experiment with how Gamemaker works, but that's the basic gist of it. A DLL is just a "library" of functions that can be called.

    - Compiler warnings are like "Bridge Out Ahead" warnings. DON'T just ignore them.
    - A compiler error is something SO stupid that the compiler genuinely can't carry on with its job. A compiler warning is the compiler saying "Well, that's bloody stupid but if you WANT to ignore me..." and carrying on.
    - The best debugging tool in the world is a bunch of printf()'s for everything important around the bits you think might be wrong.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 11-18-2003, 02:46 PM
  2. making a basic window...
    By tetra in forum Windows Programming
    Replies: 3
    Last Post: 05-09-2003, 11:14 PM
  3. help with making a basic game
    By Geo-Fry in forum C++ Programming
    Replies: 3
    Last Post: 02-25-2003, 06:35 PM
  4. Replies: 2
    Last Post: 01-13-2003, 12:28 PM
  5. Making super-packed programs?
    By Nutshell in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 09-26-2002, 05:01 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21