Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
If it is an embedded resource then it will ALWAYS exist. If it did not then there should have been a compile error.
The problem is that you are depending on runtime value (i.e. the symbol name) to index a resource that should have been statically embedded as resources at compile time.
That is invalid programming for resources that are embedded at compile time...
string alertSoundFile = "::Images\\Alert"+_Symbol+".wav";
Hello fellow traders,
I'm working on the HLINE alert trigger function of my EA, and I've stored as a ressource WAV sound files for a few symbols, and wanted to use the Alert() function for when the audi file is not found.
But I realized that when you use Playsound with a resource file, it will always return true, even if the file does not exist. It will return true and play nothing.
So I have tried to check if the file exists using FileIsExist() with the path of the file but it always returns false, whether the resource file exists or not.
Here is the code :
Obviously PlaySound() will always return true if it is tested without the FileIsExist() function before as it doesn't get accessed because of the FileIsExist() returning false all the time.
I also tested with: But it also returns false all the time, even if the file exists.
I have tried in both MQL5 and MQL4, same issue.
I searched on the forum but couldn't find anything related to this issue.
Can someone think of any solution or workaround?
Thank you in advance!
it works just fine, you don't show your resource declaration and as Fernando states your addressing the resource is wrong.
I really apologize for posting in the wrong section, my bad! That won't happen again.
Also thank you so much for pointing that out, I hadn't thought about it! I understand better how it works now.
I have made modifications accordingly and now it's working. :)
Thank you!
To Paul:
Thank you for checking and confirming. I'm self taught and still have a lot to learn.
I'm glad I was able to learn something from you two. Thank you again!
Following your advices I was able to make it work on MT5, but it still doesn't work on MT4.
PlaySound returns true even if the file is not declared in the resources.
So nothing is played but it returns true.
Paul, this is how I declared the audio files:
// Global scope #resource "\\Images\\AlertAUDCAD.wav" #resource "\\Images\\AlertAUDCHF.wav" #resource "\\Images\\AlertAUDJPY.wav" #resource "\\Images\\AlertAUDNZD.wav" string alertSoundFile; int OnInit(){ alertSoundFile = "::Images\\Alert"+_Symbol+".wav"; }Did you also try the code on MT4? Was it working on your side?
I'm on MT4 version 4.00 build 1420.
Follow up:
Following your advices I was able to make it work on MT5, but it still doesn't work on MT4.
PlaySound returns true even if the file is not declared in the resources.
So nothing is played but it returns true.
Paul, this is how I declared the audio files:
Did you also try the code on MT4? Was it working on your side?
I'm on MT4 version 4.00 build 1420.
You are assuming that the broker uses the same naming convention that you are using. Your code will fail on any broker that uses different symbol names( e.g. "AUDCAD.r", "mEURUSD", etc.).
Also, don't just use the symbol name directly when referencing your resource. That is bad programming.
Check it against a known valid list and map it to the correct one, and report an error when there is no valid mapping, or use a default resource for when it does not map.
Thank you for pointing that out. I will try a different approach.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I'm working on the HLINE alert trigger function of my EA, and I've stored as a ressource WAV sound files for a few symbols, and wanted to use the Alert() function for when the audi file is not found.
But I realized that when you use Playsound with a resource file, it will always return true, even if the file does not exist. It will return true and play nothing.
So I have tried to check if the file exists using FileIsExist() with the path of the file but it always returns false, whether the resource file exists or not.
Here is the code :
Obviously PlaySound() will always return true if it is tested without the FileIsExist() function before as it doesn't get accessed because of the FileIsExist() returning false all the time.
I also tested with: But it also returns false all the time, even if the file exists.
I have tried in both MQL5 and MQL4, same issue.
I searched on the forum but couldn't find anything related to this issue.
Can someone think of any solution or workaround?
Thank you in advance!