|
General Programming Help others and get yourself helped here!
|
|
This user broke our rules and has been BANNED
Status: Offline
Posts: 128
Join Date: Sep 2004
Location: Mars
|
Running an application -
02-12-2004
Is there any function that I can called to run a program at a specifc directory ?
|
|
|
|
|
Roi de France
Status: Offline
Posts: 5,049
Join Date: Nov 2003
Location: 46°43'60N 0°43'0W 0.187A
|
Re: Running an application -
02-12-2004
On Windows, use CreateProcess.
On Linux, use the execv family of functions.
These functions allow you to specify the working directory.
RACC home - Bots-United: beer, babies & bots (especially the latter)
"Learn to think by yourself, else others will do it for you."
|
|
|
|
|
This user broke our rules and has been BANNED
Status: Offline
Posts: 128
Join Date: Sep 2004
Location: Mars
|
Re: Running an application -
03-12-2004
gosh , I nearly fainted looking at the function's agruement
, how about some example ? Like launching hl ?
|
|
|
|
|
Summoner
Status: Offline
Posts: 1,499
Join Date: Feb 2004
Location: Mist Village
|
Re: Running an application -
03-12-2004
|
|
|
|
|
Member
Status: Offline
Posts: 145
Join Date: Jan 2004
Location: Slovak Republic
|
Re: Running an application -
04-12-2004
Quote:
Originally Posted by Rifleman
gosh , I nearly fainted looking at the function's agruement
, how about some example ? Like launching hl ?
|
Instead of almighty CreateProcess, use ShellExecute.
example of opening .rtf document :
Code:
ShellExecute(theApp.m_pMainWnd->GetSafeHwnd(),NULL,"document.rtf",NULL,"C:\\foo",SW_SHOW);
Last edited by koraX; 04-12-2004 at 13:56..
|
|
|
|
|
This user broke our rules and has been BANNED
Status: Offline
Posts: 128
Join Date: Sep 2004
Location: Mars
|
Re: Running an application -
04-12-2004
thanks for the reply kx , but I think shellexcute cant specify a specific directory of the program
|
|
|
|
|
Roi de France
Status: Offline
Posts: 5,049
Join Date: Nov 2003
Location: 46°43'60N 0°43'0W 0.187A
|
Re: Running an application -
04-12-2004
CreateProcess is not that complicated. There are good examples on MSDN, look it up, it's well explained.
RACC home - Bots-United: beer, babies & bots (especially the latter)
"Learn to think by yourself, else others will do it for you."
|
|
|
|
|
Member
Status: Offline
Posts: 145
Join Date: Jan 2004
Location: Slovak Republic
|
Re: Running an application -
04-12-2004
Quote:
Originally Posted by Rifleman
thanks for the reply kx , but I think shellexcute cant specify a specific directory of the program
|
You mean working directory ? It is 5. parameter in shellexecute
|
|
|
|
|
Member
Status: Offline
Posts: 145
Join Date: Jan 2004
Location: Slovak Republic
|
Re: Running an application -
04-12-2004
well I have found the ultimate guide to executing stuff about year ago, but is down now, so I'll post here important things
Code:
Execute Program Way 1
-----------------------------------------------------------------------------
WinExec("d:\\vc\\finished\\mqyvc\\release\\mqyvc.exe",SW_SHOW);
-----------------------------------------------------------------------------
Execute Program Way 2
-----------------------------------------------------------------------------
ShellExecute(NULL,NULL,_T("1.txt"),NULL,_T("c:\\temp"),SW_SHOW);
ShellExecute(NULL, _T("open"), "www.alsk.net", NULL,NULL,SW_SHOW);
ShellExecute(NULL, _T("explore"), "d:\\vc\\temp", NULL,NULL,SW_SHOW);
-----------------------------------------------------------------------------
Execute Program Way 3
-----------------------------------------------------------------------------
char szCmdLine[100];
STARTUPINFO StartupInfo;
PROCESS_INFORMATION ProcessInfo;
GetStartupInfo(&StartupInfo);
StartupInfo.dwFlags=STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow=SW_HIDE;
CreateProcess("d:\\vc\\finished\\mqyvc\\release\\mqyvc.exe",
szCmdLine,NULL,NULL,0,0,NULL,NULL,&StartupInfo,&ProcessInfo);
WaitForSingleObject(ProcessInfo.hProcess,5000);//or INFINITE
-----------------------------------------------------------------------------
Execute Program Way 4
-----------------------------------------------------------------------------
SHELLEXECUTEINFO seInfo;
ZeroMemory(&seInfo, sizeof(SHELLEXECUTEINFO));
seInfo.cbSize=sizeof(SHELLEXECUTEINFO);
seInfo.lpFile=strBrowserPath;
seInfo.lpParameters="D:\\Mqy\\Prj\\RunBrowser\\ExeFiles\\AutoLauchIndex.htm";
seInfo.nShow = SW_SHOWNORMAL;
ShellExecuteEx(&seInfo);
WaitForSingleObject(seInfo.hProcess,INFINITE);
-----------------------------------------------------------------------------
Use Multi-Language Dll
-----------------------------------------------------------------------------
In EPFApp.h:
HINSTANCE m_hLanDLL;
BOOL CEPFApp::InitInstance()
{
WORD wLangPID=PRIMARYLANGID(::GetSystemDefaultLangID());
switch(wLangPID)
{
case LANG_CHINESE:
m_hLanDLL=::LoadLibrary("EPResCn.dll");
break;
case LANG_JAPANESE:
m_hLanDLL=::LoadLibrary("EPResJp.dll");
break;
case LANG_ITALIAN:
m_hLanDLL=::LoadLibrary("EPResIt.dll");
break;
}
if(!m_hLanDLL)
m_hLanDLL=AfxGetResourceHandle();
AfxSetResourceHandle(m_hLanDLL);
.....
}
LoadString(theApp.m_hLanDLL,IDS_STR_TabRoll,sDisplay,256);
-----------------------------------------------------------------------------
Use Dll's Function in Two Way
-----------------------------------------------------------------------------
In dll's Exemid_M.h:
#ifdef EXEMID_MDLL_EXPORTS
#define EXEMID_MDLL_API extern "C" __declspec(dllexport)
#else
#define EXEMID_MDLL_API extern "C" __declspec(dllimport)
#endif
EXEMID_MDLL_API int __stdcall DllExemidInit(int iP1,int iP2);
In dll's Exemid_M.cpp:
#define EXEMID_MDLL_EXPORTS
#include "Exemid_M.h"
int __stdcall DllExemidInit(int iP1,int iP2)
{
...
return 0;
}
In dll's Exemid_M.def:
EXPORTS DllExemidInit;
-------------------------------------
Way1:Run time load
-------------------------------------
In EPFApp.h:
#include "EPDllDef.h"
HINSTANCE m_hImgDLL;
In EPDllDef.h:
typedef int (__stdcall *DllExemidInitDef)(int iP1,int iP2);
extern DllExemidInitDef DllExemidInit;
In EPFApp.cpp:
DllExemidInitDef DllExemidInit;
int CEPFApp::LoadDllFunc(void)
{
m_hImgDLL=::LoadLibrary("Exemid_M.dll");
DllExemidInit = (DllExemidInitDef)GetProcAddress(m_hImgDLL,"DllExemidInit");
}
In use place:
#include "EPFApp.h"
DllExemidInit(10,20);
-------------------------------------
Way2:Ini load together
-------------------------------------
In EPFApp.h:
#include "../Exemid_M/Exemid_M.h"
#pragma comment(lib,"../Exemid_M/Temp/Exemid_M.lib")
In use place:
#include "EPFApp.h"
DllExemidInit(10,20);
-----------------------------------------------------------------------------
Declare Standard Dll
-----------------------------------------------------------------------------
int HXSmtp.h:
#define HXSMTP_API extern "C" __declspec(dllexport)
HXSMTP_API void SmtpInform(char* strSubjet, char* strBody);
HXSMTP_API void CloseSmtp();
in HXSmtp.cpp:
HXSMTP_API void SmtpInform(char* strSubjet, char* strBody){}
HXSMTP_API void CloseSmtp(){}
in HXSmtp.def:
LIBRARY "HXSmtp"
DESCRIPTION 'HXSmtp Windows Dynamic Link Library'
EXPORTS
EXPORTS SmtpInform;
EXPORTS CloseSmtp;
-----------------------------------------------------------------------------
In Dll Use Outside Function
-----------------------------------------------------------------------------
in the dll:
typedef int( __cdecl *LPWriteLocalLog )(void *, unsigned long);
LPWriteLocalLog g_hWriteLocalLog = NULL;
HXSLLFUNC_API int NetWorkInit(LPWriteLocalLog)
{
g_hWriteLocalLog = hWriteLocalLog;
}
if( g_hWriteLocalLog )
g_hWriteLocalLog(bufExcept,iSizeExcept);
out the dll:
NetWorkInit(&WriteLocalLog);
-----------------------------------------------------------------------------
Use Dll Function
-----------------------------------------------------------------------------
typedef int MyTextOutDef(HDC hdc,int nXStart,int nYStart, LPCTSTR lpString,int cbString);
HINSTANCE hinst=LoadLibrary("a.dll");
MyTextOutDef *MyTextOut=(MyTextOutDef*)GetProcAddress(hinst,"MyTextOut");
MyTextOut(GetDC()->GetSafeHdc(),1,1,"aaa",3);
FreeLibrary(hinst);
to use this way, must have line in a.del of this dll project:
EXPORTS MyTextOut;
-----------------------------------------------------------------------------
Use Class in Dll
-----------------------------------------------------------------------------
1. Generate dll project
New-> MFC AppWizard(dll)->MFC Extension Dll(Using shared MFC dll)->
Add Class CMDXRowset as the following way:
in .h:
#define CLASS_EXPORT AFX_CLASS_EXPORT
class CLASS_EXPORT CMDXRowset
{
public:
......
}
2. Use dll class in other project
Copy and insert the class's .h file.
Link with xxx.lib.
Run with xxx.dll.
-----------------------------------------------------------------------------
Self Defined Dll Functions
-----------------------------------------------------------------------------
void CEPApp::MyShellExecute(HWND hwnd, LPCSTR lpOperation, LPCSTR lpFile, LPCSTR lpParameters, LPCSTR lpDirectory, INT nShowCmd)
{
typedef HINSTANCE (WIEPPI *SHELLEXECUTE)(
HWND hwnd,
LPCSTR lpOperation,
LPCSTR lpFile,
LPCSTR lpParameters,
LPCSTR lpDirectory,
INT nShowCmd);
HMODULE m_hShell32=LoadLibrary("Shell32.dll");
SHELLEXECUTE m_p_fnShellExecute=(SHELLEXECUTE)GetProcAddress(m_hShell32,"ShellExecuteA");
m_p_fnShellExecute(hwnd,lpOperation,lpFile,lpParameters,lpDirectory,nShowCmd);
FreeLibrary(m_hShell32);
}
BOOL CEPApp::MyShell_NotifyIcon(DWORD dwMessage, PNOTIFYICONDATAA lpData)
{
typedef BOOL (WIEPPI *SHELLNOTIFYICON)(
DWORD dwMessage, PNOTIFYICONDATAA lpData);
HMODULE m_hShell32=LoadLibrary("Shell32.dll");
SHELLNOTIFYICON m_p_fnShell_NotifyIcon=(SHELLNOTIFYICON)GetProcAddress(m_hShell32,"Shell_NotifyIconA");
BOOL bSuc=m_p_fnShell_NotifyIcon(dwMessage,lpData);
FreeLibrary(m_hShell32);
return bSuc;
}
-----------------------------------------------------------------------------
|
|
|
|
|
This user broke our rules and has been BANNED
Status: Offline
Posts: 128
Join Date: Sep 2004
Location: Mars
|
Re: Running an application -
05-12-2004
I see , thanks !
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
Powered by vBulletin® Version 3.8.2 Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com
|
|