Logo UGIdotNET

Discussione 'Traduzione in VB'

# Pubblicato il 18 feb 2004 14.50 - Rispondi
Vito Pantaleo
Traduzione in VB
Ciao a tutti, qualcuno mi traduce questa chiamata alle Api e Routine in VB [DllImport("kernel32.dll")]
private static extern long GetVolumeInformation(string PathName, StringBuilder VolumeNameBuffer, UInt32 VolumeNameSize, ref UInt32 VolumeSerialNumber, ref UInt32 MaximumComponentLength, ref UInt32 FileSystemFlags, StringBuilder FileSystemNameBuffer, UInt32 FileSystemNameSize);

public static string GetVolumeSerial(string strDriveLetter)
{
uint serNum = 0;
uint maxCompLen = 0;
StringBuilder VolLabel = new StringBuilder(256);
UInt32 VolFlags = new UInt32();
StringBuilder FSName = new StringBuilder(256);
strDriveLetter+=":\\";
long Ret = GetVolumeInformation(strDriveLetter, VolLabel, (UInt32)VolLabel.Capacity, ref serNum, ref maxCompLen, ref VolFlags, FSName, (UInt32)FSName.Capacity);
return Convert.ToString(serNum);
}
# Pubblicato il 18 feb 2004 19.54 - Rispondi
Corrado Cavalli [MVP]
Re: Traduzione in VB

Ho aggiunto un piccolo check sul valore di ritorno della funzione...

<DllImport("kernel32.dll")> _
Private Shared Function GetVolumeInformation(ByVal PathName As String,
ByVal VolumeNameBuffer As StringBuilder, ByVal VolumeNameSize As Int32,
ByRef VolumeSerialNumber As Int32, ByRef MaximumComponentLength As Int32,
ByRef FileSystemFlags As Int32, ByVal FileSystemNameBuffer As StringBuilder,
ByVal FileSystemNameSize As Int32) As Long
End Function

Public Shared Function GetVolumeSerial(ByVal strDriveLetter As String)
As String
Dim serNum As Int32 = 0, maxCompLen As Int32 = 0
Dim VolLabel As StringBuilder = New StringBuilder(256)
Dim VolFlags As Int32
Dim FSName As StringBuilder = New StringBuilder(256)
strDriveLetter += ":\"
If GetVolumeInformation(strDriveLetter, VolLabel, VolLabel.Capacity,
serNum, maxCompLen, VolFlags, FSName, FSName.Capacity) = 0 Then Throw New
System.ComponentModel.Win32Exception
Return Convert.ToString(serNum)
End Function



HTH

--
Corrado Cavalli [Microsoft .NET MVP-MCP]
UGIdotNET - http://www.ugidotnet.org
Weblog: http://www.ugidotnet.org/710.blog


"Vito Pantaleo" <vpanta_TOGLIQUESTASTRINGA@libero.it> wrote in message
news:11b53469-09d3-4731-8bc9-c38b40658454@UGI32958...
> Ciao a tutti, qualcuno mi traduce questa chiamata alle Api e Routine in VB
> [DllImport("kernel32.dll")]
> private static extern long GetVolumeInformation(string PathName,
StringBuilder
> VolumeNameBuffer, UInt32 VolumeNameSize, ref UInt32 VolumeSerialNumber,
ref
> UInt32 MaximumComponentLength, ref UInt32 FileSystemFlags, StringBuilder
> FileSystemNameBuffer, UInt32 FileSystemNameSize);
>
> public static string GetVolumeSerial(string strDriveLetter)
> {
> uint serNum = 0;
> uint maxCompLen = 0;
> StringBuilder VolLabel = new StringBuilder(256);
> UInt32 VolFlags = new UInt32();
> StringBuilder FSName = new StringBuilder(256);
> strDriveLetter+=":\\";
> long Ret = GetVolumeInformation(strDriveLetter, VolLabel,
> (UInt32)VolLabel.Capacity, ref serNum, ref maxCompLen, ref VolFlags,
FSName,
> (UInt32)FSName.Capacity);
> return Convert.ToString(serNum);
> }
> ----------------------
> Questo messaggio è stato postato da http://www.ugidotnet.org/forum
> UGIdotNET - User Group Italiano .NET


----------------------
Questo messaggio è stato postato da microsoft.public.it.dotnet.vb.
# Pubblicato il 18 feb 2004 21.08 - Rispondi
Vito Pantaleo
Re: Traduzione in VB
Grazie tante, per la tua gentilezza.
Ciao.

© 2001 User Group Italiano UGIdotNET. Tutti i diritti riservati. Note legali. - Partita IVA 01927050185