Download MetaTrader 5
To add comments, please log in or register
Have you found an interesting application? Publish it in Code Base - millions of traders will appreciate that!
maindoor
120
maindoor 2015.07.17 08:47 

Hi,

I am writing a program to open any offline chart programmatically and this works in recent mql4 builds,

but I need a dll out of this so older builds can use it. Can anyone who is familar with win32 programming help me

fix the 3 or 4 compilation issues ? I am new to windows programming and I don't know much about getting this to work.

All this does is :

1) do a file -> open offline

2) feed the chart name + \t + \r to the input device to open the chart.

Like I said this works just fine on recent builds, now just need a dll.  just need to fix a few compilation issues using visual studio.

C:\Program Files\Microsoft Visual Studio\MyProjects\offlinelib\offlinelib.cpp(34) : error C2065: 'StringToShortArray' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\offlinelib\offlinelib.cpp(36) : error C2065: 'ArraySize' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\offlinelib\offlinelib.cpp(182) : error C2065: 'GetAncestor' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\offlinelib\offlinelib.cpp(182) : error C2440: 'initializing' : cannot convert from 'int' to 'struct HWND__ *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
C:\Program Files\Microsoft Visual Studio\MyProjects\offlinelib\offlinelib.cpp(188) : error C2440: 'initializing' : cannot convert from 'char [9]' to 'unsigned short []'
        There is no context in which this conversion is possible
Error executing cl.exe.

offlinelib.dll - 5 error(s), 0 warning(s)

#include <windows.h>
#include "stdafx.h"
#include "offlinelib.h"
#include <stdio.h>

#include <string.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define MT4_EXPFUNC __declspec(dllexport) 

BEGIN_MESSAGE_MAP(COfflinelibApp, CWinApp)
END_MESSAGE_MAP()


COfflinelibApp::COfflinelibApp()
{

}

/////////////////////////////////////////////////////////////////////////////
// The one and only COfflinelibApp object

COfflinelibApp theApp;

/** For codes see http://www.codeproject.com/Articles/7305/Keyboard-Events-Simulation-using-keybd-event-funct */
void __stdcall sendStringToKeyboard(LPTSTR keyboardString, HKL h) {
               
        char charArray[40];
        StringToShortArray(keyboardString, charArray);
               
        for(int i = 0; i < ArraySize(charArray); i++) {
                switch (charArray[i]) {
                case 0:
                        //if(charArray[i] == NULL) continue;                  
                        continue;
                        break;
                case '_': {
                        keybd_event(0xA0,0x2A, 0 , 0); // shift down
                        sendStringToKeyboard("-",h);
                        keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release                  
                }
                        break;
                case '#': {
                        keybd_event(0xA0,0x2A, 0 , 0); // shift down
                        sendStringToKeyboard("3",h);
                        keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release                  
                }
                        break;
                case '!': {
                        keybd_event(0xA0,0x2A, 0 , 0); // shift down
                        sendStringToKeyboard("1",h);
                        keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release                  
                }
                        break;
                case '%': {
                        keybd_event(0xA0,0x2A, 0 , 0); // shift down
                        sendStringToKeyboard("5",h);
                        keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release                  
                }
                        break;
                case '&': {
                        keybd_event(0xA0,0x2A, 0 , 0); // shift down
                        sendStringToKeyboard("7",h);
                        keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release                  
                }
                        break;
                case '$': {
                        keybd_event(0xA0,0x2A, 0 , 0); // shift down
                        sendStringToKeyboard("4",h);
                        keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release                  
                }
                        break;
                case '@': {
                        keybd_event(0xA0,0x2A, 0 , 0); // shift down
                        sendStringToKeyboard("2",h);
                        keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release                  
                }
                        break;
                case '^': {
                        keybd_event(0xA0,0x2A, 0 , 0); // shift down
                        sendStringToKeyboard("6",h);
                        keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release                  
                }
                        break;
                case '*': {
                        keybd_event(0xA0,0x2A, 0 , 0); // shift down
                        sendStringToKeyboard("8",h);
                        keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release                  
                }
                        break;
                case '(': {
                        keybd_event(0xA0,0x2A, 0 , 0); // shift down
                        sendStringToKeyboard("9",h);
                        keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release                  
                }
                        break;
                case ')': {
                        keybd_event(0xA0,0x2A, 0 , 0); // shift down
                        sendStringToKeyboard("0",h);
                        keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release                  
                }
                        break;
                case '?': {
                        keybd_event(0xA0,0x2A, 0 , 0); // shift down
                        sendStringToKeyboard("/",h);
                        keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release                  
                }
                        break;
                case '<': {
                        keybd_event(0xA0,0x2A, 0 , 0); // shift down
                        sendStringToKeyboard(",",h);
                        keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release                  
                }
                        break;
                case '>': {
                        keybd_event(0xA0,0x2A, 0 , 0); // shift down
                        sendStringToKeyboard(".",h);
                        keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release                  
                }
                        break;
                case '~': {
                        keybd_event(0xA0,0x2A, 0 , 0); // shift down
                        sendStringToKeyboard("`",h);
                        keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release                  
                }
                        break;
                case '+': {
                        keybd_event(0xA0,0x2A, 0 , 0); // shift down
                        sendStringToKeyboard("=",h);
                        keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release                  
                }
                        break;
                case ':': {
                        keybd_event(0xA0,0x2A, 0 , 0); // shift down
                        sendStringToKeyboard(";",h);
                        keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release                  
                }
                        break;
                case '"': {
                        keybd_event(0xA0,0x2A, 0 , 0); // shift down
                        sendStringToKeyboard("\'",h);
                        keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release                  
                }
                        break;
                case '|': {
                        keybd_event(0xA0,0x2A, 0 , 0); // shift down
                        sendStringToKeyboard("\\",h);
                        keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release                  
                }
                        break;
                case '}': {
                        keybd_event(0xA0,0x2A, 0 , 0); // shift down
                        sendStringToKeyboard("]",h);
                        keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release                  
                }
                        break;
                case '{': {
                        keybd_event(0xA0,0x2A, 0 , 0); // shift down
                        sendStringToKeyboard("[",h);
                        keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release                  
                }
                        break;
                default: {
                        unsigned char vkey = (unsigned char)VkKeyScanExW(charArray[i], h);                  
                        unsigned char skey = (unsigned char)MapVirtualKeyW(vkey, 0);
                        keybd_event(vkey,skey,0 , 0); // ‘A’ Press
                        keybd_event(vkey,skey, KEYEVENTF_KEYUP,0); // ‘A’ Release                  
                }
                        break;
                }
        }
}


MT4_EXPFUNC void __stdcall openoffline(HWND chint, LPTSTR chname)
{
        HWND ancestorhandle = GetAncestor(chint, 2);
        PostMessageW(ancestorhandle, 0x0111, 33053, 0);

        // keep current locale
        HKL origH = GetKeyboardLayout(0);
        // set US English locale
        unsigned short uslayout[] ="00000409";
        const unsigned short *usl = uslayout;               
        HKL h = LoadKeyboardLayoutW(usl, 0x00000001);
                  
        // ctrl up
        keybd_event(0xA0, 0x2A, KEYEVENTF_KEYUP,0); // ‘left ctrl’ Release
        keybd_event(0xA1, 0x36, KEYEVENTF_KEYUP,0); // ‘righ ctrl’ Release
        Sleep(1000); 
        chname = lstrcat(chname, "\t");
        chname = lstrcat(chname, "\r");
    sendStringToKeyboard(chname, h);             

}            
           
 
JD4
1101
JD4 2015.07.17 18:46  

I am probably reading this wrong, but it looks like you are asking for help on a Visual Studio compile issue in a forum for MQL4 and MT4.  I also see a .cpp file extenstion, which, unless I am mistaken, stands for C++, again, not MQL4.

As far as the issues you are having, it looks like it tells you what is happening in the errors.  'StringToShortArray', 'ArraySize', and 'GetAncestor' are all "undeclared identifier", probably because the code is looking for functions with those names, and not finding them.  Those error lines are also telling you where in your code the issues are.  I am not sure if your settings are not right, as far as where you are telling the program to look for those files or what.  Any possible number of things could be causing things like that, but given that those names seem to be proper language function names, the file location issue sounds to be the most likely cause.

/
To add comments, please log in or register