DLL argument conversion failure

 

Hello,

I'm preparing to call a DLL within MT4 and I've come across one construct which I can't get to work. 

The original C++ code is here:

typedef void(TA_CC * TrialCallbackType)(uint32_t, void *);
TURBOACTIVATE_API HRESULT TA_CC TA_SetTrialCallback(uint32_t handle, TrialCallbackType callback, void * userDefinedPtr);

I've converted it to this code:

typedef void(*TrialCallbackType)(int, void *);
int TA_SetTrialCallback(int handle, TrialCallbackType callback, void *userDefinedPtr);

but when I compile I'm getting these errors:

'callback' - invalid parameter for import function
'userDefinedPtr' - invalid parameter for import function

Any suggestions please?

 
imamushroom:

Hello,

I'm preparing to call a DLL within MT4 and I've come across one construct which I can't get to work. 

The original C++ code is here:

I've converted it to this code:

but when I compile I'm getting these errors:

Any suggestions please?

Ensure that the data types and calling conventions match what MQL4 supports. Unlike C++, MQL4 has some limitations regarding function parameter types, especially when it comes to pointers. MT4 does not directly support passing function pointers or raw pointers as function parameters.

Void > int or long or custom structure

MQL4 cannot directly handle function pointers ( TrialCallbackType ), as it doesn't support passing function references from MQL4 to a DLL, you cannot directly pass a function pointer ( TrialCallbackType callback ), you will need to handle the callback within the DLL itself.  Set up a static function inside the DLL that is called when necessary. You can convert the void * parameter to an int or long type, and inside the DLL, you can reinterpret it to the actual pointer type. MQL4 can work with integers ( int or long ), and the DLL should convert these back to the appropriate pointer type.

Correct me if im wrong