Advertisement

Implimenting a DLL

Started by October 13, 2000 11:21 AM
11 comments, last by jt_845s 24 years, 3 months ago
i want to a dll for certain functions in my game, but I am unsure on how to make one and then impliment and use it''s functions. anyone know of tutorials out there, or maybe some examples... thanx #define ignite_software 1
[source]#define ignite_software 1[/source]
I tryed to tackle this problem about a week ago, but no one here seemed to have the solution I wanted.

I did learn alot about other kinds of dlls at flipcode.com. Maybe those are the types of dlls you want.

I was just trying to find a way to use the original header file without the export functions. I still wanted to use an import lib like OpenGLs import lib works, then all you have to have is the dll in the game directory when the game runs.
Advertisement
There is two types of DLL files.:

1: Run-Time libraries, you load the DLL files and their functions in your program as you need them. This is also called dynamic DLLs.

2: Load-Time libraries, you link your game code with an export library which tells the program to load the DLL into memory when the program is started. This is also called static DLLs.

Most likely you want to use Load-Time libraries as it is alot simpler to use. I will explain how you can do it. Be aware, this might be long. ...

First you have to create the DLL file and an export library for it. Take a look at this code:

//////////// MyDLL.cpp//////////#include "mydll.h"#include "stdio.h" // for printf()int MyDLLFunction( void ){    printf("Called from MyDLL.dll");    return 0;}//////////// MyDLL.h//////////// MYDLL_EXPORTS will automatically be defined if the name of the// project is MYDLL and you are using VC++ 6. This way we can// use the original header without the exports.#ifdef MYDLL_EXPORTS #define EXPORTDLL __declspec(dllexport)#else#define EXPORTDLL#endifEXPORTDLL MyDLLFunction(); 


__declspec(dllexport) tells the compiler which functions to include in the export library.

Alright, now we got the DLL and the export library (the export library should be builded automatically if VC++ 6 is used). Now we have to use the library. Copy the .DLL and the .LIB files to the folder of the game which are using the DLL. Now, link with the .LIB file, include MyDLL.h and call MyDLLFunction. That''s it! you should see the string "Called from MyDLL.dll" on your screen (only in console apps).

Phew, that was alot. Hope you understood some of it . If there is something you dont understand, feel free to ask.

Also, you can find alot about this on www.msdn.microsoft.com.

-René


I''ve been everywhere on this topic, and none of them make the kind of dll I want.

In OpenGLs header file, there is no EXPORT info at all, yet it still works when I include gl.h, and opengl32.lib. I get no linker errors and no missing function names. This is the kind of lib and dll files that I want. I don''t want to use the unrecognizable EXPORT code in my headers, especially when i want other people to use them who don''t want to go through all this dll learning buisness.

I have one question on one of your lines of code. Where''s the "int" after "EXPORTDLL" in "EXPORTDLL MyDLLFunction();"? Shouldn''t the int be in there?

I sure know more about dlls now, that''s for sure .
quote:

// MYDLL_EXPORTS will automatically be defined if the name of the// project is MYDLL and you are using VC++ 6. This way we can// use the original header without the exports.



oh ...I''ll try that then.
Thanks for trying, but that isn''t what I wanted.
Advertisement
Just to clarify alittle:

MadZorg wrote:
quote:
There is two types of DLL files.:

1: Run-Time libraries, you load the DLL files and their functions in your program as you need them. This is also called dynamic DLLs.

2: Load-Time libraries, you link your game code with an export library which tells the program to load the DLL into memory when the program is started. This is also called static DLLs.


Actually there is no difference between the two "types of files". The difference lies in how you use them, you can either link to an export library or load functions manually using LoadLibrary and GetProcAddress. Both methods can however be used on the same DLL files, there is no difference in the files.
I know .

The run-time method you need to make function pointers and then import the function data from the dll.
There was an article series on this site about using DLL''s just a little while back...
Hey WhatEver:

When you say that OpenGL doesn''t include the EXPORT functions in it''s headers,do you mean the export macro? If so then you are mistaken.If you look at the gl.h file you will see this macro: "WINGDIAPI" infront of all the OpenGL functions and it IS the export macro and it''s defined in the wingdi.h.

I work with DLL''s ALOT and I have never seen a header to a dll file that does not have an export macro infront of it''s function prototypes before.I could be wrong here but from what I know you simply MUST have them to tell your compiler where the functions are coming from.

Just though I might add that.

This topic is closed to new replies.

Advertisement