Conversion en PB

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Avatar de l’utilisateur
Jackymb
Messages : 17
Inscription : mer. 04/août/2004 10:09
Localisation : Aix en Provence

Conversion en PB

Message par Jackymb »

Bonjour,
j'ai besoin de faire une interogation sur l'active directory, et j'aurai besoin d'aide pour convertir le code suivant en purebasic.

Code : Tout sélectionner


IADs *pobjADs;    // Pointer to object interface
BSTR bstrName;    // String with object name    
HRESULT hResult;  // COM result code

    // String to directory service
    WCHAR *pstrADsPath = "LDAP://ldap.itd.umich.edu/O=University of Michigan,C=us";
    // Initalize COM
    CoInitialize ( NULL );

    // Get pointer to object's IADs interface
    hResult = ADsGetObject( pstrADsPath, IID_IADs, (void**) &pobjADs);

    // Check for success
    if ( SUCCEEDED ( hResult ) )
    {
    // Get the Name property from the object
    hResult = pobjADs->get_Name ( &bstrName );

        // Check for success
	if ( SUCCEEDED ( hResult ) )
	{            
	// Display Name property            
	// (must use wide strings when working with COM)
	wcout << "The name of the object found is: << bstrName << endl;
	}        
	else
	{
	wcerr << L"Error occured while getting the object name: " << hResult << endl;
	}
	// When finished with the interface, call the
	// Release method to free object
	pobjADs->Release ();
	}
	else
	{
	wcerr << L"Error occured while getting the object: "  << hResult << endl;
	}

    // Unload COM
    CoUninitialize ();

    // Return the result of any failures
    return hResult;
Merci par avance
Windows 11 x64 - PB 6.20 x64 - PB 6.21 x64 beta
nico
Messages : 3702
Inscription : ven. 13/févr./2004 0:57

Re: Conversion en PB

Message par nico »

Code : Tout sélectionner

; Compiler en UNICODE

Procedure Test(pstrADsPath.s)
	Protected pobjADs.IADs;    // Pointer to object interface
	Protected *bstrName.l;    // String with object name    
	Protected hResult.l;  // COM result code
	
	;// Initalize COM
	CoInitialize_ ( #Null )
	
	;// Get pointer To object's IADs interface
	hResult = ADsGetObject_( pstrADsPath, ?IID_IADs, @pobjADs)

	;// Check For success
	If hResult = 0
		*bstrName=SysAllocString_(Space(255))
		;// Get the Name property from the object
		hResult = pobjADs\get_Name(@*bstrName )
		;// Check For success
		If hResult=0           
			;// Display Name property            
			;// (must use wide strings when working With COM)
			MessageRequester("Info","The name of the object found is: "+PeekS(*bstrName))
			;// When finished With the Interface, call the
			;// Release method To free object
			pobjADs\Release ()
		Else
			MessageRequester("Info","Error occured While getting the object name: "+Str(hResult))
		EndIf
		SysFreeString_(*bstrName)
	Else
		MessageRequester("Info","Error occured While getting the object: "+Str(hResult))
	EndIf 
	
	;// Unload COM
	CoUninitialize_()
	
	;// Return the result of any failures
	ProcedureReturn hResult
EndProcedure 

;// String To directory service
pstrADsPath.s = "LDAP://ldap.itd.umich.edu/O=University of Michigan,C=us"
;pstrADsPath.s ="LDAP:"
Debug test(pstrADsPath)

DataSection
	IID_IADs:
	Data.l $FD8256D0
	Data.w $FD15, $11CE
	Data.b $AB, $C4, $02, $60, $8C, $9E, $75, $53
EndDataSection

Avatar de l’utilisateur
Jackymb
Messages : 17
Inscription : mer. 04/août/2004 10:09
Localisation : Aix en Provence

Re: Conversion en PB

Message par Jackymb »

bonjour,

Merci Beaucoup NICO
cela fonctionne je vais approfondir sur d'autre(s) caracteristique(s).
Mais avant je vais prendre quelque vacances
Windows 11 x64 - PB 6.20 x64 - PB 6.21 x64 beta
nico
Messages : 3702
Inscription : ven. 13/févr./2004 0:57

Re: Conversion en PB

Message par nico »

De rien, j'ai fait une petite modif; sysfreestring était mal placé.
Répondre