You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Simulating old Ansi string arrays is messy, but still possible. (This is going to depend on the DLL being well-behaved, particularly if it passes data back to MQL4 by altering the contents of the array. I've only tested this against the example C++ code at the bottom, not against something more realistic like MySql library.)
For example, the above code works with the following DLL which does a message box for each string in an array and then reverses the string before returning to MT4:
I just can't explain how helpful your snippets are. Thank you so much! I've went ahead and wrote a MySQL wrapper in pure MQL4 (for UNICODE version) that communicates with libmysql.dll (ANSI) using techniques you mentioned and techniques I found in EAX MySQL library (MQL5).
I'd really appreciate if you could take a look at my code there and let me know about things to improve or contribute to it as I'm pretty sure it could be improved.
gchrmt4,
Can you please show me how I can pass a string through a DLL function call, or point me to some sample code?
What I am looking for is confirmation that I can do a call such as:
#import
int call_a_string_function(string this_is_a_string);
#import
...
...
string foo1 = "this is a string";
int retruncode = call_a_string_function(foo1);
then what would the C code look like for the above function? I am just looking for the routine example.
e.g.
int call_a_string_function(char *this_is_a_string);
etc
Some people say to use an array or a char array etc. I am looking for some clarification. Just a simple sample on the best approach as you have mentioned memory leakage etc.
regards
gorick
gchrmt4,
Can you please show me how I can pass a string through a DLL function call, or point me to some sample code?
What I am looking for is confirmation that I can do a call such as:
#import
int call_a_string_function(string this_is_a_string);
#import
...
...
string foo1 = "this is a string";
int retruncode = call_a_string_function(foo1);
then what would the C code look like for the above function? I am just looking for the routine example.
e.g.
int call_a_string_function(char *this_is_a_string);
etc
Some people say to use an array or a char array etc. I am looking for some clarification. Just a simple sample on the best approach as you have mentioned memory leakage etc.
regards
gorick
Yes, thanks for that. Really well presented and what I expected. However, I seem to be having issues with strings.
I created a sample from that document in C, e.g below, to accept a string value as input and write it to a file:
I write the vales to a file to check.MQL is as follows:
The file output is as follows:These are the string values: R foooooooooooo1
It only returns the "R" or first character of the passed string? The "foooooooooooo1" was inserted just to check that I am printing correctly.
Does anyone have an idea of what I am doing wrong?
Yes, thanks for that. Really well presented and what I expected. However, I seem to be having issues with strings.
I created a sample from that document in C, e.g below, to accept a string value as input and write it to a file:
<removed>
Does anyone have an idea of what I am doing wrong?
The issue is in your C code, not in MQL4.
%s in printf() means "Ansi string". You need to use %ls
Yes, thanks for that. Really well presented and what I expected. However, I seem to be having issues with strings.
I created a sample from that document in C, e.g below, to accept a string value as input and write it to a file:
I write the vales to a file to check.MQL is as follows:
The file output is as follows:These are the string values: R foooooooooooo1
It only returns the "R" or first character of the passed string? The "foooooooooooo1" was inserted just to check that I am printing correctly.
Does anyone have an idea of what I am doing wrong?
Hello,
Please use the SRC button when you post code. Thank you.
This time, I edited it for you.
Hello,
Please use the SRC button when you post code. Thank you.
This time, I edited it for you.
Sorry guys, really new to posting here.
Thanks for your input, I am really grateful.
What this implies is that all the existing samples are not accurate. One has to use unicode. As I am very new to programming DLLs I started from scratch just recently, so I relied heavily on the samples given. Also, I happened to start using the 600 build at the same time.
If you have been doing this for a long time, I'd imagine that you are completely aware of the situation. I unfortunately am not, only getting snippets of information and advice in this forum.
I apologise for my ignorance.
regards and thanks
If anyone has any suggestions on what to do better please let me know.
I thank you again.
If anyone has any suggestions on what to do better please let me know.
I thank you again.