I have been trying to implement a Hook which invokes on Custom POS Button. When user clicks on Custom POS button - it'll launch a Windows Form which have Few Text Fields and buttons.
The problem is that it doesn't invoke properly. It throws me an exception like "Attempt to execute COM object failed. Internal error found". Seems it invokes the Hook but there are some problems which i don't know. I have attached Source code on this
thread.
Technologies:
C# Framework 2.0
VS 2013
Windows 7 SP1
Implementation
There are two classes created for this
One is called Sale:
using QSRules;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Windows.Forms;
namespace Sales
{
public class Transaction
{
public Boolean Process(Object session)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Service());
return true;
}
}
}
2 . Second Class is called "Service" which extends Form to display windows Forms components like Button etc
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace Sales
{
public partial class Service : Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
public Service()
{
System.Windows.Forms.MessageBox.Show("In Service");
InitializeComponent();
System.Windows.Forms.MessageBox.Show("Loaded Successfully");
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(76, 109);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Service
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 262);
this.Controls.Add(this.button1);
this.Name = "Service";
this.Text = "Service";
this.Load += new System.EventHandler(this.Service_Load);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button button1;
private void button1_Click(object sender, EventArgs e)
{
}
private void Service_Load(object sender, EventArgs e)
{
}
}
}
Interestingly, it does display two alerts "In Service" and "Loaded Successfully" but then display "Attempt to execute COM object
failed. Internal error found"