Click here to Skip to main content
15,919,479 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Animation in MFC Pin
BlackDice8-Feb-05 3:24
BlackDice8-Feb-05 3:24 
GeneralRe: Animation in MFC Pin
Ryan Binns8-Feb-05 17:38
Ryan Binns8-Feb-05 17:38 
GeneralRe: Animation in MFC Pin
Member 14844969-Feb-05 20:36
Member 14844969-Feb-05 20:36 
GeneralRe: Animation in MFC Pin
Ryan Binns10-Feb-05 12:37
Ryan Binns10-Feb-05 12:37 
GeneralRe: Animation in MFC Pin
Member 148449610-Feb-05 18:26
Member 148449610-Feb-05 18:26 
GeneralPlease HELP Pin
Rassul Yunussov8-Feb-05 0:39
Rassul Yunussov8-Feb-05 0:39 
GeneralRe: Please HELP Pin
2249178-Feb-05 0:52
2249178-Feb-05 0:52 
GeneralRe: Please HELP Pin
Rassul Yunussov8-Feb-05 1:39
Rassul Yunussov8-Feb-05 1:39 
Thank you so MUCH!!! I feel my self so stupideSmile | :) , i worked with smart pointers a little time, and concentrate my attention on them, that's why i missed these...
In programm it works OK, no memory leaks, but i made a COM dll, and i got same problem - memory leaks!!!, and i delete all buffers!!!
Here is the code:

// MTServerImpl.cpp : Implementation of CMTServer

#include "stdafx.h"
#include "MTServerImpl.h"
#include ".\mtserverimpl.h"


// CMTServer

char PathToNomenOnPocket[] = "\\Program Files\\Mobile Terminal\\Data\\Nomen.dat";
char PathToAgentsOnPocket[] = "\\Program Files\\Mobile Terminal\\Data\\Agents.dat";
char PathToNaklOnPocket[] = "\\My Documents\\*.xml";
char PathToAgentCodeOnPocket[] = "\\Program Files\\Mobile Terminal\\Data\\MTExpeditor.mtc";
char PathToMyDocyments[] = "\\My Documents\\";
char PathToHistory[] = "\\Program Files\\Mobile Terminal\\Data\\History\\";
char PathToHistoryNakl[] = "\\Program Files\\Mobile Terminal\\Data\\History\\*.xml";

STDMETHODIMP CMTServer::ClearHistory(void)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());

	// TODO: Add your implementation code here
	CDialogProgress dlg;
	dlg.Create(CDialogProgress::IDD);
	dlg.CenterWindow();
	dlg.ShowWindow(SW_SHOW);
	
	// TODO: Add your implementation code here
	RAPIINIT ri = {sizeof(RAPIINIT)}; 
	HRESULT hRes = CeRapiInitEx(&ri);
	DWORD dwRet  = WaitForSingleObject(ri.heRapiInit,5000);
	if((dwRet!=WAIT_OBJECT_0)||!SUCCEEDED(ri.hrRapiInit))
	{
		//Could Not Initialize RAPI
		MessageBeep(MB_OK);
		::MessageBox(NULL,"Невозможно инициализировать Мобильный Терминал. Убедитесь В Том Что Он Соединен Через Active Sync","Ошибка",MB_ICONERROR);
	}
	else
	{
		WCHAR wsdata[512];
		WCHAR tempwsdata[512];

		MultiByteToWideChar(CP_ACP,0,PathToHistoryNakl,strlen(PathToHistoryNakl)+1,wsdata,sizeof(wsdata)/sizeof(wsdata[0]));
		LPCE_FIND_DATA FindData = NULL;
		DWORD Count;
		CeFindAllFiles(wsdata,FAF_ATTRIB_NO_HIDDEN|FAF_NAME,&Count,&FindData);
		MultiByteToWideChar(CP_ACP,0,PathToHistory,strlen(PathToHistory)+1,wsdata,sizeof(wsdata)/sizeof(wsdata[0]));

		StrCpyW(tempwsdata,wsdata); 
		dlg.m_Progress.SetRange32(0,Count);
		dlg.m_Progress.SetStep(1);
		for(int i = 0;i<Count;i++)
		{

			StrCatW(wsdata,FindData[i].cFileName);
			if(!CeDeleteFile(wsdata))
				MessageBox(NULL,"Невозможно удалить файл","Ошибка Удаления Файла",MB_ICONERROR);
			StrCpyW(wsdata,tempwsdata);
			dlg.m_Progress.StepIt();
		}
		if(CeRapiFreeBuffer(FindData)==E_FAIL)
		{
			MessageBox(NULL,"Невозможно очистить память","Ошибка Очистки Памяти",MB_ICONINFORMATION);
		}
	}
	CeRapiUninit();	
	dlg.ShowWindow(SW_HIDE);
	dlg.DestroyWindow();
	return S_OK;
}

STDMETHODIMP CMTServer::ExportAgents(BSTR PathToAgents)
{
	// TODO: Add your implementation code here
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	CDialogProgress dlg;
	dlg.Create(CDialogProgress::IDD);
	dlg.CenterWindow();
	dlg.ShowWindow(SW_SHOW);
	
	dlg.m_Progress.SetRange32(0,30);
	dlg.m_Progress.SetStep(10);
	RAPIINIT ri = {sizeof(RAPIINIT)}; 
	HRESULT hRes = CeRapiInitEx(&ri);
	DWORD dwRet  = WaitForSingleObject(ri.heRapiInit,5000);
	if((dwRet!=WAIT_OBJECT_0)||!SUCCEEDED(ri.hrRapiInit))
	{
		//Could Not Initialize RAPI
		MessageBeep(MB_OK);
		::MessageBox(NULL,"Не возможно инициализировать Мобильный Терминал. Убедитесь В Том Что Он Соединен Через Active Sync","Ошибка",MB_ICONERROR);
	}
	else
	{
		//	_bstr_t bstrFileName;
		//bstrFileName = m_PathToAgents.AllocSysString();
		variant_t vResult;
		vResult = m_plDomDocument->load(PathToAgents);
		if(((bool)vResult)==TRUE)
		{
			char Razdelitel = '?';
			m_File = CreateFile(m_MainPath+"Agents.dat",GENERIC_READ|GENERIC_WRITE,NULL,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
			//m_File.Open("Agents.dat",CFile::modeCreate|CFile::modeWrite);
			m_plDocRoot = m_plDomDocument->documentElement;
			//Zapisat shapku
			//	Pervii Bait - Kol-vo kolonok;
			//	Vtoroi Bait - dlinna stroki kolonok;
			//	Naimenovania kolonok cherez "?"
			//	Posle kolonok - "."
			//	Dalee dannie cherez "#"	
			//Zapisat Shapku
			MSXML::IXMLDOMNodePtr pDocRoot = m_plDomDocument->documentElement;
			CreateHeadForAgents(pDocRoot);
			int Size = m_vHeadForAgents.size();
			DWORD red;
			WriteFile(m_File,&Size,sizeof(int),&red,NULL);
			//m_File.Write(&Size,sizeof(int));
			Size--;
			for(int i = 0;i<m_vHeadForAgents.size();i++)
				Size+=m_vHeadForAgents[i].GetLength();
			WriteFile(m_File,&Size,sizeof(int),&red,NULL);
			//m_File.Write(&Size,sizeof(int));
			for(i = 0;i<m_vHeadForAgents.size();i++)
			{
				WriteFile(m_File,m_vHeadForAgents[i],m_vHeadForAgents[i].GetLength(),&red,NULL);
				//m_File.Write(m_vHeadForAgents[i],m_vHeadForAgents[i].GetLength());
				if(i<m_vHeadForAgents.size()-1)
					WriteFile(m_File,&Razdelitel,1,&red,NULL);
				//m_File.Write(&Razdelitel,1);
			}
			//~Zapisat shapku
			dlg.m_Progress.StepIt();
			m_vHead.clear();
			Razdelitel = '.';
			WriteFile(m_File,&Razdelitel,1,&red,NULL);
			//m_File.Write(&Razdelitel,1);


			GetChildForAgents(m_plDocRoot);
			dlg.m_Progress.StepIt();
			//Perepisat vse na Pocket PC
			//m_File.Close();
			CloseHandle(m_File);
			m_File = CreateFile(m_MainPath+"Agents.dat",GENERIC_READ,NULL,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
			//m_File.Open("Agents.dat",CFile::modeRead);
			DWORD HIGH;
			int FileSize;
			FileSize = GetFileSize(m_File,&HIGH);
			char* buffer = new char[FileSize];
			//m_File.Read(buffer,m_File.GetLength());
			ReadFile(m_File,buffer,FileSize,&red,NULL);
			WCHAR wsdata[256];
			MultiByteToWideChar(CP_ACP,0,PathToAgentsOnPocket,strlen(PathToAgentsOnPocket)+1,wsdata,sizeof(wsdata)/sizeof(wsdata[0]));
			HANDLE hFile = CeCreateFile(wsdata,GENERIC_READ|GENERIC_WRITE,NULL,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
			if(hFile==INVALID_HANDLE_VALUE)
			{
				MessageBox(NULL,"Невозможно создать файл","Ошибка Мобильного терминала",MB_ICONERROR);
				return FALSE;
			}
			DWORD Bytes;
			CeWriteFile(hFile,buffer,FileSize,&Bytes,NULL);
			CeCloseHandle(hFile);
			CloseHandle(m_File);
			//m_File.Close();
			DeleteFile(m_MainPath+"Agents.dat");
			delete [] buffer;
			dlg.m_Progress.StepIt();
			//~Perepisat vse na Pocket PC
		}
	}
	CeRapiUninit();
	dlg.ShowWindow(SW_HIDE);
	dlg.DestroyWindow();
	return S_OK;
}
void CMTServer::GetChildForAgents(MSXML::IXMLDOMNodePtr pParent)
{

	MSXML::IXMLDOMNamedNodeMapPtr pNamedNodeMapPtr =NULL;
	MSXML::IXMLDOMNodePtr pXMLAttrNode = NULL;
	long AttributesNumber = 0;
	CString AttrName;

	HRESULT hResult = pParent->get_attributes(&pNamedNodeMapPtr);
	if(FAILED(hResult))
	{
		::MessageBox(NULL,"Ошибка получения атрибута","Ошибка XML",MB_ICONERROR);
		return;
	}

	pNamedNodeMapPtr->get_length(&AttributesNumber);
	char Razdelitel = '#';
	for(int i = 0;i<AttributesNumber;i++)
	{
		pNamedNodeMapPtr->get_item(i,&pXMLAttrNode);
		VARIANT var;
		pXMLAttrNode->get_nodeValue(&var);
		CString str =(CString) var.bstrVal;
		if(str=="")
			str=" ";
		str.Replace('#','-');
		DWORD red;
		WriteFile(m_File,str,str.GetLength(),&red,NULL);
		WriteFile(m_File,&Razdelitel,1,&red,NULL);
		//m_File.Write(str,str.GetLength());
		//m_File.Write(&Razdelitel,1);
	}
	for(MSXML::IXMLDOMNodePtr pChild = pParent->firstChild;NULL!=pChild;pChild=pChild->nextSibling)
	{
		GetChildForAgents(pChild);
	}
}
void CMTServer::GetChild(MSXML::IXMLDOMNodePtr pParent,CString FullPath = "")
{
	MSXML::IXMLDOMNamedNodeMapPtr pNamedNodeMapPtr =NULL;
	MSXML::IXMLDOMNodePtr pXMLAttrNode = NULL;
	long AttributesNumber = 0;
	CString AttrName;

	HRESULT hResult = pParent->get_attributes(&pNamedNodeMapPtr);
	if(FAILED(hResult))
	{
		::MessageBox(NULL,"Ошибка получения атрибута","Ошибка XML",MB_ICONERROR);
		return;
	}

	pNamedNodeMapPtr->get_length(&AttributesNumber);
	char Razdelitel = '#';
	for(int i = 0;i<AttributesNumber;i++)
	{
		pNamedNodeMapPtr->get_item(i,&pXMLAttrNode);
		CString str((LPCTSTR)pXMLAttrNode->nodeName);
		if(str=="Группа")
		{
			VARIANT var;
			pXMLAttrNode->get_nodeValue(&var);
			FullPath += (CString)var.bstrVal+"\\";
		}
		else
		{
			DWORD red;
			if(!i)
			{
				WriteFile(m_File,FullPath,FullPath.GetLength(),&red,NULL);
				WriteFile(m_File,&Razdelitel,1,&red,NULL);
				//m_File.Write(FullPath,FullPath.GetLength());
				//m_File.Write(&Razdelitel,1);
			}
			VARIANT var;
			pXMLAttrNode->get_nodeValue(&var);
			CString str = (CString)var.bstrVal;
			if(str=="")
				str = " ";
			str.Replace('#','-');
			WriteFile(m_File,str,str.GetLength(),&red,NULL);
			WriteFile(m_File,&Razdelitel,1,&red,NULL);
			//m_File.Write(str,str.GetLength());
			//m_File.Write(&Razdelitel,1);
		}
	}
	for(MSXML::IXMLDOMNodePtr pChild = pParent->firstChild;NULL!=pChild;pChild=pChild->nextSibling)
	{
		GetChild(pChild,FullPath);
	}
}
int CMTServer::CreateHeadForAgents(MSXML::IXMLDOMNodePtr pParent)
{
	MSXML::IXMLDOMNamedNodeMapPtr pNamedNodeMapPtr =NULL;
	MSXML::IXMLDOMNodePtr pXMLAttrNode = NULL;
	long AttributesNumber = 0;

	HRESULT hResult = pParent->get_attributes(&pNamedNodeMapPtr);
	if(FAILED(hResult))
	{
		::MessageBox(NULL,"Ошибка получения атрибута","Ошибка XML",MB_ICONERROR);
		return 1;
	}

	pNamedNodeMapPtr->get_length(&AttributesNumber);
	for(int i = 0;i<AttributesNumber;i++)
	{
		pNamedNodeMapPtr->get_item(i,&pXMLAttrNode);
		for(int j = 0;j<AttributesNumber;j++)
		{
			pNamedNodeMapPtr->get_item(j,&pXMLAttrNode);
			CString str((LPCTSTR)pXMLAttrNode->nodeName);
			m_vHeadForAgents.push_back(str);
		}
		return 1;
		break;
	}
	for(MSXML::IXMLDOMNodePtr pChild = pParent->firstChild;NULL!=pChild;pChild=pChild->nextSibling)
	{
		if(CreateHeadForAgents(pChild)==1)
			return 1;
	}
	return 0;
}
int CMTServer::CreateHead(MSXML::IXMLDOMNodePtr pParent)
{
	MSXML::IXMLDOMNamedNodeMapPtr pNamedNodeMapPtr =NULL;
	MSXML::IXMLDOMNodePtr pXMLAttrNode = NULL;
	long AttributesNumber = 0;

	HRESULT hResult = pParent->get_attributes(&pNamedNodeMapPtr);
	if(FAILED(hResult))
	{
		::MessageBox(NULL,"Ошибка получения атрибута","Ошибка XML",MB_ICONERROR);
		return 1;
	}

	pNamedNodeMapPtr->get_length(&AttributesNumber);
	for(int i = 0;i<AttributesNumber;i++)
	{
		pNamedNodeMapPtr->get_item(i,&pXMLAttrNode);
		CString str((LPCTSTR)pXMLAttrNode->nodeName);
		if(str!="Группа")
		{
			for(int j = 0;j<AttributesNumber;j++)
		 {
			 pNamedNodeMapPtr->get_item(j,&pXMLAttrNode);
			 CString str((LPCTSTR)pXMLAttrNode->nodeName);
			 m_vHead.push_back(str);
		 }
		 return 1;
		}
		break;
	}
	for(MSXML::IXMLDOMNodePtr pChild = pParent->firstChild;NULL!=pChild;pChild=pChild->nextSibling)
	{
		if(CreateHead(pChild)==1)
			return 1;
	}
	return 0;
}
STDMETHODIMP CMTServer::ExportNomen(BSTR PathToNomen)
{
	// TODO: Add your implementation code here
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	CDialogProgress dlg;
	dlg.Create(CDialogProgress::IDD);
	dlg.CenterWindow();
	dlg.ShowWindow(SW_SHOW);
	
	dlg.m_Progress.SetRange32(0,30);
	dlg.m_Progress.SetStep(10);
	RAPIINIT ri = {sizeof(RAPIINIT)}; 
	HRESULT hRes = CeRapiInitEx(&ri);
	DWORD dwRet  = WaitForSingleObject(ri.heRapiInit,5000);
	if((dwRet!=WAIT_OBJECT_0)||!SUCCEEDED(ri.hrRapiInit))
	{
		//Could Not Initialize RAPI
		MessageBeep(MB_OK);
		::MessageBox(NULL,"Не возможно инициализировать Мобильный Терминал. Убедитесь В Том Что Он Соединен Через Active Sync","Ошибка",MB_ICONERROR);
	}
	else
	{
		//_bstr_t bstrFileName;
		//bstrFileName = m_PathToNomen.AllocSysString();
		variant_t vResult;
		vResult = m_plDomDocument->load(PathToNomen);
		if(((bool)vResult)==TRUE)
		{
			char Razdelitel = '?';
			m_File = CreateFile(m_MainPath+"Nomen.dat",GENERIC_READ|GENERIC_WRITE,NULL,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);

			//m_File.Open("Nomen.dat",CFile::modeCreate|CFile::modeWrite);
			m_plDocRoot = m_plDomDocument->documentElement;
			//Zapisat shapku
			//	Pervii Bait - Kol-vo kolonok;
			//	Vtoroi Bait - dlinna stroki kolonok;
			//	Naimenovania kolonok cherez "?"
			//	Posle kolonok - "."
			//	Dalee dannie cherez "#"	
			MSXML::IXMLDOMNodePtr pDocRoot = m_plDomDocument->documentElement;
			m_vHead.push_back(CString("Путь"));
			CreateHead(pDocRoot);
			int Size = m_vHead.size();
			DWORD red;
			WriteFile(m_File,&Size,sizeof(int),&red,NULL);
			//m_File.Write(&Size,sizeof(int));
			Size--;
			for(int i = 0;i<m_vHead.size();i++)
				Size+=m_vHead[i].GetLength();
			WriteFile(m_File,&Size,sizeof(int),&red,NULL);
			//m_File.Write(&Size,sizeof(int));
			for(i = 0;i<m_vHead.size();i++)
			{
				WriteFile(m_File,m_vHead[i],m_vHead[i].GetLength(),&red,NULL);
				//m_File.Write(m_vHead[i],m_vHead[i].GetLength());
				if(i<m_vHead.size()-1)
					WriteFile(m_File,&Razdelitel,1,&red,NULL);
				//m_File.Write(&Razdelitel,1);
			}
			//~Zapisat shapku
			dlg.m_Progress.StepIt();
			m_vHead.clear();
			Razdelitel = '.';
			WriteFile(m_File,&Razdelitel,1,&red,NULL);
			//m_File.Write(&Razdelitel,1);
			//Zapisat Dannie
			GetChild(m_plDocRoot);
			dlg.m_Progress.StepIt();
			//Perepisat vse na Pocket PC
			//m_File.Close();
			CloseHandle(m_File);
			m_File = CreateFile(m_MainPath+"Nomen.dat",GENERIC_READ,NULL,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
			//m_File.Open("Nomen.dat",CFile::modeRead);
			DWORD HIGH;
			int FileSize;
			FileSize = GetFileSize(m_File,&HIGH);
			char* buffer = new char[FileSize];
			ReadFile(m_File,buffer,FileSize,&red,NULL);
			//m_File.Read(buffer,m_File.GetLength());
			WCHAR wsdata[256];
			MultiByteToWideChar(CP_ACP,0,PathToNomenOnPocket,strlen(PathToNomenOnPocket)+1,wsdata,sizeof(wsdata)/sizeof(wsdata[0]));
			HANDLE hFile = CeCreateFile(wsdata,GENERIC_READ|GENERIC_WRITE,NULL,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
			if(hFile==INVALID_HANDLE_VALUE)
			{
				MessageBox(NULL,"Невозможно создать файл","Ошибка Мобильного терминала",MB_ICONERROR);
			}
			DWORD Bytes;
			CeWriteFile(hFile,buffer,FileSize,&Bytes,NULL);
			CeCloseHandle(hFile);
			CloseHandle(m_File);
			//m_File.Close();
			DeleteFile(m_MainPath+"Nomen.dat");
			delete [] buffer;
			dlg.m_Progress.StepIt();
			//~Perepisat vse na Pocket PC
		}
		else
		{
			::MessageBox(NULL,"Невозможно загрузить файл XML","Ошибка XML",MB_ICONERROR);
		}
	}
	CeRapiUninit();
	dlg.ShowWindow(SW_HIDE);
	dlg.DestroyWindow();
	return S_OK;
}

STDMETHODIMP CMTServer::ImportNaklad(BSTR PathToNaklad)
{
	// TODO: Add your implementation code here

	AFX_MANAGE_STATE(AfxGetStaticModuleState());


	RAPIINIT ri = {sizeof(RAPIINIT)}; 
	HRESULT hRes = CeRapiInitEx(&ri);
	DWORD dwRet  = WaitForSingleObject(ri.heRapiInit,5000);
	if((dwRet!=WAIT_OBJECT_0)||!SUCCEEDED(ri.hrRapiInit))
	{
		//Could Not Initialize RAPI
		MessageBeep(MB_OK);
		::MessageBox(NULL,"Не возможно инициализировать Мобильный Терминал. Убедитесь В Том Что Он Соединен Через Active Sync","Ошибка",MB_ICONERROR);
	}
	else
	{
		HANDLE file;
		char* XMLHEAD = "<?xml version=\"1.0\" encoding=\"windows-1251\"?><НАКЛАДНАЯ>";
		char* XMLEND = "</НАКЛАДНАЯ>";


		WCHAR wsdata[256];
		WCHAR tempwsdata[256];

		MultiByteToWideChar(CP_ACP,0,PathToNaklOnPocket,strlen(PathToNaklOnPocket)+1,wsdata,sizeof(wsdata)/sizeof(wsdata[0]));
		LPCE_FIND_DATA FindData = NULL;
		DWORD Count;

	
		//CeFindAllFiles(wsdata,FAF_ATTRIB_NO_HIDDEN,lplpFindData);
		CeFindAllFiles(wsdata,FAF_ATTRIB_NO_HIDDEN|FAF_NAME,&Count,&FindData);
		MultiByteToWideChar(CP_ACP,0,PathToMyDocyments,strlen(PathToMyDocyments)+1,wsdata,sizeof(wsdata)/sizeof(wsdata[0]));

		StrCpyW(tempwsdata,wsdata);

		
		if(Count==0)
		{
			MessageBox(NULL,"Мобильный терминал пуст","Информация",MB_ICONINFORMATION);
			return S_OK;
		}	

		CDialogProgress dlg;
		dlg.Create(CDialogProgress::IDD);
		dlg.CenterWindow();
		dlg.ShowWindow(SW_SHOW);
		dlg.m_Progress.SetRange(0,Count*10);
		dlg.m_Progress.SetStep(10);
		//CFileException fe;
		file = CreateFile(m_PathToNaklad,GENERIC_READ|GENERIC_WRITE,NULL,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
		//file.Open(m_PathToNaklad,CFile::modeCreate|CFile::modeWrite,&fe);
		DWORD red;
		WriteFile(file,XMLHEAD,strlen(XMLHEAD),&red,NULL);
		//file.Write(XMLHEAD,strlen(XMLHEAD));
		for(int i = 0;i<Count;i++)
		{
			StrCatW(wsdata,FindData[i].cFileName);

			HANDLE hFileTemp = CeCreateFile(wsdata,GENERIC_READ,NULL,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_READONLY,NULL);

			if(hFileTemp==INVALID_HANDLE_VALUE)
			{
				MessageBox(NULL,"Невозможно открыть файл","Ошибка Мобильного Терминала",MB_ICONINFORMATION);
				//return FALSE;
			}

			DWORD HIGH;
			int Size = CeGetFileSize(hFileTemp,&HIGH);
			if(Size>45)
			{
				char* ldata = new char[Size-45];
				LARGE_INTEGER li;
				li.QuadPart = 45;
				li.LowPart = CeSetFilePointer(hFileTemp,li.LowPart,&li.HighPart,FILE_BEGIN);
				CeReadFile(hFileTemp,ldata,Size-45,&HIGH,NULL);
				WriteFile(file,ldata,Size-45,&red,NULL);
				//file.Write(data,Size-45);
				CeCloseHandle(hFileTemp);
				delete [] ldata;

			}
			//Skopirovat v History
			WCHAR HistoryPath[512]; 
			MultiByteToWideChar(CP_ACP,0,PathToHistory,strlen(PathToHistory)+1,HistoryPath,sizeof(HistoryPath)/sizeof(HistoryPath[0]));
			CeCopyFile(wsdata,StrCatW(HistoryPath,FindData[i].cFileName),FALSE);
			//~Skopirovat v History
			if(!CeDeleteFile(wsdata))
				MessageBox(NULL,"Невозможно удалить файл с мобильного терминала","Ошибка мобильного терминала",MB_ICONERROR);
			StrCpyW(wsdata,tempwsdata);
			//ProgressCtrl->StepIt();
			dlg.m_Progress.StepIt();
		}
		WriteFile(file,XMLEND,strlen(XMLEND),&red,NULL);
		CloseHandle(file);
		//file.Write(XMLEND,strlen(XMLEND));
		//file.Close();
		if(CeRapiFreeBuffer(FindData)==E_FAIL)
		{
			MessageBox(NULL,"Невозможно очистить память","Ошибка очистки памяти",MB_ICONINFORMATION);
		};
		dlg.ShowWindow(SW_HIDE);
		dlg.DestroyWindow();
	}
	CeRapiUninit();
	return S_OK;
}

STDMETHODIMP CMTServer::SetTempPath(BSTR TempPath)
{
	// TODO: Add your implementation code here
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	m_MainPath = (CString) TempPath;
	return S_OK;
}

STDMETHODIMP CMTServer::GetAgentCode(BSTR* AgentCode)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	RAPIINIT ri = {sizeof(RAPIINIT)}; 
	HRESULT hRes = CeRapiInitEx(&ri);
	DWORD dwRet  = WaitForSingleObject(ri.heRapiInit,5000);
	if((dwRet!=WAIT_OBJECT_0)||!SUCCEEDED(ri.hrRapiInit))
	{
		//Could Not Initialize RAPI
		MessageBeep(MB_OK);
		::MessageBox(NULL,"Не возможно инициализировать Мобильный Терминал. Убедитесь В Том Что Он Соединен Через Active Sync","Ошибка",MB_ICONERROR);
	}
	else
	{
	// TODO: Add your implementation code here
		WCHAR wsdata[256];
		DWORD HIGH;

		MultiByteToWideChar(CP_ACP,0,PathToAgentCodeOnPocket,strlen(PathToAgentCodeOnPocket)+1,wsdata,sizeof(wsdata)/sizeof(wsdata[0]));

		HANDLE hFileTemp = CeCreateFile(wsdata,GENERIC_READ,NULL,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_READONLY,NULL);	
		int Size = CeGetFileSize(hFileTemp,&HIGH);
		char* data = new char[Size+1];
		data[Size] = 0;

		CeReadFile(hFileTemp,data,Size,&HIGH,NULL);

		CString str = data;
		delete []data;
		CeCloseHandle(hFileTemp);
		*AgentCode = str.AllocSysString();
	}
	CeRapiUninit();
	return S_OK;
}

GeneralRe: Please HELP Pin
2249178-Feb-05 17:03
2249178-Feb-05 17:03 
GeneralRe: Please HELP Pin
Rassul Yunussov8-Feb-05 18:24
Rassul Yunussov8-Feb-05 18:24 
GeneralRe: Please HELP Pin
Rassul Yunussov8-Feb-05 1:42
Rassul Yunussov8-Feb-05 1:42 
GeneralLocale Problem........... Pin
nutkase8-Feb-05 0:03
nutkase8-Feb-05 0:03 
GeneralRe: Locale Problem........... Pin
David Crow8-Feb-05 2:55
David Crow8-Feb-05 2:55 
Generalencryption and decryption in vc++ Pin
shaans7-Feb-05 23:20
shaans7-Feb-05 23:20 
GeneralRe: encryption and decryption in vc++ Pin
shiraztk8-Feb-05 0:15
shiraztk8-Feb-05 0:15 
GeneralRe: encryption and decryption in vc++ Pin
namaskaaram8-Feb-05 0:58
namaskaaram8-Feb-05 0:58 
QuestionHow to define size for CTreeView's branches Pin
bilas7-Feb-05 23:14
bilas7-Feb-05 23:14 
AnswerRe: How to define size for CTreeView's branches Pin
Fred D.8-Feb-05 0:05
Fred D.8-Feb-05 0:05 
GeneralRe: How to define size for CTreeView's branches Pin
bilas8-Feb-05 3:55
bilas8-Feb-05 3:55 
Questionhow power point slids integrate with vc++ MFC diloge? Pin
syed abbdul qavi7-Feb-05 23:11
syed abbdul qavi7-Feb-05 23:11 
AnswerRe: how power point slids integrate with vc++ MFC diloge? Pin
David Crow8-Feb-05 2:56
David Crow8-Feb-05 2:56 
GeneralHitting allmenu items of an launched application Pin
Vaibhav Sanghavi7-Feb-05 23:03
Vaibhav Sanghavi7-Feb-05 23:03 
QuestionHow to find that Machine is on LAN Pin
RuchirD7-Feb-05 22:19
RuchirD7-Feb-05 22:19 
AnswerRe: How to find that Machine is on LAN Pin
2249177-Feb-05 22:29
2249177-Feb-05 22:29 
GeneralRe: How to find that Machine is on LAN Pin
RuchirD8-Feb-05 17:11
RuchirD8-Feb-05 17:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.