Benefit of isolating Win32 API functions in a single module? Syntax and x32/x64 compatibility

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
In developing a Windows Forms application (VS2010/VB) with several dozen classes and modules, I seem to have incorporated a variety of Win32 API function variations throughout my application, some of which seem to be duplicative/redundant. For improved code
management, I am considering consolidating and isolating (as much as possible) the Win32 API functions in a single module. Several questions arise:


Is this effort worthwhile? What syntax should be used when the Win32 functions are moved from a class to a module?
While I am doing this, should I also consolidate function signatures to enable x32/x64 compatibility?
Regarding syntax, I have noticed that the following syntax which works in a Windows form class, does not work in a module:
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _<br/>
Private Shared Function GetWindowTextLength( _<br/>
ByVal hwnd As IntPtr) As Integer<br/>
End Function
Whereas the following syntax works in a module:
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _<br/>
(ByVal hwnd As Long, ByVal lpString As String, _<br/>
ByVal cch As Long) As Long
Is there any way the former syntax (with setlasterror and charset assertions) can be used in a module?

Thanks for any advice. <hr class="sig -BGood

View the full article
 
Back
Top