TWAIN Working Group

Newsletter Signup
Donate
Help keep TWAIN free
  • About TWAIN
    • What’s New?
    • News
    • Events
    • Membership
    • Consider a Donation
    • Contact Us
  • Why TWAIN?
  • Developers
    • Driver Developer
    • Application Developer
    • TWAIN Features
    • Specification & Tools
    • Self Certification Process
  • Support Forums
  • Scanner End-User
  • Find Certified Drivers
    • Facebook
    • LinkedIn
    • Vimeo

Scan button on scanner button panel

Forums › TWAIN Classic › Scan button on scanner button panel

  • This topic has 3 replies, 2 voices, and was last updated 10 years, 7 months ago by dpenney.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • August 24, 2010 at 7:27 pm #22628 Reply
    loki_dre
    Participant
    • Topics - 1
    • Replies - 1
    • Total Posts - 2

    Hello,
    I am using the Canon P-150.
    I am trying to make the ‘scan button’ on the scanner’s button panel run a program when it is pushed. I have heard this can be done with the function RegisterLaunchApplication from the STI (Still Image) API. Anyone have some experience with doing this.

    the code I have right now is listed below, however I keep getting an error (0x80070057) when I execute the function ‘RegisterLaunchApplication’:


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    using System.Reflection;
    using System.Management;
    using System.Management.Instrumentation;

    private void button1_Click(object sender, EventArgs e)
    {
    IntPtr hinst = GetModuleHandle(null);
    IStillImage sti;
    int ret = StiCreateInstance(hinst, STI_VERSION_3, out sti, IntPtr.Zero);
    string commandline = """ + Assembly.GetEntryAssembly().Location + "" /StiDevice:%1 /StiEvent:%2";
    MessageBox.Show(commandline);
    ret = sti.RegisterLaunchApplication("MyApp", commandline);
    MessageBox.Show(ret.ToString());
    }


    [ComImport]
    [Guid("641BD880-2DC8-11D0-90EA-00AA0060F86C")]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface IStillImage
    {
    [PreserveSig]
    int RegisterLaunchApplication(
    [In, MarshalAs(UnmanagedType.LPWStr)] string pwszAppName,
    [In, MarshalAs(UnmanagedType.LPWStr)] string pwszCommandLine);
    }

    [DllImport("kernel32.dll")]
    static extern IntPtr GetModuleHandle(
    [MarshalAs(UnmanagedType.LPWStr)] string lpModuleName);

    [DllImport("sti.dll", EntryPoint = "StiCreateInstanceW")]
    static extern int StiCreateInstance(IntPtr hinst, int dwVer, out IStillImage ppSti, IntPtr punkOuter);

    const int STI_VERSION = 0x01000002;
    const int STI_VERSION_3 = 0x01000003;
    August 24, 2010 at 10:40 pm #25323 Reply
    dpenney
    Participant
    • Topics - 3
    • Replies - 66
    • Total Posts - 69

    @loki_dre wrote:

    …I keep getting an error (0x80070057) when I execute the function ‘RegisterLaunchApplication’

    According to winerror.h: 0x80070057 = E_INVALIDARG = “One or more arguments are invalid”

    I bet the second parameter is required to be a full path to an EXE file (e.g. C:windowsnotepad.exe).
    –

    August 25, 2010 at 1:05 am #25324 Reply
    loki_dre
    Participant
    • Topics - 1
    • Replies - 1
    • Total Posts - 2

    I believe the code has the full path for the 2nd argument, but correct me if I am wrong

    August 25, 2010 at 2:27 am #25325 Reply
    dpenney
    Participant
    • Topics - 3
    • Replies - 66
    • Total Posts - 69

    @loki_dre wrote:

    I believe the code has the full path for the 2nd argument, but correct me if I am wrong

    What exactly does commandline contain before the call to RegisterLaunchApplication?

    As an experiment try:

      ret = sti.RegisterLaunchApplication("MyApp", "C:\windows\notepad.exe");

    in place of:

      ret = sti.RegisterLaunchApplication("MyApp", commandline); 

    If that works, your second argument is invalid for some reason.
    –

  • Author
    Posts
Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: Scan button on scanner button panel
Your information:




Quick Links

Service Providers
TWAIN Support Forums
Membership
Contact Us
Privacy Policy

Newsletter Signup

TWAIN Working Group Family

TWAIN Working Group
TWAIN Direct®
TWAIN Resources
TWAIN Certified Drivers
PDF/raster

  • Facebook
  • GitHub
  • LinkedIn
  • Vimeo

Recent Topics

  • Sports betting Bonus Code
  • PDF/R For who and where?
  • Making searchable PDF with PDF/R
  • Backward compatibility with PDF/A and traditional PDF
  • could not open the twain source. Make sure there is a valid source for your sca
  • Quarterly Newsletter
  • TWAIN Working Group Membership
  • Logo Usage
  • TWAIN License
  • Contact Us
Privacy Policy • Privacy Tools • Copyright © 2021 TWAIN Working Group • by iHwy, LLC • Log in

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.