DutchKevv
DutchKevv

Reputation: 1699

How to get a file name from a current Class in MQL4 (.mq4)?

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

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

Source - https://msdn.microsoft.com/nl-nl/library/windows/desktop/ms683197(v=vs.85).aspx

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();
#import

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?

Upvotes: 1

Views: 858

Answers (2)

user3666197
user3666197

Reputation: 1

Current filename is read-able via a __FILE__ macro.

New-MQL4 has a built in support for showing current file name.

With a support for __FILE__, __LINE__, __PATH__ et al, one may implement whatever in-vivo / post-mortem code reporting facility suites one's needs.

MetaEditor documentation shows other additional macros __FUNCSIG__, __MQL4BUILD__ and many more.

Upvotes: 1

DutchKevv
DutchKevv

Reputation: 1699

I found a workaround..

With the following function

typename(this);

The ClassName is given.. This gives me enough to work with..

A function that outputs the real 'file-name' is still welcome.

Upvotes: 2

Related Questions