C++常用操作函数
载入动态库
bool LoadDll()
{
HttpDownDll = LoadLibrary("");
if(HttpDownDll == NULL)
{
MessageBox(0, "载?入?动ˉ态?库a错洙?误ó!?", "错洙?误ó", MB_OK|MB_ICONWARNING);
FreeLibrary(HttpDownDll);
return false;
}
SendCommand = (SendCommandFunc)GetProcAddress(HttpDownDll, "SendCommand");
if(SendCommand == NULL)
{
MessageBox(0, "GetProcAddress错洙?误ó!?", "错洙?误ó", MB_OK|MB_ICONWARNING);
FreeLibrary(HttpDownDll);
return false;
}
return true;
}
卸载动态库
bool FreeDll()
{
FreeLibrary(HttpDownDll);
SendCommand = NULL;
return true;
}
字符串分割
std::vector<std::string> split(std::string str,std::string pattern)
{
std::string::size_type pos;
std::vector<std::string> result;
str+=pattern; _access(const char *path,int mode)
mode的值:
00 是否存在
02 写权限
04 读权限
06 读写权限
*/
char l_SourceFile[256] = {0};
strcpy(l_SourceFile, ());
if(!_access(l_SourceFile,0))<<endl;
l_Result = 1;
}
}
return l_Result;
}
重命名文件
int RenameFileFunc(string v_SourceFile, string v_NewFileName)
{
int l_Result = 0;
char l_SourceFile[256] = {0};
char l_NewFileName[256] = {0};
strcpy(l_SourceFile, ());
strcpy(l_NewFileName, ());
if(!_access(l_SourceFile, 0))"<<newname<<" 已存在"<<endl
"<<newname<<" 正在使用,未关闭."<<endl
"<<"你没有权限重命名此文件."<<endl;
l_Result = 1;
}
}
else.
CloseHandle(hFile);
}
}
写文件
void Write(char * v_Path, char *v_Content, const int v_ContentSize)
{
HANDLE hFile = ::CreateFile(v_Path, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, NULL, NULL);
if (hFile != INVALID_HANDLE_VALUE)
{
.
CloseHandle(hFile);
}
}
查进程
BOOL FindProcess()
{
int i=0;
PROCESSENTRY32 pe32;
= sizeof(pe32);
HANDLE hProcessSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if(hProcessSnap == INVALID_HANDLE_VALUE)
{
i+=0;
}
BOOL bMore = ::Process32First(hProcessSnap, &pe32);
while(bMore)
{
");
hFind = FindFirstFile(l_FilePathName, &l_WFindData);
if (hFind == INVALID_HANDLE_VALUE)
{
dwSessionId = WTSGetActiveConsoleSessionId ();
do
{
WTSQueryUserToken( dwSessionId ,&hUserToken );
dwCreationFlags = NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE;
ZeroMemory( &si , sizeof( STARTUPINFO ) );
= sizeof( STARTUPINFO );
= "winsta0\\default" ;
ZeroMemory( &pi , sizeof( pi) );
TOKEN_PRIVILEGES tp ;
LUID luid ;
if( !::OpenProcessToken ( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY
| TOKEN_DUPLICATE | TOKEN_ASSIGN_PRIMARY | TOKEN_ADJUST_SESSIONID
| TOKEN_READ | TOKEN_WRITE , &hPToken ) )
{
dwRet = GetLastError ();
break;
}
else;
if ( !LookupPrivilegeValue ( NULL, SE_DEBUG_NAME, &luid ) )
{
dwRet = GetLastError ();
break;
}
else;
=1;
[0].Luid = luid;
[0].Attributes = SE_PRIVILEGE_ENABLED;
if( !DuplicateTokenEx ( hPToken, MAXIMUM_ALLOWED, NULL , SecurityIdentification , TokenPrimary, & hUserTokenDup ) )
{
dwRet = GetLastError ();
break;
}
else;
if( CreateProcessAsUser ( hUserTokenDup, //
if(dwResult == NO_ERROR)
{
l_Result = 0;
strcpy(l_ReturnBuffer, "Success");
LocalWriteLog(LOG_RUNFILE, "CancelConn||WNetAddConnection2", l_ReturnBuffer);
}
else
{
l_Result = -1;
GetLastErrMsg(l_ReturnBuffer);
LocalWriteLog(LOG_ERRFILE, "CancelConn||WNetAddConnection2", l_ReturnBuffer);
}
strcpy(v_ReturnBuffer, l_ReturnBuffer);
}
createprocessa catch(exception ex)
{
l_Result = -2;
strcpy(v_ReturnBuffer, ());
}
return l_Result;
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论