Creating c# library for mt4

 
I have worked on a simple DLL for mt4 by using visual studio 2013 c#. I added RGiesecke modules by using NuGet packeges. I can call simple procedures when it has only integer values. But when the function in the library has string values, mt4 cant find the function. Also, it makes wrong results for double or floating math operations. Does anyone have any experience on c# - mt4 connections.
 

I tried with C++, exactly the same code in https://www.mql5.com/en/articles/18. Below is the message I get. 

2016.05.19 21:08:38.642    2012.01.02 02:00  Cannot load 'CDLLsample.dll' [126]


I tried changing MFU as described in comments, and also compiled with x64, still the same error code 126. 

How to Exchange Data: A DLL for MQL5 in 10 Minutes
How to Exchange Data: A DLL for MQL5 in 10 Minutes
  • 2010.01.27
  • Renat Fatkhullin
  • www.mql5.com
Now not so many developers remember how to write a simple DLL, and what are special features of different system binding. Using several examples, I will try to show the entire process of the simple DLL's creation in 10 minutes, as well as to discuss some technical details of our binding implementation. I will show the step-by-step process of DLL creation in Visual Studio with examples of exchanging different types of variables (numbers, arrays, strings, etc.). Besides I will explain how to protect your client terminal from crashes in custom DLLs.
 
Cagatay Tezsezen:

I tried with C++, exactly the same code in https://www.mql5.com/en/articles/18. Below is the message I get. 

2016.05.19 21:08:38.642    2012.01.02 02:00  Cannot load 'CDLLsample.dll' [126]


I tried changing MFU as described in comments, and also compiled with x64, still the same error code 126. 

https://www.mql5.com/en/forum/103454
What can cause "cannot load library mylib.dll (error 126)"? (forexzapATgmailDOTcom) - MQL4 forum
What can cause "cannot load library mylib.dll (error 126)"? (forexzapATgmailDOTcom) - MQL4 forum
  • www.mql5.com
What can cause "cannot load library mylib.dll (error 126)"? (forexzapATgmailDOTcom) - MQL4 forum
 
Thank you for the answer. I found that registering the directories of libraries are not enough. One must copy all necessary lib and dll files to expert directory. Aso, it is not enough to copy them to include directory. But still there are strange problems that has to be solved. I can return integer, double or any number. However, I can not return back a string.
 
Cagatay Tezsezen:
I have worked on a simple DLL for mt4 by using visual studio 2013 c#. I added RGiesecke modules by using NuGet packeges. I can call simple procedures when it has only integer values. But when the function in the library has string values, mt4 cant find the function. Also, it makes wrong results for double or floating math operations. Does anyone have any experience on c# - mt4 connections.
Try compile with x86 not x64.
 
Cagatay Tezsezen:
Thank you for the answer. I found that registering the directories of libraries are not enough. One must copy all necessary lib and dll files to expert directory. Aso, it is not enough to copy them to include directory. But still there are strange problems that has to be solved. I can return integer, double or any number. However, I can not return back a string.
Answer is mql4_ansi2unicode. You can google this for more information.
 
Anton Nel:
Answer is mql4_ansi2unicode. You can google this for more information.

Hi Anton.


Happy to see you.  I compile with 86.

I noticed Foating values are also passed wrong to mt4. Only integers are being sent correctly. What d you think the reason is?

 
Cagatay Tezsezen:

Hi Anton.


Happy to see you.  I compile with 86.

I noticed Foating values are also passed wrong to mt4. Only integers are being sent correctly. What d you think the reason is?

What about "double" instead of "float"?
 
Anton Nel:
What about "double" instead of "float"?
Same. It sends a value but the value is not as expected.
 
Cagatay Tezsezen:
Same. It sends a value but the value is not as expected.
What does the value look like? Example?
 
Anton Nel:
What does the value look like? Example?

Thank you very much Anton. I solved the problem about strings. I did not work on double and float problem yet, because I have another issue. I try to export a DLL function to mt4. The red line gives an error message when trying to load to mt4: Unhandled exception 0xE0434352.

  [DllExport("readmysql", CallingConvention = CallingConvention.StdCall)]
        public static string readmysql(string databasename, string tablename, string refereanceword, string columnname, string lookupcolumn)
        {
   
        string myConnectionString = "server=localhost;uid=root;" + "pwd=000000;database=trytabase;";

            MySqlCommand mcd;
            MySqlDataReader mdr;
            string getvalue;


            MySql.Data.MySqlClient.MySqlConnection conn;
            conn = new MySql.Data.MySqlClient.MySqlConnection();

            conn.ConnectionString = myConnectionString;


I appreciate any comment on that matter

Reason: