⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 generalutils.cpp

📁 COM编程接口处理方法 多个方法调用COM库函数
💻 CPP
字号:

#include "GeneralUtils.h"
#include "StdAfx.h"

// Function name	: isDirectory
// Description	    : determine if the specified path is a directory or not
// Return type		: bool (return true if the specified path is a directoy false if not)
bool IsDirectory(LPCTSTR path)
{
	TCHAR absPath[_MAX_PATH];
	::_tfullpath(absPath, path, _MAX_PATH);

	DWORD attr = ::GetFileAttributes(absPath);
	if (attr == 0xFFFFFFFF || !(attr & FILE_ATTRIBUTE_DIRECTORY))
		return false;   // does not exist or is not a directory
	else
		return true;
}

// Function name	: returnFileExtension
void ReturnFileExtension(LPCTSTR path, BSTR * extension)
{

	if (extension == NULL)
		return;

	TCHAR absPath[_MAX_PATH];
	TCHAR ext[_MAX_EXT];

	::_tfullpath(absPath, path, _MAX_PATH);
	::_tsplitpath(absPath, NULL, NULL, NULL, ext);
	SysReAllocString(extension, ext);
}

// Function name	: fileTypeExists
// Return type		: bool (true if file exists / false if not)
// Argument         : LPCTSTR dirpath (in format c:\temp)
// Argument         : LPCTSTR filter  (filter *.abc )
bool FileTypeExists(LPCTSTR dirpath, LPCTSTR filter)
{
	TCHAR path[_MAX_PATH];
	::_tcscpy(path, dirpath);

	// prepare to construct the filter.
	if (path[_tcslen(path) - 1] != _T('\\'))
	::_tcscat(path, TEXT("\\"));

	// append the filter
	::_tcscat(path, filter);

	// search
	HANDLE hSearch;
	WIN32_FIND_DATA findData;
	hSearch = ::FindFirstFile(path, &findData);

	if (hSearch == INVALID_HANDLE_VALUE)
		return false;

	::FindClose(hSearch);
	return true;
}


// Function name	: fileExists
// Description	    : Return the existance of a file
// Return type		: bool (TRUE if exists FALSE if not)
bool FileExists(LPCTSTR loc)
{
	return (::GetFileAttributes(loc) != -1);
}

// Function name	: returnFilesystemPath
void ReturnFilesystemPath(BSTR fileLoc, BSTR * path)
{

	USES_CONVERSION;
	
	TCHAR tDrive[_MAX_DRIVE];
	TCHAR tDir[_MAX_DIR]; 

	::_tsplitpath( OLE2T(fileLoc), tDrive, tDir, NULL, NULL);
 
	CComBSTR outPath(tDrive);
	outPath.Append(tDir);

	::SysReAllocString(path, outPath);

	return;
}

// Function name	: returnFile
void ReturnFile(BSTR loc, BSTR * fileName)
{

	USES_CONVERSION;

	TCHAR tFname[_MAX_FNAME];
	TCHAR tExt[_MAX_EXT];

	::_tsplitpath( OLE2T(loc), NULL, NULL, tFname, tExt);

	CComBSTR name(tFname);
	name.Append(tExt);
	
	::SysReAllocString(fileName, name);

	return;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -