GetVolumeNameForVolumeMountPoint Usage

  • Thread starter Thread starter Mike Warrington
  • Start date Start date
M

Mike Warrington

Hi,

I've been having real problems trying to get the above function to work in
my vb .net application which hopefully will assign a new drive letter to a
CD-Rom drive. This is what I've got so far:

Declare Function GetVolumeNameForVolumeMountPoint Lib "kernel32.dll"
Alias "GetVolumeNameForVolumeMountPointA" (ByVal lpszVolumeMountPoint As
String, ByVal lpszVolumeName As String, ByVal cchBufferLength As Integer) As
Integer

public function

Dim iret As Integer
Dim current as string = "Z:\"

Current &= vbNullChar
Dim sTemp = New StringBuilder(50)
sTemp = vbNullChar


iret = GetVolumeNameForVolumeMountPoint(Current, sTemp, 50)
end function

Supposedly the volume name is returned in the sTemp string, but i've yet to
get a return on this. I've also experimented with using pointers to the
strings and altering the function but this also doesn't work.

Any help would be appreciated.

Many Thanks

Mike
(Definitely a beginner)
 
* "Mike Warrington said:
I've been having real problems trying to get the above function to work in
my vb .net application which hopefully will assign a new drive letter to a
CD-Rom drive. This is what I've got so far:

Declare Function GetVolumeNameForVolumeMountPoint Lib "kernel32.dll"
Alias "GetVolumeNameForVolumeMountPointA" (ByVal lpszVolumeMountPoint As
String, ByVal lpszVolumeName As String, ByVal cchBufferLength As Integer) As
Integer

public function

Dim iret As Integer
Dim current as string = "Z:\"

Current &= vbNullChar
Dim sTemp = New StringBuilder(50)
sTemp = vbNullChar

What's the purpose of the line above? Get rid of it and write 'Dim
sTemp As New StringBuilder(50)' instead.

Deklare the 'lpszVolumeName' parameter as 'StringBuilder' instead of
declaring it as 'String'. Then change the function's return value's
type to 'Boolean' and check if the return value is 'True'. 'True'
indicates that the function call was successful.

<msdn>
lpszVolumeName
[out] Pointer to a string that receives the volume name. This name is
a unique volume name of the form "\\?\Volume{GUID}\" where GUID is the
GUID that identifies the volume.
</msdn>

Then, search for 'ControlChars.NullChar' in 'sTemp.ToString' and take
the part left from the 'NullChar' using the 'Strings.Left' function.
 
Mike,

Try this: define the second parameter as StringBuilder.
something like:
Declare Function GetVolumeNameForVolumeMountPoint Lib "kernel32.dll" _
Alias "GetVolumeNameForVolumeMountPointA" (ByVal lpszVolumeMountPoint As _
String, ByVal lpszVolumeName As System.Text.StringBuilder, ByVal
cchBufferLength As _
Integer) As Integer

hope this helps..
Imran.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top