Problem with .dll I'm writing

 
Hi,

I'm trying to write a .dll to use and I've hit a problem. I took the sample .dll provided and added this function:
MT4_EXPFUNC void __stdcall Hello()
{
System::Windows::Forms::MessageBox::Show("Hello from MT4!");
}

I can get the .dll to compile just fine...I can even get MQL to find it, although I had to give the complete path in the include file, the script will even attempt to call the function, but fails at the call. The log message is:

2006.12.02 09:06:07 MT4toDLLTestHelloWorld USDJPYm,Daily: loaded successfully
2006.12.02 09:06:15 MT4toDLLTestHelloWorld USDJPYm,Daily: cannot call function 'Hello' from dll 'C:\Program Files\Interbank FX Trader 4\experts\libraries\CompileSampleDLL. dll' (error 127)
2006.12.02 09:06:15 MT4toDLLTestHelloWorld USDJPYm,Daily: expert stopped

I have this directive at the top of my .dll:
#using <system.windows.forms.dll>

and I am compiling /clr, other than what I've mentioned here, I have left the code from the sample .dll untouched.

What is the problem?

BW
 


and I am compiling /clr, other than what I've mentioned here, I have left the code from the sample .dll untouched.

What is the problem?

BW

Oops...this statement was not true. Here's the other, major, difference. If I leave in the DllMain function, then the .dll compiles, but I get an error about calling "MSIL-compiled (clr) function from a native constructor or from DllMain" (this is a vc++ debug library error) when trying to run the script. If I comment out the DllMain, then I do not get this error, but I get the error from the previous post. I hope someone can help me here. Please be pedantic (i.e. long-winded) with any advice as I am quite new to vd++...and I've been ALL over the internet.

BW
 
Gee, I guess none of the moderators want to help me out...I just love all of the support provided for MQL.

BW
 
Probably calling of the windows functions does not work in MT4 dynamic libraries.
 
RickD,

Thanks for the reply...seriously. I don't think this is it, though, because I've seen numerous .dll's that call windows functions...including one that calls the MessageBox. Luckily I've found a gentleman over at forex-tsd who has successfully compiled .dll for MT4 with Visual Studio 2005 who is willing to help me out a bit.

Do you have any other ideas?

Again, thank you very much for the reply.

BW
 
There is the "allow DDL imports" tick-box in the expert settings, but you're probably aware of that one; I just mention it because it was something I overlooked when I briefly played with DLL's.
 

bwilhiteforex,

Do you use .def file?

LIBRARY YourLibrary

EXPORTS Hello

 
RickD,

I've been told this might be the problem. Visual Studio 2005 EE won't generate the .def file for me (as far as I can tell). So I may have to do it manually. I didn't think this should make a difference, because aren't the functions declared for MQL in the .mqh include file? I will definitely be giving it a try, though. Also, do you know where the .def fits into the whole process for MQL? My understanding here is a little fuzzy. Thank you for your help.

BW
 
richplank:
There is the "allow DDL imports" tick-box in the expert settings, but you're probably aware of that one; I just mention it because it was something I overlooked when I briefly played with DLL's.
Rich,

This is easy to overlook :) I WISH it were the problem. Thank you.

BW
 
bwilhiteforex

I also tried to write a dll using C# and I faild. my code was as simple as this one:

using System;

using System.Collections.Generic;

using System.Text;

namespace MYLib

{

public class Class1

{

double Getb()

{

return(5);

}

}

}

I think the problem must be from the way .NET framework is orgnizing its namespoaces. before .NET, functions were directly exposed. but now, they are hidden in shields of namespaces and classes. I think MQL can not distinguish them. Please tell us if .def file has helped you.

regards

 
I'm very interested in this as well.
Reason: