|
-
Feb 16th, 2002, 11:57 PM
#1
Thread Starter
Addicted Member
in vb.net to get a value back from a function you dont set the return value to the function name.
You do the Return statement. Like this.
Code:
Option Strict On
Module modGetInfo
Public Declare Function GetVolumeInformation Lib "kernel32" _
Alias "GetVolumeInformationA" _
(ByVal lpRootPathName As String, _
ByVal lpVolumeNameBuffer As String, _
ByVal nVolumeNameSize As Long, _
ByVal lpVolumeSerialNumber As Long, _
ByVal lpMaximumComponentLength As Long, _
ByVal lpFileSystemFlags As Long, _
ByVal lpFileSystemNameBuffer As String, _
ByVal nFileSystemNameSize As Long) As Long
Function GetHardDriveSerialNumber() As Long
Dim Result As Long
Dim RootPathName As String = "C:"
Dim VolumeNameBuffer As String = Space(256)
Dim VolumeNameSize As Long = 256
Dim VolumeSerialNumber As Long = 0
Dim MaximumComponentLength As Long = 256
Dim FileSystemFlags As Long = 0
Dim FileSystemNameBuffer As String = Space(256)
Dim FileSystemNameSize As Long = 256
Result = GetVolumeInformation(RootPathName, _
VolumeNameBuffer, _
VolumeNameSize, _
VolumeSerialNumber, _
MaximumComponentLength, _
FileSystemFlags, _
FileSystemNameBuffer, _
FileSystemNameSize)
'do this
Return VolumeSerialNumber
'instead of this
GetHardDriveSerialNumber = VolumeSerialNumber
End Function
End Module
that should work for you
 ender_pete 
C#,VS.NET Ent Arch, vb6 ee sp5,html,vbscript,jscript,
xml,dhtml,delphi,c++,vc++,java,cgi,php, python, ada(so ancient) ,adasage(also ancient) and others i can't remember.....
-
Feb 17th, 2002, 12:15 AM
#2
Dazed Member
Posted by ender_pete
in vb.net to get a value back from a function you dont set the return value to the function name.
Actually you can set the return value to the function name.
-
Feb 17th, 2002, 01:37 AM
#3
Fanatic Member
The problem is still unsolved, but thanks at least for your interest and your attempts.
Regarding the method of return, you are both right - you can do it either way, but I don't think that is the issue here.
I have a suspicion it is something to do with the string declares.
In VB6 I would say
VB Code:
Dim VolumeNameBuffer As String * 256
which is a fixed-length string
VB Code:
Dim VolumeNameBuffer As String = Space(256)
is NOT a fixed length string, I think. But how else can I declare a fixed length string in .net?
I know about the nasty
VB Code:
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=100> Public s As String
(have not tried it yet), but isn't that just an Upgrade Wizard kludge? Isn't there a native way to declare fixed length strings in .net?
Anyway, if the API call is falling flat on its face for some reason - whether passing the wrong type of arguments or not - then why does it return a non-zero (success) value?
Me am think very strange (to quote I. R. Baboon.)
Last edited by BrianHawley; Feb 17th, 2002 at 01:41 AM.
Brian
(Fighting with the RightToLeft bugs in VS 2005)
-
Feb 17th, 2002, 10:40 AM
#4
Lively Member
I don't think that you use API functions in the same way as we did in VB 6. Instead of using function declarations, I believe that you have to use the Imports keyword to refer to the system object that contains the function or class that you want to use.
VB Code:
Imports System
Imports System.Environment
Not sure what the .net version of your specific function is though.
Maybe check out The KPD-Team 2001 website. Their API-Guide that is available for download might provide some help.
Darrin@CB69
-----------------------------------------------
Arrogance kills brain cells
-----------------------------------------------
Private Sub Sandwich (big As Byte)
On Error GoTo Pub
-
Feb 18th, 2002, 01:25 AM
#5
Fanatic Member
Yes, I'm coming around to that way of thinking - although I think the approach is via system.management rather than system.environment. I understand that .net DOES support 'traditional' API calls, but that it is viewed as backward compatability and not encouraged. It's just that we have a LOT of code to port, and were looking for a method that required the least changes possible. That would of course be altering the API calls to work in .net, rather than rewriting them all - but it looks as if rewriting may be easier - particularly if failed call returns a 'success' token, which is going to play hell with the apps. Better it just failed.
That KPD Team site is OUTSTANDING. Wish I had found it long ago.
Thanks for the help.
Brian
(Fighting with the RightToLeft bugs in VS 2005)
-
Jun 29th, 2002, 05:25 PM
#6
Member
This is how i have been "emulating" the fixed length string declare for dotnet
VB Code:
Dim str as string * 100
Dim str As New String(" ", 100)
-
Jun 29th, 2002, 09:24 PM
#7
try setting the rootpath string to c:\ instead of just c:
yeah that is porbably a long shot..but worth a try anyway.
Hint: My long shot guesses always seem to be right on the money 90% of the time :
-
Jul 3rd, 2002, 04:44 AM
#8
When declaring API calls, you be carefull which params have to be set byval and which byref
you need the backslash after the driveletter
in VB.Net you should use Integers instead of Longs
good luck
Sascha
VB Code:
Public Declare Function GetVolumeInformation Lib "kernel32" Alias "GetVolumeInformationA" _
(ByVal lpRootPathName As String, _
ByVal lpVolumeNameBuffer As String, _
ByVal nVolumeNameSize As Integer, _
ByRef lpVolumeSerialNumber As Integer, _
ByRef lpMaximumComponentLength As Integer, _
ByRef lpFileSystemFlags As Integer, _
ByVal lpFileSystemNameBuffer As String, _
ByVal nFileSystemNameSize As Integer) As Integer
Function GetHardDriveSerialNumber() As Integer
Dim Result As Integer
Dim RootPathName As String = "C:\"
Dim VolumeNameBuffer As String = Space(256)
Dim VolumeNameSize As Integer = 256
Dim VolumeSerialNumber As Integer = 0
Dim MaximumComponentLength As Integer = 256
Dim FileSystemFlags As Integer = 0
Dim FileSystemNameBuffer As String = Space(256)
Dim FileSystemNameSize As Integer = 256
Result = GetVolumeInformation(RootPathName, _
VolumeNameBuffer, _
VolumeNameSize, _
VolumeSerialNumber, _
MaximumComponentLength, _
FileSystemFlags, _
FileSystemNameBuffer, _
FileSystemNameSize)
Return VolumeSerialNumber
End Function
-
Jul 3rd, 2002, 04:48 PM
#9
Frenzied Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|