// //TODO: If this DLL is dynamically linked against the MFC DLLs, // any functions exported from this DLL which call into // MFC must have the AFX_MANAGE_STATE macro added at the // very beginning of the function. // // For example: // // extern "C" BOOL PASCAL EXPORT ExportedFunction() // { // AFX_MANAGE_STATE(AfxGetStaticModuleState()); // // normal function body here // } // // It is very important that this macro appear in each // function, prior to any calls into MFC. This means that // it must appear as the first statement within the // function, even before any object variable declarations // as their constructors may generate calls into the MFC // DLL. // // Please see MFC Technical Notes 33 and 58 for additional // details. // void MyDeleteFile(CString& sPath) { WIN32_FIND_DATA fd; HANDLE hFind = ::FindFirstFile(sPath + _T("\\*.*"),&fd); if (hFind != INVALID_HANDLE_VALUE) { while (::FindNextFile(hFind,&fd)) { //判断是否为目录 if (fd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) { CString name; name = fd.cFileName; //判断是否为.和.. if ((name != ".") && (name != "..")) { //如果是真正的目录,进行递归 MyDeleteFile(sPath + fd.cFileName + _T("\\")); } } else DeleteFile(sPath + _T("\\") + fd.cFileName); } ::FindClose(hFind); } RemoveDirectory(sPath); }
CXMLParser::CXMLParser(const std::string& fileStr) { #pragma region Create temp folder CString szFolder; LPITEMIDLIST pidl; LPMALLOC pShellMalloc; TCHAR szTemp[MAX_PATH]; if(SUCCEEDED(SHGetMalloc(&pShellMalloc))) { if(SUCCEEDED(SHGetSpecialFolderLocation(NULL, CSIDL_APPDATA,&pidl))) { SHGetPathFromIDList(pidl,szTemp); szFolder =szTemp; pShellMalloc->Free(pidl); } pShellMalloc->Release(); } szFolder.TrimRight(_T("\\")); szFolder += _T("\\TF3DXML"); MyDeleteFile(szFolder); CFileStatus fstatus; if (!CFile::GetStatus(szFolder,fstatus)) { ::CreateDirectory(szFolder,NULL); } #pragma endregion Create temp folder const size_t strsize=(szFolder.GetLength()+1)*2; // 宽字符的长度; char * qstr= new char[strsize]; //分配空间; size_t sz=0; wcstombs_s(&sz,qstr,strsize,szFolder,_TRUNCATE); cUnpackFile unpackTool; unpackTool.CreateDirFromZip(qstr,fileStr.c_str()); delete []qstr; //delete []filestr; CFileFind finder; LPCTSTR pstr = szFolder; CString strWildcard(pstr); strWildcard += _T("\\*.*"); CString m_ext_now; m_ext_now.Format(_T("%s"),_T("3DRep")); CString m_str_3dxml; //查找装配树的.3dxml文件 m_str_3dxml.Format(_T("%s"),_T("3dxml")); BOOL bWorking = finder.FindFile(strWildcard); while (bWorking) { bWorking = finder.FindNextFile(); CString name = finder.GetFileName(); CString extend = name.Right(name.GetLength() - name.ReverseFind('.') - 1); if(!finder.IsDots()) { if (extend == m_ext_now)//m_ext_now为你要查找的文件扩展名 { CString str=finder.GetFilePath(); // 先得到要转换为字符的长度 const size_t strsize=(str.GetLength()+1)*2; // 宽字符的长度; char * pstr= new char[strsize]; //分配空间; size_t sz=0; wcstombs_s(&sz,pstr,strsize,str,_TRUNCATE); TiXmlDocument *myDocument = new TiXmlDocument(pstr); myDocument->LoadFile(); TiXmlElement *rootElement=myDocument->RootElement(); if(rootElement->FirstChildElement()->FirstChildElement()!=NULL && strcmp(rootElement->FirstChildElement()->FirstChildElement()->Value(),"Rep")==0) { m_pTempFile=new TF3DRepFile(); string filename; CT2A xx(name); filename = xx; m_pTempFile->SetFileName(filename); TraverseRep(rootElement->FirstChildElement()->FirstChildElement()); m_fileList.push_back(m_pTempFile); } delete myDocument; delete []pstr; } if(extend == m_str_3dxml) { CString str=finder.GetFilePath(); // 先得到要转换为字符的长度 const size_t strsize=(str.GetLength()+1)*2; // 宽字符的长度; char * pstr= new char[strsize]; //分配空间; size_t sz=0; wcstombs_s(&sz,pstr,strsize,str,_TRUNCATE); TiXmlDocument *myDocument = new TiXmlDocument(pstr); myDocument->LoadFile(); TiXmlElement *rootElement=myDocument->RootElement(); if(strcmp(rootElement->FirstChildElement()->NextSiblingElement()->Value(),"ProductStructure")==0) { rootElement=rootElement->FirstChildElement()->NextSiblingElement()->FirstChildElement(); m_root=new ReferenceTreeElement(); m_root->value=(char *)rootElement->FirstAttribute()->Next()->Next()->Value(); m_root->id=atoi(rootElement->FirstAttribute()->Next()->Value()); m_root->instancename=""; m_root->FirstChildElement=NULL; m_root->NextSimblingElement=NULL; while(rootElement!=NULL) { if(strcmp(rootElement->Value(),"Reference3D")==0) { AddReference3D(rootElement); } if(strcmp(rootElement->Value(),"Instance3D")==0) { AddInstance3D(rootElement); } rootElement=rootElement->NextSiblingElement(); } FindAllTreeNode(); ReferenceTreeElement *p=m_root; LinkTreeNode(p,NULL); } } } } finder.Close(); MyDeleteFile(szFolder); }
int _assuan_sock_bind (assuan_context_t ctx, assuan_fd_t sockfd, struct sockaddr *addr, int addrlen) { #ifdef HAVE_W32_SYSTEM if (addr->sa_family == AF_LOCAL || addr->sa_family == AF_UNIX) { struct sockaddr_in myaddr; struct sockaddr_un *unaddr; HANDLE filehd; int len = sizeof myaddr; int rc; char nonce[16]; char tmpbuf[33+16]; DWORD nwritten; if (get_nonce (nonce, 16)) return -1; unaddr = (struct sockaddr_un *)addr; myaddr.sin_port = 0; myaddr.sin_family = AF_INET; myaddr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); filehd = MyCreateFile (unaddr->sun_path, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); if (filehd == INVALID_HANDLE_VALUE) { if (GetLastError () == ERROR_FILE_EXISTS) gpg_err_set_errno (WSAEADDRINUSE); return -1; } rc = bind (HANDLE2SOCKET (sockfd), (struct sockaddr *)&myaddr, len); if (!rc) rc = getsockname (HANDLE2SOCKET (sockfd), (struct sockaddr *)&myaddr, &len); if (rc) { int save_e = errno; CloseHandle (filehd); MyDeleteFile (unaddr->sun_path); gpg_err_set_errno (save_e); return rc; } snprintf (tmpbuf, sizeof tmpbuf, "%d\n", ntohs (myaddr.sin_port)); len = strlen (tmpbuf); memcpy (tmpbuf+len, nonce,16); len += 16; if (!WriteFile (filehd, tmpbuf, len, &nwritten, NULL)) { CloseHandle (filehd); MyDeleteFile (unaddr->sun_path); gpg_err_set_errno (EIO); return -1; } CloseHandle (filehd); return 0; } else { int res = bind (HANDLE2SOCKET(sockfd), addr, addrlen); if (res < 0) gpg_err_set_errno ( _assuan_sock_wsa2errno (WSAGetLastError ())); return res; } #else return bind (sockfd, addr, addrlen); #endif }