ShellExecute(NULL,L"open",L"D:\\CSharpConsoleApp1.exe",NULL, NULL,SW_SHOWDEFAULT);
//Run CSharpConsoleApp1.exe.
thanks Luptator
this is my whole c++ project-only one function:
ExpertSample.CPP :
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <shellapi.h>
#define MT4_EXPFUNC __declspec(dllexport)
//+------------------------------------------------------------------+
BOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)
{
//----
switch(ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
//----
return(TRUE);
}
//+------------------------------------------------------------------+
MT4_EXPFUNC void __stdcall T1()
{
ShellExecute(NULL,"open", "D:\\CSharpConsoleApp1.exe",NULL, NULL,SW_SHOWDEFAULT);
return;
}
//+------------------------------------------------------------------+
and ExpertSample.def:
LIBRARY ExpertSample
EXPORTS T1
and at the end I receive this error:
--------------------Configuration: ExpertSample - Win32 Debug--------------------
Compiling...
ExpertSample.cpp
d:\forex\n2\experts\indicators\expertsample.cpp(30) : warning C4129: 'F' : unrecognized character escape sequence
Linking...
Creating library Debug/ExpertSample.lib and object Debug/ExpertSample. exp
ExpertSample.obj : error LNK2001: unresolved external symbol __imp__ShellExecuteA@24
Debug/ExpertSample.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
ExpertSample.dll - 2 error(s), 1 warning(s)
could you please give more help?
#pragma comment (lib,"shell32.lib")
From MSDN:
"
Error Message
unresolved external symbol "symbol"Code references something (such as a function, variable, or label) that the linker can't find in the libraries and object files.
This error message is followed by fatal error LNK1120.
The project is missing a reference to a library (.LIB) or object (.OBJ) file.
"thanks.
now it compiles and Links but doesn't execute:
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <shellapi.h>
//----
#define MT4_EXPFUNC __declspec(dllexport)
#pragma comment (lib,"shell32.lib")
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
BOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)
{
//----
switch(ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
//----
return(TRUE);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
MT4_EXPFUNC void __stdcall T1()
{
ShellExecute(NULL,"open","C:\\Windows\\notepad.exe",NULL,NULL, SW_SHOWDEFAULT);
return;
}
//+------------------------------------------------------------------+
MT4_EXPFUNC int __stdcall T2()
{
return(1);
}
def file:
LIBRARY ExpertSample
T1
T2
and an indicator using this dll:
#property indicator_chart_window #import "D:\Forex\N2\experts\indicators\ExpertSample.dll" void T1(); int T2(); #import int init() { Alert(T2()); T1(); return(0); } int deinit() { return(0); } int start() { int counted_bars=IndicatorCounted(); //---- //---- return(0); }
could you please help?
Copy ExpertSample.dll to \experts\libraries\
MQL4 code:
#import "ExpertSample.dll" void T1(); int T2(); #import
I did all of them:
program works well because alert(T2()) wroks as it should do.
there is no errors in journal
and I copied DLL to Libraries dir
but program doesn't work?
do you have any new Idea?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello
I have a question and my question is more related to C programming instead of MQL:
I wrote a program in C# to run on each tic of terminal. This is an exe console application. now I can't find a way to run a console application from within dlls. I tried ShellExecute from <shellapi.h> and failed(may be this is my own problem not to be familiar enough with using this api)
could you please help me?