char wideCharPoste[256]; if ( pPoste != NULL ) MultiByteToWideChar( CP_ACP , 0 , pPoste , strlen( pPoste ) + 1 , (LPWSTR) wideCharPoste , 256 ); char wideCharCheminPartage [256]; if ( pCheminPartage ! = NULL ) MultiByteToWideChar( CP_ACP , 0 , pCheminPartage , strlen( pCheminPartage ) + 1 , (LPWSTR) wideCharCheminPartage , 256 ); char wideCharNomPartage[256]; if ( pNomPartage != NULL ) MultiByteToWideChar( CP_ACP , 0 , pNomPartage , strlen( pNomPartage ) + 1 , (LPWSTR) wideCharNomPartage , 256 ); shareinfo.shi2_netname = wideCharNomPartage ; shareinfo.shi2_type = STYPE_DISKTREE; shareinfo.shi2_remark = TEXT("Test"); shareinfo.shi2_permissions = ACCESS_ALL; shareinfo.shi2_max_uses = (unsigned long)(-1); shareinfo.shi2_current_uses = 0; shareinfo.shi2_path = wideCharCheminPartage ; shareinfo.shi2_passwd = NULL;
nStatus = NetShareAdd( wideCharPoste , 2, (unsigned char *)(&shareinfo), &dwErrArg);
//fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff //fff CreerPartage fff //fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff // Creation d'un partage sur un poste distant // MSDN help // NetShareAdd : http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netmgmt/netmgmt/netshareadd.asp DECLSPEC BOOL WINAPI CreerPartage(LPSTR pPoste, LPSTR pCheminPartage, LPSTR pNomPartage, LPSTR pCommentairePartage, LPSTR pErreur) { NET_API_STATUS nStatus = 0; SHARE_INFO_2 shareinfo; DWORD dwErrArg; strcpy(pErreur, ""); if(!pPoste || !pCheminPartage || !pNomPartage || !pCommentairePartage) { return 1; }// fin if if(strncmp(pPoste, "\\\",2) != 0) { return 1; }// fin if shareinfo.shi2_path = AsWideString(pCheminPartage); shareinfo.shi2_netname = AsWideString(pNomPartage); shareinfo.shi2_remark = AsWideString(pCommentairePartage); shareinfo.shi2_type = STYPE_DISKTREE; shareinfo.shi2_permissions = ACCESS_ALL; shareinfo.shi2_max_uses = (unsigned long)(-1); shareinfo.shi2_current_uses = 0; shareinfo.shi2_passwd = NULL; nStatus = NetShareAdd(AsWideString(pPoste), 2, (unsigned char *)(&shareinfo), &dwErrArg); if(nStatus == NERR_Success) { // Le partage cree return 0; } else { // Erreur return 1; }// fin if }// fin fonction CreerPartage //fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff //fff AsWideString fff //fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff // Converti AINSI en UNICODE static char* AsWideString(const char* cszANSIstring) { int nBufSize = 0; if( cszANSIstring == NULL ) { return NULL; }// fin if nBufSize = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, cszANSIstring, -1, NULL, 0); WCHAR* wideString = new WCHAR[nBufSize+1]; MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, cszANSIstring, -1, wideString, nBufSize); return reinterpret_cast<char*>(wideString); }// fin fonction AsWideString
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question