Home › Forums › TWAIN Classic › Scan button on scanner button panel
- This topic has 3 replies, 2 voices, and was last updated 13 years, 8 months ago by dpenney.
- AuthorPosts
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;@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).
–I believe the code has the full path for the 2nd argument, but correct me if I am wrong
@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.
–- AuthorPosts