C++中调用.EXE高手指点一下
用C++编写一个调用.exe文件来处理图片的程序
该.exe文件处理程序需要用convert.exe a.jpg -compress b.tiff 命令
ShellExecute(handle, "explore ", path_to_folder, NULL, NULL, SW_SHOWNORMAL);函数能写这个程序么
include <shellapi.h>
#include <iostream>
using namespace std;
int main()
{
ShellExecute(handle, "open ", "C:\\Program Files\\ImageMagick-6.2.7-Q16\\convert.exe ", NULL,
NULL, SW_SHOW );
system( "convert.exe a.jpg -compress none b.tiff ");
cout < < "我的功能是运行一个记事本. " < <endl;
return 0;
}
这样对么 我怎么运行不出来啊 错在哪里 帮改一下
[解决办法]
#include <windows.h>
[解决办法]
简单啊
CreateProcess(_T( "C:\\Program Files\\ImageMagick-6.2.7-Q16\\convert.exe "),
_T( "a.jpg -compress b.tiff "),
LPSECURITY_ATTRIBUTES lpProcessAttributes,\\NULL
LPSECURITY_ATTRIBUTES lpThreadAttributes,\\NULL
BOOL bInheritHandles,\\ true or false
DWORD dwCreationFlags,\\ 其他参数见sdk或msdn
LPVOID lpEnvironment,
LPCTSTR lpCurrentDirectory,
LPSTARTUPINFO lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation
)
[解决办法]
#include <string>
#include <windows.h>
using namespace std;
int main(int argc, char* argv[])
{
PROCESS_INFORMATION ProcessInfo;
STARTUPINFO StartupInfo={0};
string strCmd;
strCmd = "C:\\Program Files\\ImageMagick-6.2.7-Q16\\convert.exe a.jpg -compress none b.tiff ";
CreateProcess(NULL,
(char*)strCmd.c_str(),
NULL,
NULL,
FALSE,
CREATE_NEW_CONSOLE,
NULL,
NULL,
&StartupInfo,
&ProcessInfo);
return 0;
}