VB.NET GetShortFileName Equivalent

  • Thread starter Thread starter Allen
  • Start date Start date
I am not sure I understand what you are saying you prefer here -- you would
like people to call the "A" or "W" versions directly, with no aliasing? Or
something else?

It would be easier to understand what you meant if you posted an example
declare you believe to be "good" and then the version that you believe to be
"bad".

Good:

Declare Auto Function GetUserName Lib "advapi32" ( _
ByVal lpBuffer As System.Text.StringBuilder, _
ByRef nSize As Integer) As Boolean

Bad:

Declare Function GetUserName Lib "advapi32" Alias "GetUserNameA" ( _
ByVal lpBuffer As String, _
ByRef nSize As Integer) As Boolean


That make it clear? In other words, leave off the Alias and use the
Auto keyword.

Tom Shelton
 
Tom Shelton said:
Good:

Declare Auto Function GetUserName Lib "advapi32" ( _
ByVal lpBuffer As System.Text.StringBuilder, _
ByRef nSize As Integer) As Boolean

Bad:

Declare Function GetUserName Lib "advapi32" Alias "GetUserNameA" ( _
ByVal lpBuffer As String, _
ByRef nSize As Integer) As Boolean


That make it clear? In other words, leave off the Alias and use the
Auto keyword.

Thats one option -- but it ignores the ton of legacy Declares that use the
old syntax. If you want to update, why not get away from declares and use
the more feature filled syntax that avoids them entirely?
 
Thats one option -- but it ignores the ton of legacy Declares that use the
old syntax. If you want to update, why not get away from declares and use
the more feature filled syntax that avoids them entirely?

Personally, I agree. I like the new syntax better and it does allow
more complete control. But, it is over kill for the majority of API
calls, and the declare syntax isn't quite as confusing for people
comming from a VB background. The new syntax doesn't bother me, because
it is essentially the same method that C# uses - and since I do almost
all my development in C#, I'm used to it. Though, I think it is a good
idea for people to look into using DllImport - since it seems to me I've
come across a couple of situations where it was required to get the
marshalling right (though, I can't remember exactly what they were off
the top of my head...).

Tom Shelton
 
Back
Top