======================================================================== C++ DLL for Visual Studio 2008 and 2010 ======================================================================== Make copies of this text document because you may want to change something but want to keep the original too. ***Creating DLL using .def file : *** 1. File > New > Project> Win32 Project > (enter name of dll and its folder path) > [OK ]> [next] > [DLL] > [Finish] 2. Do this : drag n drop copy of this text document your read right now (I said a copy) on to Visual Studio and read this from there :). 3. - Right click > add > existing item ... > then manually create .def file by right click > new > Text Document then rename it into .def and click [add]. - open the .def file you just create. Right click its tab and select copy full path. - DO THIS FIRST BEFORE CANGING EVERYTHING IN PROPERTY WINDOW - if you do this later it reset property to default: Right click select > properties > then click [configuration Manager ...] button, in "Active Solution Configuration" click and select [release]. In "Active solution Platform" click and select [Win32]. Click [OK] or [Yes] if there's any then click [Close]. - Click "Configuration properies" > "Linker" > "Input" > and click drop down arrow "Module Definition File" > > right click and select paste to write your .def full path name, or > right click and click edit > Macros >> and paste/write your .def full path name > click [OK] - Click "Configuration properies" > General > Use of MFC > from drop down list, select "Use MFX in static library" - If you want the dll to be created in MetaTrader Library : Click "Configuration properies" > "Linker" > "General" > and click drop down arrow's "Output File" > click edit and input the full path of MetaTrader libraries. However this will put the.lib, .exp, and the .pdb files into MetaTrader libraries folder, are you sure you want to do that ? x This is only for Gods : don't do this if you're novice programmer, it will give you warning that you don't understand Click "Configuration properies" > "C/C++" > Precompiled Headers > select "Create/Use Precompiled Header" > click to select "Not Using Precompiled Header". This way you can delete header files folder and resources folder and stdafx.cpp file and dllmain.cpp but you must rewrite the rest. - Click [Apply] > [OK] 4. Do all these below and anytime you change a file of your project do this : save it, rebuild it to see if there is an error 5. don't change dllmain.cpp 6. Open stdafx.h and change all into this : //+-----------------------------------------------------------------+ // stdafx.h : include file for standard system include files, // or project specific include files that are used frequently, but // are changed infrequently // //+------------------------------------------------------------------+ //| Sample DLL for MQL4 | //| Copyright © 2004-2006, MetaQuotes Software Corp. | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #pragma once #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers #include // windows header files //#include // visual studio may ... //#include // not compiling both of these #include "targetver.h" // TODO: reference additional headers your program requires here //+-------------------------------------------------------------------+ 7. Open def file and write this below and save it ; ; This ==>> ; <== is how you write comment id .def file ; so you should write the code below without ; before your code ; ; ;LIBRARY "your dll name" ;DESCRIPTION 'desribing what you want but this will give you warning' ;EXPORTS ; name of function number 1 ; name of function number 2 and so on ; 8. On .cpp : DON'T delete anything but add this : //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ #define MT4_EXPFUNC __declspec(dllexport) //+------------------------------------------------------------------+ //| MetaTrader 4 data structure | //+------------------------------------------------------------------+ #pragma pack(push,1) struct RateInfo { unsigned int ctm; double open; double low; double high; double close; double vol; }; struct MqlStr { int len; char *string; }; static int CompareMqlStr(const void *left,const void *right); #pragma pack(pop) //---- //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ /* write your code like sample below MT4_EXPFUNC >variable_type< __stdcall Function_name(type variable) { your code here; return(return_function); } here is the sample : MT4_EXPFUNC int __stdcall GetIntValue(const int ipar) { printf("GetIntValue takes %d\n",ipar); return(ipar); } */ //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ 9. Click Build > click Build Solution and or Build : should gives a succeed with no error and maybe warning then write your code correctly, don't forget the _stdcall 10. if you having an errors re-check your steps and codes from both Visual Studio and MetaEditor 11. If you still having them, curse your self from following an advice from novice programmer :)