Importing function from dll problems.
it appears that metatrader's string is not char in c++, its wchar_t ( windows 2 byte char )
__declspec(dllexport) void __stdcall Hello(wchar_t *say)
{
char in[32];
get_string(say, in, 31);
cout << in << endl;
}
void get_string(wchar_t *in, char *out, int ilen)
{
for (int a = 0; a < ilen; a++)
{
if (!in[a])
{
out[a] = 0;
break;
}
out[a] = (char)in[a];
}
}
Hello guys,
I'm not quite sure what am i doing wrong yet i have spend about 4 hours on this problem and somehow i just don't know the mistake.
dll:
#define MTpublic __declspec(dllexport)
using namespace std;
void MTpublic __stdcall spinit(int in)
{
sp::goconsole();
}
__declspec(dllexport) void __stdcall Hello(char *say)
{
cout << say << endl;
}
void MTpublic __stdcall spend(int in)
{
FreeConsole();
}
expert's code in mt4:
#import "MTsparklyAI.dll"
void spinit(int);
void spend(int);
void Hello(string say);
#import
int OnInit()
{
spinit(1);
Hello( "testing" );
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason)
{
spend(1);
}
MqlTick tick;
void OnTick()
{
SymbolInfoTick(_Symbol, tick);
Print( "bid:", tick.bid, " ask:", tick.ask, " time:", tick.time, " last:", tick.last );
}
Function spend and spinit works fine but Hello doesn't work.
Experts window says:
2015.10.28 19:41:06.894 Testing EURCHF,M1: unresolved import function call
2015.10.28 19:41:06.894 Cannot find 'Hello' in 'MTsparklyAI.dll'
What am i doing wrong here?
Also, somewhy it doens't allow void func() either
spend don't need params yet if it doens't have one, mt don't find the function.
tried to import it 2 ways:
#import "MTsparklyAI.dll"
void spend();
#import
and
#import "MTsparklyAI.dll"
void spend(void);
#import
also double checked if in dll function looks the same and it does but still...
Any ideas what is going on?
Thanks