Download MetaTrader 5

Get current file name inside Class

To add comments, please log in or register

Hi there,


To prevent some boilerplate code, I want to read the file name, of the file a class is executing in..  

There is no default MQ4 function available, but it should be possible with a native windows function (GetModuleFileName kernel32.dll)

Source - 

 I did read about #import the Kernel32.dll, and steal some functions from there, but it doesn't seem to work..


#import "kernel32.dll"
   int  GetModuleFileName();


It gives me the following error ->

2015.01.05 00:15  Cannot find 'GetModuleFileName' in 'kernel32.dll'

It explains itself, the getModuleFileName is not in kernel32.dll

Does anyone know how to get the current file name??



Ex Ovo Omnia
Ex Ovo Omnia  

Well, regarding the proper import, the information is in the link you published.

GetModuleFileNameW (Unicode) and GetModuleFileNameA (ANSI)


DWORD WINAPI GetModuleFileName(
  _In_opt_ HMODULE hModule,
  _Out_    LPTSTR  lpFilename,
  _In_     DWORD   nSize 


The proper syntax for import would be

int GetModuleFileNameW(int zero,str& lpFilename,int nSize);

This command would very likely return "terminal.exe" module.

If you expect the current script name, you should use MQLInfoString(MQL_PROGRAM_NAME)

To add comments, please log in or register