#pragma once
//help macro
#ifndef SAFE_DELETE
#define SAFE_DELETE(p) if(p){ delete p; p = NULL; }
#endif
//
#ifndef SAFE_DELETE_ARY
#define SAFE_DELETE_ARY(p) if(p){ delete []p; p = NULL; }
#endif
#ifndef CLR_ARY
#define CLR_ARY( t, s, n ) memset( &n, 0, sizeof(t)*s );
#endif
#ifndef CLR_PTR
#define CLR_PTR( t, s, p ) memset( p, 0, s*sizeof(t) );
#endif
#ifndef DEC_CLR_ARY
#define DEC_CLR_ARY(t, s, n ) t n[s]; CLR_ARY( t, s, n );
#endif
#ifndef DEC_CLR_CHR_ARY
#define DEC_CLR_CHR_ARY( n, size ) DEC_CLR_ARY( TCHAR, size, n )
#endif
#ifndef CLR_CHR_ARY
#define CLR_CHR_ARY( n, s ) CLR_ARY( TCHAR, n, s )
#endif
#ifndef DEC_CLR_PTR_ARY
#define DEC_CLR_PTR_ARY( t, size, n ) \
t* n = new t[size]; \
if(n){ CLR_PTR( t, size, n ) }
#endif
#ifndef DEC_CLR_CHR_PTR_ARY
#define DEC_CLR_CHR_PTR_ARY( n, s ) DEC_CLR_PTR_ARY( TCHAR, s, n )
#endif
#ifndef CLR_SCT
#define CLR_SCT( t, n ) memset( &n, 0, sizeof(t) );
#endif
#ifndef CLR_SCT_PTR
#define CLR_SCT_PTR( t, p ) memset( p, 0, sizeof(t) );
#endif
#ifndef DEC_CLR_SCT
#define DEC_CLR_SCT( t, n ) t n; CLR_SCT( t, n);
#endif
#ifndef GET_NEW_CHRARY_SIZE
#define GET_NEW_CHRARY_SIZE( n ) (_tcslen(n)+1)*sizeof(TCHAR)
#endif
#ifdef _AFXDLL
//
// function:GetAppExePath
// desc: get exe path
// return: CString
inline CString GetAppExePath(void)
{
DEC_CLR_CHR_ARY( cp, MAX_PATH );
GetModuleFileName( NULL, cp, MAX_PATH );
return CString(cp);
}
//
//
// function GetCurExePath
// desc: get cur execute file path
// return: CString
inline CString GetCurExePath(void)
{
DEC_CLR_CHR_ARY( cp, MAX_PATH );
GetModuleFileName( NULL, cp, MAX_PATH );
while( cp[ _tcslen( cp )-1 ] != TEXT('\\') )
{
cp[ _tcslen( cp ) - 1 ] = TEXT('\0');
}
return CString( cp );
}
#endif
inline BOOL GetAppExePath( LPTSTR p)
{
if(!GetModuleFileName( NULL, p, MAX_PATH ) )
{
return FALSE;
}else{
return TRUE;
}
}
//
inline BOOL GetCurAppPath( LPTSTR p)
{
if(!GetModuleFileName( NULL, p, MAX_PATH ) )
{
return FALSE;
}else{
while( p[_tcslen(p)-1] != TEXT('\\') )
{
p[_tcslen(p)-1] = TEXT('\0');
}
return TRUE;
}
}
//
inline BOOL RunExtPath( LPCTSTR p, bool showwindow = true, bool bInner = true, bool useParam = false, bool fpath = true)
{
if( NULL == p ){ return FALSE; }
STARTUPINFO si;
PROCESS_INFORMATION pi;
BOOL bOK = FALSE;
CLR_SCT( STARTUPINFO, si );
si.cb = sizeof( STARTUPINFO );
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = showwindow?SW_SHOW:SW_HIDE;
if( !showwindow )
{
si.hStdError = stderr;
si.hStdInput = stdin;
si.hStdOutput = stdout;
}
DEC_CLR_CHR_ARY( np, MAX_PATH );
if( !fpath )
{
if( GetCurAppPath( np ) )
{
_tcscat_s( np, MAX_PATH, p );
}
}else{
_tcscpy_s( np, MAX_PATH, p );
}
bOK = ::CreateProcess(
(useParam )?NULL:(np), //NULL,
(useParam )?(np):NULL, //(np),
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&si,
&pi);
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
return bOK;
}
//
inline bool GetExeAppName( LPTSTR s )
{
bool bOK = true;
DEC_CLR_CHR_ARY( nn, MAX_PATH );
if( GetAppExePath( nn ) ){
while( nn[_tcslen(nn)-1] != _T('\\') )
{
s[_tcslen(s)] = nn[_tcslen(nn)-1];
nn[_tcslen(nn)-1] = _T('\0');
}
_tcsrev(s);
}else{
bOK = false;
}
return bOK;
}
3262

被折叠的 条评论
为什么被折叠?



