|
/////////////////////////////////////////////////////////////////
// //
// Usefull helper functions //
//-------------------------------------------------------------//
// //
// By Eugene Khodakovsky //
// June, 2000 //
// ekhodakovsky@yahoo.com //
/////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include <fstream.h>
#include "SLUtil.h"
// C:/WINDOWS
const CString GetWindowsDirectory()
{
TCHAR path[MAX_PATH] = {0};
::GetWindowsDirectory(path,sizeof(path)/sizeof(TCHAR));
return CString(path);
}
// C:/WINDOWS/SYSTEM
const CString GetSystemDirectory()
{
TCHAR path[MAX_PATH] = {0};
::GetSystemDirectory(path,sizeof(path)/sizeof(TCHAR));
return CString(path);
}
const CString GetUserName()
{
TCHAR name[MAX_PATH] = {0};
DWORD nSize = sizeof(name)/sizeof(TCHAR);
::GetUserName(name,&nSize);
return CString(name);
}
const CString GetComputerName()
{
TCHAR name[MAX_PATH] = {0};
DWORD nSize = sizeof(name)/sizeof(TCHAR);
::GetComputerName(name,&nSize);
return CString(name);
}
// C
const CString GetSystemDrive()
{
CString strPath;
strPath = GetSystemDirectory();
int idx = strPath.Find(':');
ATLASSERT(idx != 0);
if(idx != 0)
{
strPath = strPath.Left(idx);
}
return strPath;
}
//////////////////////////////////////////////////////////////////////////////
// CComBSTR
CComBSTR operator+(CComBSTR& v1,CComBSTR& v2)
{
CComBSTR bstr = v1; bstr += v2; return bstr;
}
CComBSTR operator+(CString v1,CComBSTR& v2)
{
CComBSTR bstr = v1; bstr += v2; return bstr;
}
CComBSTR operator+(LPCSTR v1,CComBSTR& v2)
{
CComBSTR bstr = v1; bstr += v2; return bstr;
}
CComBSTR operator+(CComBSTR& v1,LPCSTR v2)
{
CComBSTR bstr = v1; bstr += v2; return bstr;
}
CComBSTR operator+(CComBSTR& v1,CString v2)
{
CComBSTR bstr = v1; bstr += CComBSTR(v2); return bstr;
}
//////////////////////////////////////////////////////////////////////////////
// GUID helper
void ProgIDFromCLSID(const CLSID& clsid,CComBSTR& comBSTR)
{
LPOLESTR bstr;
::ProgIDFromCLSID (clsid,&bstr);
comBSTR = CString(bstr);
CoTaskMemFree(bstr);
}
void StringFromCLSID(const CLSID& clsid,CComBSTR& comBSTR)
{
LPOLESTR bstr;
::StringFromCLSID (clsid,&bstr);
comBSTR = CString(bstr);
CoTaskMemFree(bstr);
}
void StringFromIID(const CLSID& clsid,CComBSTR& comBSTR)
{
LPOLESTR bstr;
::StringFromIID (clsid,&bstr);
comBSTR = CString(bstr);
CoTaskMemFree(bstr);
}
void CLSIDFromString(CComBSTR& comBSTR,CLSID& clsid)
{
LPOLESTR bstr;
comBSTR.CopyTo(&bstr);
::CLSIDFromString(bstr,&clsid);
::SysFreeString(bstr);
}
void IIDFromString(CComBSTR& comBSTR,CLSID& clsid)
{
LPOLESTR bstr;
comBSTR.CopyTo(&bstr);
::IIDFromString(bstr,&clsid);
::SysFreeString(bstr);
}
void CLSIDFromProgID(CComBSTR& comBSTR,CLSID& clsid)
{
LPOLESTR bstr;
comBSTR.CopyTo(&bstr);
::CLSIDFromProgID(bstr,&clsid);
::SysFreeString(bstr);
}
//////////////////////////////////////////////////////////////////////////////
// Notepad
void ShowInNotepad(const CString& strText)
{
CString strPathName = GetSystemDrive() + _T(":/Temp/SLText.txt");
ofstream file(strPathName);
CString str(strText);
str.Replace('\r',' ');
file << str;
file.close();
::WinExec("notepad.exe " + strPathName,true);
}
void ShowInNotepad(const CComBSTR& bstrText)
{
CString strText = bstrText;
ShowInNotepad(strText);
}
//////////////////////////////////////////////////////////////////////////////
// String Tokenaizer
CString GetNextToken(CString& strSrc, const CString strDelim)
{
CString token;
int idx = strSrc.FindOneOf(strDelim);
if(idx != -1)
{
token = strSrc.Left(idx);
strSrc = strSrc.Right(strSrc.GetLength() - (idx + 1) );
}
else
{
token = strSrc;
strSrc.Empty();
}
return token;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.