By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,417 Members | 1,178 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,417 IT Pros & Developers. It's quick & easy.

GetVolumeNameForVolumeMountPoint Usage

P: n/a
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)
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.

"Mike Warrington" <mi*************@bigfoot.com> wrote in message
news:ut**************@tk2msftngp13.phx.gbl...
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)

Nov 21 '05 #2

P: n/a
* "Mike Warrington" <mi*************@bigfoot.com> scripsit:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.