Visual Basic and NULL pointers

Top  Previous  Next

Many DTWAIN functions that process strings allows the string parameter to be NULL.  For example, the DTWAIN_GetErrorString function has the option to set the string parameter to NULL if the caller only desires to have the length of the error string returned.

 

For Visual Basic .NET and greater (Visual Basic 2005 and later versions), you must use the following for sending NULL pointers to DTWAIN:

 

For 32-bit applications:

System.IntPtr.Zero

 

For 64-bit applications:

System.LongPtr.Zero

 

For example, to call DTWAIN_GetErrorString with a NULL pointer (assume this is a 32-bit application).

 

 

           Dim eLength As Integer

           REM get the length of the error message

           eLength = DTWAINAPI.DTWAIN_GetErrorString( DTWAINAPI.DTWAIN_ERR_BAD_SOURCE, System.IntPtr.Zero, 0 )

 

            REM size our string buffer appropriately and call again to get the string

            Dim sText As String

            sText = new String( Chr(0), eLength )

            DTWAINAPI.DTWAIN_GetErrorString( DTWAINAPI.DTWAIN_ERR_BAD_SOURCE, sText, eLength )