Need tutorial to create .dll file

The forum for experienced coders to upload their helpful hints, tips and lessons.
Post Reply
scopier
Posts: 3
Joined: Sun Dec 23, 2012 3:39 pm

Need tutorial to create .dll file

Post by scopier »

hello all, I was a newcomer, is there Master here that could give a tutorial on how to create a .dll file?

Thanks before
User avatar
mjws00
Trader
Posts: 609
Joined: Fri Jan 04, 2013 10:17 pm
Location: Victoria

Re: Need tutorial to create .dll file

Post by mjws00 »

This is a pretty significant topic. Probably a book and not a post or two. Tough to respond to. Start here http://www.forex-tsd.com/Empty4-4-m ... n-dll.html and don't forget google.

Maybe a bump will give those who have better ideas a chance to respond. Good luck.
Reading the dark heart.
roger-write
Trader
Posts: 63
Joined: Sat May 19, 2012 10:34 am

Re: Need tutorial to create .dll file

Post by roger-write »

I've got a few bits/files that should help along with some basic notes for how to use them with visual studios. I'll put it on my list to post tomorrow.

Creating the DLL isn't hard, but there are lots of subtleties with passing arguments, etc. that you'll probably need to do some googling to figure out.
roger-write
Trader
Posts: 63
Joined: Sat May 19, 2012 10:34 am

Re: Need tutorial to create .dll file

Post by roger-write »

Following are the steps I use for creating a DLL for Empty4. This "should" work for VS2005 or VS2008. Not sure about other versions, so if you have another version of VS and these instructions don't work, you may have to do some digging.
  • First off, you will need to edit dllglue.cpp (attached in zip file) and edit the path for the debug functions for your own location. MetaQuotes, in their infinite wisdom, have decided to prevent coders from using the VS debugger to debug your DLLs. So you will have to resort to arcane debugging techniques of the middle ages, using print statements, etc. To facilitate this nonsense, you can use DebugWrite to "print" out statements to a file from inside the DLL.
  • Start up VS
  • Select File/New/Project from menu
  • Select Visual C++ / MFC
  • Select MFC DLL
  • Name your project and where it will go in the dialogue
  • Click OK, and in the wizard click Next
  • Select DLL Type: "Regular DLL with MFC statically linked"
  • Click Finish
  • Right-click and remove the following items from the VS Solution Explorer pane (when prompted, delete permanently):
    • All Headers files (Resource.h, stdafx.h, <project>.h, etc.)
    • All resource files (*.rc, etc.)
    • All source file, EXCEPT <project>.def (leave that one)
    • Delete the ReadMe.txt file if you want as well
  • Copy the DLL bits (attached) into the new project at the same location as where the <project>.def file is (both stdafx.h and dllglue.cpp)
  • In VS Solution Explorer pane, right-click Header files, and Add Existing Item
  • Select the newly copied stdafx.h file
  • Now right-click Source Files and Add Existing Item
  • Select the newly copied dllglue.cpp file
  • In VS Solution Explorer pane, right-click your project name in bold and select properties
  • At the top of the dialogue, select All Configurations
  • Click on Linker and set the Output File to the location and name of where you want it to create the DLL (for example, I usually set this to the Empty4 experts/libraries directory for convenience)
  • Now expand the C/C++ section and select Precompiled Headers
  • Under Create/Use Precompiled Headers, select "Not Using Precompiled Headers" (I always get errors unless I do this and too lazy to figure out why).
  • Click OK to the dialogue
  • You might as well set Release instead of Debug since you can't use the debugger and it will produce a smaller DLL
  • Build the project - if all the steps were done correctly and you are using a similar VS to VS2005, you should get a clean build and you now have an empty DLL shell ready to beginning populating with all your cool Empty4 functions.
  • Add your own .h/.cpp files as needed
  • All .cpp files MUST include the statement: #include "stdafx.h"
TO EXPORT A FUNCTION
  • Define your exported functions as follows:

    MT4EXP <type> __stdcall <name>(<args>, ...)
    {
    }
  • Add the name of your function to the <project>.def file
NOTES:
  • If you run multiple copies of Empty4, each one will have its own version of your DLL
  • If you run multiple EA's/indicators on one Empty4 platform, they WILL SHARE the DLL
  • What this means is, if the DLL contains context of any sort, you will need to have a session identifier that gets passed to the DLL to make sure it is using the correct context
  • As said earlier, there are a bunch of subtleties about how things are passed, etc. but you should be able to google all of this.
Good luck!
DLLBits.zip
You do not have the required permissions to view the files attached to this post.
eigenvector
Trader
Posts: 20
Joined: Sat Jul 14, 2012 3:14 pm

Re: Need tutorial to create .dll file

Post by eigenvector »

If you do C# this sample code may help you: Code to Export C# DLL to Empty4
Post Reply

Return to “Coding Lessons - info for all”