Thank to @Dave-KreskowiakWatch I find the MQL5 solution. and now I Find the solution for mql4 too.
you can use this 2 link for the start:
https://www.mql5.com/en/forum/353293[
^]
Calling a DLL from MQL | Andres Jaimes[
^]
first of all we should put the output project on x86 and .NET framework 3.5. also need install package unmanaged exports for nugget. because the MQL4 only can read the x86 and C++ DLL so we need the unmanaged exports to worked as the middleware.
the example on 2 link is worked but for the string we should do the extra work. because the MQL4 encoding the string in UTF-16 or UCS-2. so you should convert the string in utf-16 code on DLL.
the final code for C# DLL and change the code too this is:
using RGiesecke.DllExport;
using System.Runtime.InteropServices;
using System.Management;
using System;
namespace SystemInformationMQL4
{
public class Class1
{
[DllExport("GetMotherboardSerialNumber", CallingConvention = CallingConvention.StdCall)]
public static IntPtr GetMotherboardSerialNumber()
{
string serialNumber = string.Empty;
using (var searcher = new ManagementObjectSearcher("SELECT SerialNumber FROM Win32_BaseBoard"))
{
foreach (var queryObj in searcher.Get())
{
serialNumber = queryObj["SerialNumber"].ToString();
break;
}
}
return Marshal.StringToHGlobalUni(serialNumber);
}
[DllExport("GetStorageDeviceSerialNumber", CallingConvention = CallingConvention.StdCall)]
public static IntPtr GetStorageDeviceSerialNumber()
{
string serialNumber = string.Empty;
using (var searcher = new ManagementObjectSearcher("SELECT SerialNumber FROM Win32_DiskDrive WHERE MediaType='Fixed hard disk media'"))
{
foreach (var queryObj in searcher.Get())
{
serialNumber = queryObj["SerialNumber"].ToString();
break;
}
}
return Marshal.StringToHGlobalUni(serialNumber);
}
}
}
and the mql4 code is:
#import "SystemInformationMQL4.dll"
string GetMotherboardSerialNumber();
string GetStorageDeviceSerialNumber();
#import
int OnInit()
{
string motherBoard = GetMotherboardSerialNumber();
string hardDrive = GetStorageDeviceSerialNumber();
Alert(motherBoard + " " + hardDrive);
return(INIT_SUCCEEDED);
}
and with this we have C# DLL worked in MQL4.