I have a Canon MP250 printer which can scan, copy, and print. I want to create my own ScanGear of a direct program to instruct the printer to print, and scan. I do have the disc that came with the printer but I just want to play around with it and like create my own app that will send printing commands to the printer and scanning commands to the printer to scan documents.

The main idea is not to use any of their software but be able to communicate with it and still do the printing, scanning functions as if I had installed their software's. I don't want to have their scangear on my laptop but rather create the program that will directly communicate with the device.

Anyone know how I can create this app or any link, documentation or anything that may point to the right direction with clues.

Thank you.

As you may already know. Most Printers support the TWAIN interface. Most printers also support WIA.

This being said, you could use a TWAIN or WIA library to access your scanner (Pending drivers are installed).

See attached file for code for a scanning library! (Courtesy of Mkasoft)

Place the code in a codefile and compile it into a library, then add that library reference to your project.

To use the code, try:

Private sMyScanner As String = String.Empty

Private Sub btnSelectSource_Click(sender As System.Object, e As System.EventArgs) Handles btnSelectSource.Click
    'Set the scan source for your scan.
    sMyScanner = TwainLib.GetScanSource
End Sub

Private Sub btnScan_Click(sender As System.Object, e As System.EventArgs) Handles btnScan.Click
    'Scan images from source and place the file path in a list of string for later access.
    Dim lstFiles As List(Of String) = TwainLib.ScanImages(".bmp", True, sMyScanner)
End Sub
written by mkaatr
' http://www.mka-soft.com
' Easy Twain Version 3.0
' Features:
' 1- detect autofeeder and use it by default
' 2- select a scanner only
' 3- scan documents from scanner without having to select the scanner everytime
' 4- comments and explinations to the source code
' 5- simpler function call than before, just use: "TwainLib.ScanImages" and "TwainLib.GetScanSource"

Imports System
Imports System.Runtime.InteropServices
Imports System.Windows.Forms
Imports System.Collections
Imports System.Drawing
Imports System.ComponentModel
Imports System.Data
Imports System.IO
Imports System.Drawing.Imaging
Imports System.Text
Imports System.Runtime.InteropServices.ComTypes


Public Module TwainOperations

    ' this is a single function call which get all images from scanner
    Public Function ScanImages(Optional ByVal ImageType As String = ".jpg", Optional ByVal CloseScannerUIAfterImageTransfer As Boolean = True, Optional ByVal ScannerInfo As String = "") As List(Of String)
            Dim TW As New TwainHandler
            Dim Z = TW.SelectSourceAndScan(ImageType, CloseScannerUIAfterImageTransfer, ScannerInfo)
            Return Z
        Catch ex As Exception
            Return New List(Of String)
        End Try
    End Function

    Public Function ScanImage(ByVal imageType As String, ByVal CloseUI As Boolean, ByVal ScannerInfo As String) As List(Of Image)
            Dim TW As New TwainHandler
            Dim Z = TW.ScanAndReturnImages(imageType, CloseUI, ScannerInfo)
            Return Z
        Catch ex As Exception
            Return New List(Of Image)
        End Try
    End Function

    ' this function gets the scan source
    Public Function GetScanSource() As String
            Dim TW As New TwainHandler
            Dim Obj = TW.GetScanObj()
            Return Obj.GetSelectedSourceInfo
        Catch ex As Exception
            Return ""
        End Try
    End Function

    Public Function SaveFileLocation(Optional ByVal sPath As String = "") As String
        If sPath = "" Then
            Return File_Location
            File_Location = sPath
            Return ""
        End If
    End Function

    Public Property File_Location As String
            Return My.Settings.FilePath
        End Get
        Set(value As String)
            If value.Length > 0 Then
                My.Settings.FilePath = value
            End If
        End Set
    End Property
End Module

Module MainCode
#Region "Twain DLL calls are defined here with some required enums"

    ' windows message
    <StructLayout(LayoutKind.Sequential, Pack:=4)> Public Structure WINMSG_S
        Public hwnd As IntPtr
        Public message As Integer
        Public wParam As IntPtr
        Public lParam As IntPtr
        Public time As Integer
        Public x As Integer
        Public y As Integer
    End Structure

    ' twain general commands - these are not standard commands, they are just to simplify stuff 
    Public Enum TwainCommand
        TwainCommand_Not = -1
        TwainCommand_Null = 0
        TwainCommand_TransferReady = 1
        TwainCommand_CloseRequest = 2
        TwainCommand_CloseOk = 3
        TwainCommand_DeviceEvent = 4
        TwainCommand_Failure = 5
    End Enum

    ' data groups
    <Flags()> Public Enum TwDG As Short
        TwDG_Control = &H1
        TwDG_Image = &H2
        TwDG_Audio = &H4
    End Enum

    ' data argument types
    Public Enum TwDAT As Short
        TwDAT_Null = &H0
        TwDAT_Capability = &H1
        TwDAT_Event = &H2
        TwDAT_Identity = &H3
        TwDAT_Parent = &H4
        TwDAT_PendingXfers = &H5
        TwDAT_SetupMemXfer = &H6
        TwDAT_SetupFileXfer = &H7
        TwDAT_Status = &H8
        TwDAT_UserInterface = &H9
        TwDAT_XferGroup = &HA
        TwDAT_TwunkIdentity = &HB
        TwDAT_CustomDSData = &HC
        TwDAT_DeviceEvent = &HD
        TwDAT_FileSystem = &HE
        TwDAT_PassThru = &HF
        TwDAT_ImageInfo = &H101
        TwDAT_ImageLayout = &H102
        TwDAT_ImageMemXfer = &H103
        TwDAT_ImageNativeXfer = &H104
        TwDAT_ImageFileXfer = &H105
        TwDAT_CieColor = &H106
        TwDAT_GrayResponse = &H107
        TwDAT_RGBResponse = &H108
        TwDAT_JpegCompression = &H109
        TwDAT_Palette8 = &H10A
        TwDAT_ExtImageInfo = &H10B
        TwDAT_SetupFileXfer2 = &H301
    End Enum

    ' message
    Public Enum TwMSG As Short
        TwMSG_Null = &H0
        TwMSG_Get = &H1
        TwMSG_GetCurrent = &H2
        TwMSG_GetDefault = &H3
        TwMSG_GetFirst = &H4
        TwMSG_GetNext = &H5
        TwMSG_Set = &H6
        TwMSG_Reset = &H7
        TwMSG_QuerySupport = &H8
        TwMSG_XFerReady = &H101
        TwMSG_CloseDSReq = &H102
        TwMSG_CloseDSOK = &H103
        TwMSG_DeviceEvent = &H104
        TwMSG_CheckStatus = &H201
        TwMSG_OpenDSM = &H301
        TwMSG_CloseDSM = &H302
        TwMSG_OpenDS = &H401
        TwMSG_CloseDS = &H402
        TwMSG_UserSelect = &H403
        TwMSG_DisableDS = &H501
        TwMSG_EnableDS = &H502
        TwMSG_EnableDSUIOnly = &H503
        TwMSG_ProcessEvent = &H601
        TwMSG_EndXfer = &H701
        TwMSG_StopFeeder = &H702
        TwMSG_ChangeDirectory = &H801
        TwMSG_CreateDirectory = &H802
        TwMSG_Delete = &H803
        TwMSG_FormatMedia = &H804
        TwMSG_GetClose = &H805
        TwMSG_GetFirstFile = &H806
        TwMSG_GetInfo = &H807
        TwMSG_GetNextFile = &H808
        TwMSG_Rename = &H809
        TwMSG_Copy = &H80A
        TwMSG_AutoCaptureDir = &H80B
        TwMSG_PassThru = &H901
    End Enum

    ' return code
    Public Enum TwRC As Short
        TwRC_Success = &H0
        TwRC_Failure = &H1
        TwRC_CheckStatus = &H2
        TwRC_Cancel = &H3
        TwRC_DSEvent = &H4
        TwRC_NotDSEvent = &H5
        TwRC_XferDone = &H6
        TwRC_EndOfList = &H7
        TwRC_InfoNotSupported = &H8
        TwRC_DataNotAvailable = &H9
    End Enum

    ' condition code
    Public Enum TwCC As Short
        TwCC_Success = &H0
        TwCC_Bummer = &H1
        TwCC_LowMemory = &H2
        TwCC_NoDS = &H3
        TwCC_MaxConnections = &H4
        TwCC_OperationError = &H5
        TwCC_BadCap = &H6
        TwCC_BadProtocol = &H9
        TwCC_BadValue = &HA
        TwCC_SeqError = &HB
        TwCC_BadDest = &HC
        TwCC_CapUnsupported = &HD
        TwCC_CapBadOperation = &HE
        TwCC_CapSeqError = &HF
        TwCC_Denied = &H10
        TwCC_FileExists = &H11
        TwCC_FileNotFound = &H12
        TwCC_NotEmpty = &H13
        TwCC_PaperJam = &H14
        TwCC_PaperDoubleFeed = &H15
        TwCC_FileWriteError = &H16
        TwCC_CheckDeviceOnline = &H17
    End Enum

    ' type definition
    Public Enum TwOn As Short
        TwOn_Array = &H3
        TwOn_Enum = &H4
        TwOn_One = &H5
        TwOn_Range = &H6
        TwOn_DontCare = -1
    End Enum

    ' type definition
    Public Enum TwType As Short
        TwType_Int8 = &H0
        TwType_Int16 = &H1
        TwType_Int32 = &H2
        TwType_UInt8 = &H3
        TwType_UInt16 = &H4
        TwType_UInt32 = &H5
        TwType_Bool = &H6
        TwType_Fix32 = &H7
        TwType_Frame = &H8
        TwType_Str32 = &H9
        TwType_Str64 = &HA
        TwType_Str128 = &HB
        TwType_Str255 = &HC
        TwType_Str1024 = &HD
        TwType_Str512 = &HE
    End Enum

    ' capabilities
    Public Enum TwCap As Short
        TwCap_XferCount = &H1
        TwCap_ICompression = &H100
        TwCap_IPixelType = &H101
        TwCap_IUnits = &H102
        TwCap_IXferMech = &H103
        TwCap_FeederEnabled = &H1002
        TwCap_FeederLoaded = &H1003
        TwCap_PAPERDETECTABLE = &H100D
        TwCap_AutoFeed = &H1007
        TwCap_AutoScan = &H1010
    End Enum

    <StructLayout(LayoutKind.Sequential, Pack:=2, CharSet:=CharSet.Ansi)> Public Class TwIdentity
        Public Id As IntPtr
        Public Version As TwVersion
        Public ProtocolMajor As Short
        Public ProtocolMinor As Short
        Public SupportedGroups As Integer
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=34)> Public Manufacturer As String
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=34)> Public ProductFamily As String
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=34)> Public ProductName As String
    End Class

    <StructLayout(LayoutKind.Sequential, Pack:=2, CharSet:=CharSet.Ansi)> Public Structure TwVersion
        Public MajorNum As Short
        Public MinorNum As Short
        Public Language As Short
        Public Country As Short
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=34)> Public Info As String
    End Structure

    <StructLayout(LayoutKind.Sequential, Pack:=2)> Public Class TwUserInterface
        Public ShowUI As Short
        Public ModalUI As Short
        Public ParentHand As IntPtr
    End Class

    <StructLayout(LayoutKind.Sequential, Pack:=2)> Public Class TwStatus
        Public ConditionCode As Short
        Public Reserved As Short
    End Class

    <StructLayout(LayoutKind.Sequential, Pack:=2)> Public Structure TwEvent
        Public EventPtr As IntPtr
        Public Message As Short
    End Structure

    <StructLayout(LayoutKind.Sequential, Pack:=2)> Public Class TwImageInfo
        Public XResolution As Integer
        Public YResolution As Integer
        Public ImageWidth As Integer
        Public ImageLength As Integer
        Public SamplesPerPixel As Short
        <MarshalAs(UnmanagedType.ByValArray, SizeConst:=8)> Public BitsPerSample() As Short
        Public BitsPerPixel As Short
        Public Planar As Short
        Public PixelType As Short
        Public Compression As Short
    End Class

This article has been dead for over six months. Start a new discussion instead.