Library ex5 as resource - page 2

 
Nelson Wanyama:

I once loaded an ex5 file into my program as a binary array. Then saved it on a file, naming it file.ex5, then tried loading it and it worked fine.

What am I saying? You can try loading the ex5 into a separate *.mqh file, then you can save the file to Libraries before trying to use access it.

However, since MQL uses early binding, I'm not sure if the file will be loaded after the EA has saved it. You might have to make your EA check for the file, if not present, create it and exit. Then the file will be loaded on next launch.

That was a great idea, thank you.

Unfortunately MT5 throws a "cannot open file" error before any code is executed so it's impossible to generate the file.

But again: Thank you! It's a nice insight.

 
Nelson Wanyama:

I once loaded an ex5 file into my program as a binary array. Then saved it on a file, naming it file.ex5, then tried loading it and it worked fine.

What am I saying? You can try loading the ex5 into a separate *.mqh file, then you can save the file to Libraries before trying to use access it.

However, since MQL uses early binding, I'm not sure if the file will be loaded after the EA has saved it. You might have to make your EA check for the file, if not present, create it and exit. Then the file will be loaded on next launch.

It is a crude method but I think it might be fun to look at.

I use the editor context-menu to add the binary file:


You can't.

 

1. Pack the library into an indicator and make API calls dynamic (via events) not static (via direct exports/imports).

2. Reconsider your decision to pack the library into EA. Why not to embed it as a part of mql compilation?

 
Stanislav Korotky:

1. Pack the library into an indicator and make API calls dynamic (via events) not static (via direct exports/imports).

2. Reconsider your decision to pack the library into EA. Why not to embed it as a part of mql compilation?

1. Not possible because the library send ordens.

2. I don't have access to the code, only the ex5 file.

 
Henrique Vilela:

That was a great idea, thank you.

Unfortunately MT5 throws a "cannot open file" error before any code is executed so it's impossible to generate the file.

But again: Thank you! It's a nice insight.

A dll call to rename the file and move it to libraries folder could do.It's a long shot, but that depends on how important the library really is.

The internal FileCopy is throwing an error trying to rename the file to *.ex5, I'm not sure why.

Edit:

After the file is saved, a manual rename to *.ex5 then move the file to Libraries gets it to work like any other.

PS: That's a dummy lib without any functions. Create one then import the ex5 as I have done.

Files:
 

Compile and run this script. It carries an ex5 to another program that prints 'Nothing'.

I guess WinAPI can help move the file to the appropriate folder then rename it. You can try it yourself.

Move the file this script produces (printit.bin) to scripts folder then rename it to *.ex5, and run it. It works just fine.

I'll take a look at winAPI, see what I can do to move the file.

Files:
Code_it.mq5  71 kb
 

I don't see how this script can help.

You replaced an ex5 (library) to another ex5 (script that writes that library).

The plan is to eliminate one file, to be able send just one ex5 file to the user instead of two.

 

I would like that same feature. I would not like to send another ex5 file to users.

At the same time, i need to provide the library to other developers. So i can't solve the problem with includes (mqh) because i want to protect/hide part of my code.

 
Henrique Vilela:

I don't see how this script can help.

You replaced an ex5 (library) to another ex5 (script that writes that library).

The plan is to eliminate one file, to be able send just one ex5 file to the user instead of two.

You can embed your program, the library and a template saved with the program on chart into a script, using the method I've shown above.

Your script should then create the files as I showed, and use a dll to move and rename them to *.ex5 and *.tpl for the template, after which it should apply the template, thus loading the program.

It seems lengthy but workable.

I have a vague knowledge of dll's, I couldn't figure out how to move and rename the files, which I'd have done.

You won't have to use the #resource directive anymore, as the script will have generated the file in the appropriate location.

I plan to use this feature to send the libraries and EAs remotely(encrypted), only when a user is fully licensed to use the product. This will help prevent 'code decompilation' of my main file.

 
Nelson Wanyama:

You can embed your program, the library and a template saved with the program on chart into a script, using the method I've shown above.

Your script should then create the files as I showed, and use a dll to move and rename them to *.ex5 and *.tpl for the template, after which it should apply the template, thus loading the program.

Got it. The script would work as in installer that generates all the files required.

I kind of like it, except for the use of dll.

Thank you so much for your help! I'll keep looking for alternatives.