|
Hi,
Im working with the AVI Files for a project which records real time video and audio. I was wondering if there is something that could help me to determine the health of Mic and Camera, without actually looking at the Video or listening to the Audio.
(May be I can parse through the AVI file for header chunks or Data chunks, but I am not sure about what I should be looking for )
Thanks!
Abilash G. Sanam
|
|
|
|
|
I have an unmanaged C++ application and want to use managed C# forms. Converting the code to managed code and rewriting in C# are not options. Somehow I think that the CComPtr is a key but am not sure how to use it. Can anyone help?
-Erik
|
|
|
|
|
I guess you can make a COM wrapper for your C# forms and then use them from unmanaged C++.
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
How can I set specific color for my window (toolbar)?
Thanks a lot in advance, bilas.
|
|
|
|
|
Is it possible to add icons to the resource file dynamicly? What I would like to do is to allow the user to paint his own icons, name them using some given convention, and use them as icons in a CTreeCtrl. the reason I want to do that is because I don't want to have to recompile my program for each set of icons (and for each user.)
In Java, I could do that easely, using the ImageIcon class. All you need is a URL for where the image is located. I can call the ImageIcon(URL location) constructor, and then use my icon anywhere I want. Is there any way to achieve something like that in VC++?
Thanks for your help,
/Uzi
|
|
|
|
|
hey,
If you mean select icons from directory you can try out this:
//get all icons in a directory
WIN32_FIND_DATA DataFind;
char SearchValue[MAX_PATH];
strcpy(SearchValue, W2A(DirectoryPath));
if (SearchValue[strlen(SearchValue)-1] != '\\' && SearchValue[strlen(SearchValue)-1] != '/')
strcat(SearchValue, "\\");
strcat(SearchValue, "*.ico");
// start file listing
HANDLE hFile = FindFirstFile(SearchValue, &DataFind);
if (hFile == INVALID_HANDLE_VALUE)
return 0;
CComBSTR Filename;
do
{
if (!(DataFind.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
Filename.AppendBSTR(DirectoryPath);
Filename.Append(A2W(DataFind.cFileName));
HICON icon = (HICON) LoadImage(NULL, W2A(Filename),IMAGE_ICON,16,16,LR_LOADFROMFILE);
if(icon != NULL)
{
m_ImageList.AddIcon(icon);
index++;
}
}
}while(FindNextFile(hFile, &DataFind));
FindClose(hFile);
|
|
|
|
|
i am poor in english.... plz tyr to understand.. thanks
hai all,
i Create an arrow Control, i add this control to the web page , i used a logic to draw an arrow as mouse down starting drawing,and mouse up for ending of line i place the arrow tip at ending point.
but in design time i failed to draw exactly what i need.
because i want exactly the windows vb line control...
but any third party tool will take more edge points..
any one tried to get two points at design time..
plz help me, i wrote in vc++6.0 and i am trying to export to vc++7.0 .. so plz help me ...
surya.. .
|
|
|
|
|
I have been trying to track dowm the memoru leaks reported when my application ends;
Detected memory leaks!
Dumping objects ->
thrdcore.cpp(311) : {1254} client block at 0x01954958, subtype c0, 68 bytes long.
a CWinThread object at $01954958, 68 bytes long
Object dump complete.
The program '[1564] My_Example.exe: Native' has exited with code 20 (0x14).
I have included the following statements to help track down the leaks:-
Inserted in the main .cpp file
// Memory leak detection
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#include ".\ssic_exampledlg.h"
// End of Memoy Leak detection stuff
Inserted on the Close event
// Determine where the memory leaks are
_CrtDumpMemoryLeaks();
But cant seem to determine the cause of the leaks!
Any suggestions?
|
|
|
|
|
|
In this SPECIFIC case, you are not deleting the CWinThread object that has been returned by your call to AfxBeginThread or otherwise. In many cases, the CWinThread object does not delete itself when the thread terminates, although you can set a member variable so that it will do so.
It is better to detect that the thread has terminated and then delete the CWinThread object from your program's main thread.
If you don't want to bother tracking the object, then
CWinThread::m_bAutoDelete<br />
Specifies whether the CWinThread object should be automatically deleted at thread termination.
set the member variable TRUE after the call to AfxBeginThread, and hopefully the thread does not terminate before you can set the member, otherwise, create the thread suspended, set the member variable, then resume the thread.
AfxBeginThread - dwCreateFlags <br />
Specifies an additional flag that controls the creation of the thread. This flag can contain one of two values: <br />
CREATE_SUSPENDED Start the thread with a suspend count of one. Use CREATE_SUSPENDED if you want to initialize any member data of the CWinThread object, such as m_bAutoDelete or any members of your derived class, before the thread starts running. Once your initialization is complete, use CWinThread::ResumeThread to start the thread running. The thread will not execute until CWinThread::ResumeThread is called.
|
|
|
|
|
Hi,
I am trying to display a 12-bit TIFF image in an MFC application. How can I do this? I tried using SetDIBitsToDevice(), but it takes a bitmap header structure as input, and the bitmap header structure does not support 12-bit images. Can anyone help me out?
Thanks,
Ajay
|
|
|
|
|
I would look at the CxImage[^] article here on codeproject. That loads in and displays Tiffs, Jpegs, etc.
Iain.
|
|
|
|
|
Thanks!! I already have CXImage, but it does not support 12-bit TIFF images.
Any idea how to display them?
Thanks,
Ajay
|
|
|
|
|
Sorry. As CxImage uses another libary to load tiffs, you might want to see if that
tifflib works with 12bit tiffa. Then you may be able to work with that. But that is
the end of my limited idea.
Iain.
|
|
|
|
|
Hi am an MFC newbie and am getting problems into displaying an animation in an MFC MDI window. The problem is that i have loaded a 3ds model into it and i want to move it when either the computer is idle or when a user activate a button. Please help!!
|
|
|
|
|
|
BlackDice wrote:
isn't there a message for Onidle()?
Uhh no. OnIdle() is called whenever there isn't a message...
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
So any suggestion about how to proceed?
|
|
|
|
|
Sorry, I don't know much about animation
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
|
I got a programm, that works with xml files. And it uses MSXML.dll. But i found i greate memory leak, and i can't understand - what am i doing wrong???
Here is the code:
#pragma once
#include <vector>
#import <msxml.dll> named_guids
using namespace MSXML;
using namespace std;
class CNakladImporter
{
vector <CString> m_vHead;
vector <CString> m_vHeadForAgents;
CFile m_File;
CString m_PathToNomen;
CString m_PathToAgents;
CString m_PathToNaklad;
MSXML::IXMLDOMDocumentPtr m_plDomDocument;
MSXML::IXMLDOMElementPtr m_plDocRoot;
void GetChild(MSXML::IXMLDOMNodePtr pParent,CString FullPath);
void GetChildForAgents(MSXML::IXMLDOMNodePtr pParent);
int CreateHead(MSXML::IXMLDOMNodePtr pParent);
int CreateHeadForAgents(MSXML::IXMLDOMNodePtr pParent);
public:
CNakladImporter(void);
void SetPathToNomen(CString Path);
void SetPathToAgents(CString Path);
void SetPathToNaklad(CString Path);
BOOL ExportAgents(CProgressCtrl* ProgressCtrl);
BOOL ExportNomen(CProgressCtrl* ProgressCtrl);
BOOL ImportNaklad(CProgressCtrl* ProgressCtrl);
void ClearHistory();
~CNakladImporter(void);
bool InitXML(void);
};
and implementation
#include "StdAfx.h"
#include "nakladimporter.h"
char PathToNomenOnPocket[] = "\\Program Files\\Mobile Terminal\\Data\\Nomen.dat";
char PathToAgentsOnPocket[] = "\\Program Files\\Mobile Terminal\\Data\\Agents.dat";
char PathToNaklOnPocket[] = "\\My Documents\\*.xml";
char PathToMyDocyments[] = "\\My Documents\\";
char PathToHistory[] = "\\Program Files\\Mobile Terminal\\Data\\History\\";
char PathToHistoryNakl[] = "\\Program Files\\Mobile Terminal\\Data\\History\\*.xml";
CNakladImporter::CNakladImporter(void)
{
}
CNakladImporter::~CNakladImporter(void)
{
}
void CNakladImporter::SetPathToNomen(CString Path)
{
m_PathToNomen = Path;
}
void CNakladImporter::SetPathToAgents(CString Path)
{
m_PathToAgents = Path;
}
void CNakladImporter::SetPathToNaklad(CString Path)
{
m_PathToNaklad = Path;
}
BOOL CNakladImporter::ExportAgents(CProgressCtrl* ProgressCtrl)
{
_bstr_t bstrFileName;
bstrFileName = m_PathToAgents.AllocSysString();
variant_t vResult;
vResult = m_plDomDocument->load(bstrFileName);
if(((bool)vResult)==TRUE)
{
ProgressCtrl->SetRange(0,30);
ProgressCtrl->SetStep(10);
char Razdelitel = '?';
m_File.Open("Agents.dat",CFile::modeCreate|CFile::modeWrite);
m_plDocRoot = m_plDomDocument->documentElement;
MSXML::IXMLDOMNodePtr pDocRoot = m_plDomDocument->documentElement;
CreateHeadForAgents(pDocRoot);
int Size = m_vHeadForAgents.size();
m_File.Write(&Size,sizeof(int));
Size--;
for(int i = 0;i<m_vHeadForAgents.size();i++)
Size+=m_vHeadForAgents[i].GetLength();
m_File.Write(&Size,sizeof(int));
for(i = 0;i<m_vHeadForAgents.size();i++)
{
m_File.Write(m_vHeadForAgents[i],m_vHeadForAgents[i].GetLength());
if(i<m_vHeadForAgents.size()-1)
m_File.Write(&Razdelitel,1);
}
ProgressCtrl->StepIt();
m_vHead.clear();
Razdelitel = '.';
m_File.Write(&Razdelitel,1);
GetChildForAgents(m_plDocRoot);
ProgressCtrl->StepIt();
m_File.Close();
m_File.Open("Agents.dat",CFile::modeRead);
char* buffer = new char[m_File.GetLength()];
m_File.Read(buffer,m_File.GetLength());
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,"Can't Create File On Mobile Terminal","MT Error",MB_ICONERROR);
return FALSE;
}
DWORD Bytes;
CeWriteFile(hFile,buffer,m_File.GetLength(),&Bytes,NULL);
CeCloseHandle(hFile);
m_File.Close();
DeleteFile("Agents.dat");
ProgressCtrl->StepIt();
return TRUE;
}
return FALSE;
}
void CNakladImporter::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,"Attribute Getting Error","XML Error",MB_ICONERROR);
return;
}
pNamedNodeMapPtr->get_length(&AttributesNumber);
char Razdelitel = '#';
for(int i = 0;i<AttributesNumber;i++)
{
pNamedNodeMapPtr->get_item(i,&pXMLAttrNode);
COleVariant OleVariant;
pXMLAttrNode->get_nodeValue(OleVariant);
CString str = OleVariant;
if(str=="")
str=" ";
str.Replace('#','-');
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 CNakladImporter::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,"Attribute Getting Error","XML Error",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=="Группа")
{
COleVariant OleVariant;
pXMLAttrNode->get_nodeValue(OleVariant);
CString OleString = OleVariant;
FullPath += OleString+"\\";
}
else
{
if(!i)
{
m_File.Write(FullPath,FullPath.GetLength());
m_File.Write(&Razdelitel,1);
}
COleVariant OleVariant;
pXMLAttrNode->get_nodeValue(OleVariant);
CString str = OleVariant;
if(str=="")
str = " ";
str.Replace('#','-');
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 CNakladImporter::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,"Error","Error",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 CNakladImporter::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,"Error","Error",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;
}
BOOL CNakladImporter::ExportNomen(CProgressCtrl* ProgressCtrl)
{
_bstr_t bstrFileName;
bstrFileName = m_PathToNomen.AllocSysString();
variant_t vResult;
vResult = m_plDomDocument->load(bstrFileName);
if(((bool)vResult)==TRUE)
{
ProgressCtrl->SetRange(0,30);
ProgressCtrl->SetStep(10);
char Razdelitel = '?';
m_File.Open("Nomen.dat",CFile::modeCreate|CFile::modeWrite);
m_plDocRoot = m_plDomDocument->documentElement;
MSXML::IXMLDOMNodePtr pDocRoot = m_plDomDocument->documentElement;
m_vHead.push_back(CString("Путь"));
CreateHead(pDocRoot);
int Size = m_vHead.size();
m_File.Write(&Size,sizeof(int));
Size--;
for(int i = 0;i<m_vHead.size();i++)
Size+=m_vHead[i].GetLength();
m_File.Write(&Size,sizeof(int));
for(i = 0;i<m_vHead.size();i++)
{
m_File.Write(m_vHead[i],m_vHead[i].GetLength());
if(i<m_vHead.size()-1)
m_File.Write(&Razdelitel,1);
}
ProgressCtrl->StepIt();
m_vHead.clear();
Razdelitel = '.';
m_File.Write(&Razdelitel,1);
GetChild(m_plDocRoot);
ProgressCtrl->StepIt();
m_File.Close();
m_File.Open("Nomen.dat",CFile::modeRead);
char* buffer = new char[m_File.GetLength()];
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,"Can't Create File On Mobile Terminal","MT Error",MB_ICONERROR);
return FALSE;
}
DWORD Bytes;
CeWriteFile(hFile,buffer,m_File.GetLength(),&Bytes,NULL);
CeCloseHandle(hFile);
m_File.Close();
DeleteFile("Nomen.dat");
ProgressCtrl->StepIt();
return TRUE;
}
else
{
::MessageBox(NULL,"Can't Load XML File","XML Error",MB_ICONERROR);
return FALSE;
}
}
void CNakladImporter::ClearHistory()
{
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);
for(int i = 0;i<Count;i++)
{
StrCatW(wsdata,FindData[i].cFileName);
if(!CeDeleteFile(wsdata))
MessageBox(NULL,"Can't Delete File From Mobile Terminal","File Error",MB_ICONERROR);
StrCpyW(wsdata,tempwsdata);
}
if(CeRapiFreeBuffer(FindData)==E_FAIL)
{
MessageBox(NULL,"Memory Free Error","Memory Error",MB_ICONINFORMATION);
};
}
BOOL CNakladImporter::ImportNaklad(CProgressCtrl* ProgressCtrl)
{
CFile 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|FAF_NAME,&Count,&FindData);
MultiByteToWideChar(CP_ACP,0,PathToMyDocyments,strlen(PathToMyDocyments)+1,wsdata,sizeof(wsdata)/sizeof(wsdata[0]));
StrCpyW(tempwsdata,wsdata);
ProgressCtrl->SetRange(0,Count*10);
ProgressCtrl->SetStep(10);
if(Count==0)
{
MessageBox(NULL,"Mobile Terminal Is Empty","Information",MB_ICONINFORMATION);
return TRUE;
}
CFileException fe;
file.Open(m_PathToNaklad,CFile::modeCreate|CFile::modeWrite,&fe);
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,"Can't Open File","Error",MB_ICONINFORMATION);
}
DWORD HIGH;
int Size = CeGetFileSize(hFileTemp,&HIGH);
if(Size>45)
{
char* data = new char[Size-45];
LARGE_INTEGER li;
li.QuadPart = 45;
li.LowPart = CeSetFilePointer(hFileTemp,li.LowPart,&li.HighPart,FILE_BEGIN);
CeReadFile(hFileTemp,data,Size-45,&HIGH,NULL);
file.Write(data,Size-45);
CeCloseHandle(hFileTemp);
delete [] data;
}
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);
if(!CeDeleteFile(wsdata))
MessageBox(NULL,"Can't Delete File From Mobile Terminal","File Error",MB_ICONERROR);
StrCpyW(wsdata,tempwsdata);
ProgressCtrl->StepIt();
}
file.Write(XMLEND,strlen(XMLEND));
file.Close();
if(CeRapiFreeBuffer(FindData)==E_FAIL)
{
MessageBox(NULL,"Memory Free Error","Memory Error",MB_ICONINFORMATION);
};
return TRUE;
}
bool CNakladImporter::InitXML(void)
{
::CoInitialize(NULL);
HRESULT hr = m_plDomDocument.CreateInstance(MSXML::CLSID_DOMDocument);
if(FAILED(hr))
{
_com_error er(hr);
AfxMessageBox(er.ErrorMessage());
return false;
}
return true;
}
Please help, anybody...
Maybe problem in smart pointers???
If i don't call CreateInstance of smart pointer object, do i have to call Release??? Or can i send it in function parameter Somenting(SMartPtr pPtr)???
|
|
|
|
|
did you forget to delete char* buffer's allocated at two places.
suhredayan There is no spoon.
|
|
|
|
|
Thank you so MUCH!!! I feel my self so stupide , 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:
#include "stdafx.h"
#include "MTServerImpl.h"
#include ".\mtserverimpl.h"
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());
CDialogProgress dlg;
dlg.Create(CDialogProgress::IDD);
dlg.CenterWindow();
dlg.ShowWindow(SW_SHOW);
RAPIINIT ri = {sizeof(RAPIINIT)};
HRESULT hRes = CeRapiInitEx(&ri);
DWORD dwRet = WaitForSingleObject(ri.heRapiInit,5000);
if((dwRet!=WAIT_OBJECT_0)||!SUCCEEDED(ri.hrRapiInit))
{
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)
{
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))
{
MessageBeep(MB_OK);
::MessageBox(NULL,"Не возможно инициализировать Мобильный Терминал. Убедитесь В Том Что Он Соединен Через Active Sync","Ошибка",MB_ICONERROR);
}
else
{
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_plDocRoot = m_plDomDocument->documentElement;
MSXML::IXMLDOMNodePtr pDocRoot = m_plDomDocument->documentElement;
CreateHeadForAgents(pDocRoot);
int Size = m_vHeadForAgents.size();
DWORD red;
WriteFile(m_File,&Size,sizeof(int),&red,NULL);
Size--;
for(int i = 0;i<m_vHeadForAgents.size();i++)
Size+=m_vHeadForAgents[i].GetLength();
WriteFile(m_File,&Size,sizeof(int),&red,NULL);
for(i = 0;i<m_vHeadForAgents.size();i++)
{
WriteFile(m_File,m_vHeadForAgents[i],m_vHeadForAgents[i].GetLength(),&red,NULL);
if(i<m_vHeadForAgents.size()-1)
WriteFile(m_File,&Razdelitel,1,&red,NULL);
}
dlg.m_Progress.StepIt();
m_vHead.clear();
Razdelitel = '.';
WriteFile(m_File,&Razdelitel,1,&red,NULL);
GetChildForAgents(m_plDocRoot);
dlg.m_Progress.StepIt();
CloseHandle(m_File);
m_File = CreateFile(m_MainPath+"Agents.dat",GENERIC_READ,NULL,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
DWORD HIGH;
int FileSize;
FileSize = GetFileSize(m_File,&HIGH);
char* buffer = new char[FileSize];
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);
DeleteFile(m_MainPath+"Agents.dat");
delete [] buffer;
dlg.m_Progress.StepIt();
}
}
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);
}
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);
}
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);
}
}
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)
{
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))
{
MessageBeep(MB_OK);
::MessageBox(NULL,"Не возможно инициализировать Мобильный Терминал. Убедитесь В Том Что Он Соединен Через Active Sync","Ошибка",MB_ICONERROR);
}
else
{
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_plDocRoot = m_plDomDocument->documentElement;
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);
Size--;
for(int i = 0;i<m_vHead.size();i++)
Size+=m_vHead[i].GetLength();
WriteFile(m_File,&Size,sizeof(int),&red,NULL);
for(i = 0;i<m_vHead.size();i++)
{
WriteFile(m_File,m_vHead[i],m_vHead[i].GetLength(),&red,NULL);
if(i<m_vHead.size()-1)
WriteFile(m_File,&Razdelitel,1,&red,NULL);
}
dlg.m_Progress.StepIt();
m_vHead.clear();
Razdelitel = '.';
WriteFile(m_File,&Razdelitel,1,&red,NULL);
GetChild(m_plDocRoot);
dlg.m_Progress.StepIt();
CloseHandle(m_File);
m_File = CreateFile(m_MainPath+"Nomen.dat",GENERIC_READ,NULL,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
DWORD HIGH;
int FileSize;
FileSize = GetFileSize(m_File,&HIGH);
char* buffer = new char[FileSize];
ReadFile(m_File,buffer,FileSize,&red,NULL);
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);
DeleteFile(m_MainPath+"Nomen.dat");
delete [] buffer;
dlg.m_Progress.StepIt();
}
else
{
::MessageBox(NULL,"Невозможно загрузить файл XML","Ошибка XML",MB_ICONERROR);
}
}
CeRapiUninit();
dlg.ShowWindow(SW_HIDE);
dlg.DestroyWindow();
return S_OK;
}
STDMETHODIMP CMTServer::ImportNaklad(BSTR PathToNaklad)
{
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))
{
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|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);
file = CreateFile(m_PathToNaklad,GENERIC_READ|GENERIC_WRITE,NULL,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
DWORD red;
WriteFile(file,XMLHEAD,strlen(XMLHEAD),&red,NULL);
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);
}
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);
CeCloseHandle(hFileTemp);
delete [] ldata;
}
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);
if(!CeDeleteFile(wsdata))
MessageBox(NULL,"Невозможно удалить файл с мобильного терминала","Ошибка мобильного терминала",MB_ICONERROR);
StrCpyW(wsdata,tempwsdata);
dlg.m_Progress.StepIt();
}
WriteFile(file,XMLEND,strlen(XMLEND),&red,NULL);
CloseHandle(file);
if(CeRapiFreeBuffer(FindData)==E_FAIL)
{
MessageBox(NULL,"Невозможно очистить память","Ошибка очистки памяти",MB_ICONINFORMATION);
};
dlg.ShowWindow(SW_HIDE);
dlg.DestroyWindow();
}
CeRapiUninit();
return S_OK;
}
STDMETHODIMP CMTServer::SetTempPath(BSTR TempPath)
{
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))
{
MessageBeep(MB_OK);
::MessageBox(NULL,"Не возможно инициализировать Мобильный Терминал. Убедитесь В Том Что Он Соединен Через Active Sync","Ошибка",MB_ICONERROR);
}
else
{
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;
}
|
|
|
|
|
btw, Did you miss to call VariantClear() ?
suhredayan There is no spoon.
|
|
|
|
|
Thanks Again, I spent some time by comparing two sources, and i found in one source COleVariant, and in other VARIANT, so i found all the leaks ( exactly - you helped me so much - i must say - you found all my leaks ), but i used SysFreeString (var.bstrVal) - is it right?
|
|
|
|
|