C# 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 C# applications, 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).
namespace WindowsApplication { using Dynarithmic;
static void Main() { //... // get the length of the error message int eLength = TwainAPI.DTWAIN_GetErrorString( TwainAPI.DTWAIN_ERR_BAD_SOURCE, System.IntPtr.Zero, 0 );
// size our string buffer appropriately and call again to get the string StringBuilder sText = new StringBuilder( eLength ); TwainAPI.DTWAIN_GetErrorString( TwainAPI.DTWAIN_ERR_BAD_SOURCE, sText, eLength ); } }
|