Hi.
Thank you for your update.
Here are 2 remarks :
1- I could finally successfully compile the following statements that you provided me with previously for debugging purpose :
#pragma comment(lib, "User32")
void __stdcall MyFunction(wchar_t* string1, wchar_t* string2)
{
std::wstringstream msg;
msg << L"string1 = " << string1 << L"\n\n" << L"string2 = "
<< string2;
MessageBoxW(0, msg.str().c_str(), L"Message", MB_OK|MB_ICONINFORMATION);
}
I just added the statement #include <sstream> and compilation was OK.
After calling the DLL, your code displayed the 2 parameters passed to the DLL corectly.
We can thus be sure that parameters are passed correctly to the DLL.
2- Just like you do, I suspected there might be something wrong with the ShellExecuteExW statement.
I found this item :
https://stackoverflow.com/questions/42155265/shellexecuteex-doesnt-pass-long-command
The problem described in there might be similar to my problem : it is related to something that doesn't work with ShellExecuteEx, but which is OK when ShellExecute is used. The problem is related to a very long lpFile value in the SHELLEXECUTE info structure.
My 'string'2' value being also rather long (more than 100 characters). I copied the file described by 'string2' into another location, in order to make the lpFile parameter shorter (the new value of string2 is now something like C:/name.R).
With this change, the DLL runs fine : the R script that is executed creates the wished files.
But this causes another problem : the DLL is only executed once, because when control is given back to Metatrader, some message like 'stack is damaged' are issued, and the DLL is no longer called (the calling program runs once per minute). I have to investigate the problem on the Metatrader side but at least this test shows that there is something wrong occuring with ShellExecuteExW, as you suspect.
Based on the results of the numerous tests so far, I have got the impression that when lpFile is 'long', the ShellExecuteExW does nothing and gives a zero return code (?) whilst when
lpFile is 'short', ShellExecuteExW works fine.
On the other side, ShellExecuteExW works fine when lpFile is assigned a hardcoded value (even a 'long' one).
I also found that there were some limitations about the length of the value assigned to lpFile (I found 2K, or 8K, depending on the 'author'), but anyway those limitations are far beyond the value that I am using.
I shall try to persue the track you suggest, using CreateProcess instead of ShellExecuteEx.
Thanks.