PC Review


Reply
Thread Tools Rate Thread

API Declaration Styles

 
 
=?Utf-8?B?RGF2aWQgQW50b24=?=
Guest
Posts: n/a
 
      15th Aug 2005
There are two styles of declaring external API functions in VB:

1. VB6-Style (for lack of a better description)
Public Declare ...

2. Using attributes (similar to C#) and omitting the function body:
<DLLImport ....>
Public Shared Function ...
End Function

I've always assumed that the latter style was more in the spirit of .NET and
our Instant VB converter currently converts to the latter style, but recent
googling seems to show that the first style is still very popular. Any
thoughts on the two different styles?
--
David Anton
www.tangiblesoftwaresolutions.com
Home of:
Clear VB: Cleans up outdated VB.NET code
Instant C#: Converts from VB.NET to C#
Instant VB: Converts from C# to VB.NET
Instant J#: Converts from VB.NET to J#
 
Reply With Quote
 
 
 
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      15th Aug 2005
"David Anton" <(E-Mail Removed)> schrieb:
> There are two styles of declaring external API functions in VB:
>
> 1. VB6-Style (for lack of a better description)
> Public Declare ...
>
> 2. Using attributes (similar to C#) and omitting the function body:
> <DLLImport ....>
> Public Shared Function ...
> End Function
>
> I've always assumed that the latter style was more in the spirit of .NET
> and
> our Instant VB converter currently converts to the latter style, but
> recent
> googling seems to show that the first style is still very popular. Any
> thoughts on the two different styles?



I prefer VB.NET's 'Declare' syntax over 'DllImport' because I think it's
more self-documenting and easier to use due to better IntelliSense support.
'Declare' statements don't need the 'Shared' modifier when placed in a
class, while 'DllImport' functions do. In addition to that, many declares
can already be found in the 'Declare' format. Still, there are some cases
when 'DllImport' must.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

 
Reply With Quote
 
Dragon
Guest
Posts: n/a
 
      15th Aug 2005
According to Lutz Roeder's .NET Reflector
(http://www.aisto.com/roeder/dotnet), Declare statements are converted
to "attributish" style, for example

~
Friend Declare Auto Function LoadLibrary Lib "kernel32.dll" ( _
<MarshalAs(UnmanagedType.LPTStr)> ByVal LibFileName As String _
) As IntPtr
~

becomes

~
<DllImport("kernel32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Friend Shared Function LoadLibrary(<MarshalAs(UnmanagedType.LPTStr)>
ByVal LibFileName As String) As IntPtr
End Function
~

To my mind, classic VB-style declarations are no bad (since they are not
considered as obsolete like On Error statements), because they take less
space and are easier to type (IMHO).


 
Reply With Quote
 
Mattias Sjögren
Guest
Posts: n/a
 
      16th Aug 2005
>Any thoughts on the two different styles?

http://www.dotnetinterop.com/faq/?q=DeclareDllImport



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
 
Reply With Quote
 
=?Utf-8?B?RGF2aWQgQW50b24=?=
Guest
Posts: n/a
 
      16th Aug 2005
Thanks Herfried, Dragon, and Mattias - I think we'll offer an option to
convert to the 'Declare' format when the attributes in the original C# code
being convered are appropriate.

Thanks also for the link Mattias!

--
David Anton
www.tangiblesoftwaresolutions.com
Home of:
Clear VB: Cleans up outdated VB.NET code
Instant C#: Converts from VB.NET to C#
Instant VB: Converts from C# to VB.NET
Instant J#: Converts from VB.NET to J#


"David Anton" wrote:

> There are two styles of declaring external API functions in VB:
>
> 1. VB6-Style (for lack of a better description)
> Public Declare ...
>
> 2. Using attributes (similar to C#) and omitting the function body:
> <DLLImport ....>
> Public Shared Function ...
> End Function
>
> I've always assumed that the latter style was more in the spirit of .NET and
> our Instant VB converter currently converts to the latter style, but recent
> googling seems to show that the first style is still very popular. Any
> thoughts on the two different styles?
> --
> David Anton
> www.tangiblesoftwaresolutions.com
> Home of:
> Clear VB: Cleans up outdated VB.NET code
> Instant C#: Converts from VB.NET to C#
> Instant VB: Converts from C# to VB.NET
> Instant J#: Converts from VB.NET to J#

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Restoring original Normal and No spacing styles in styles gallery Stefan Blom Microsoft Word Document Management 0 21st Aug 2009 06:40 PM
Word 2007 styles - Styles pane - "Disable Linked Styles" rgille Microsoft Word Document Management 5 3rd Jul 2008 03:31 AM
Make Word Outlining use bullet styles instead of heading styles? =?Utf-8?B?Qm9iVw==?= Microsoft Word Document Management 1 13th Apr 2006 05:21 PM
Problem on new styles declaration Mr. x Microsoft Word New Users 1 10th Dec 2003 08:52 AM
Formatting text with styles: problem with default Word97 styles jk Microsoft Word Document Management 1 29th Aug 2003 02:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:10 PM.