I am creating a application form to view/change a tag from a software called InTouch.
I added the dll as a reference and I would like to use the Read(string tagName) fct in the IOM.InTouchDataAccess. VS does not see the fct Read when I write InTouchWrapper TagType = new read(). It only sees InTouchWrapper as I wrote in the code which gives me the error IOM.InTouchDataAccess.InTouchWrapper' does not contain a constructor that takes 0 arguments
I don't understand why is this happening. I am running the InTouch software while coding, maybe there is an access conflict with the software.
MyCode
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 IOM.InTouchDataAccess;
namespace TagBrowser
{
public partial class TagBrowser : Form
{
public TagBrowser()
{
InitializeComponent();
}
private void TagBrowser_Load(object sender, EventArgs e)
{
}
private void TagBox_TextChanged(object sender, EventArgs e)
{
}
private void TypeBox_SelectedIndexChanged(object sender, EventArgs e)
{
InTouchWrapper TagType = new InTouchWrapper();
}
The dll
using System;
using System.Collections.Generic;
using System.Text;
using NDde.Client;
namespace IOM.InTouchDataAccess
{
public class InTouchDdeWrapper : IDisposable
{
private int DDE_TIMEOUT = 60000;
private DdeClient _ddeClient;
public InTouchDdeWrapper()
{
_ddeClient = new DdeClient("View", "Tagname");
}
~InTouchDdeWrapper()
{
Dispose();
}
public void Initialize()
{
_ddeClient.Connect();
}
public string Read(string tagName)
{
return _ddeClient.Request(tagName, DDE_TIMEOUT).Replace("\0", "");
}
I'm putting this here in case somebody else would get the same problem:
Are you sure it's the correct dll you referenced? Try to open the
exact referenced dll in a decompiler (JustDecompile free,
Reflector or dotPeek free) and see if it's the code you
expect.
Related
So today I tried dll injection to game (assult cube) to test my experience with my job.
But I got problems with Win32 Exception: 0xc0000005.
My code looks like:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Memory;
namespace AssultCube_Cheat
{
public partial class Form1 : Form
{
Mem assultcube = new Mem();
public static string RifleAmmo = "ac_client.exe+0x0017E0A8";
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
int PID = assultcube.GetProcIdFromName("ac_client");
if (PID > 0)
{
assultcube.OpenProcess(PID);
Thread WA = new Thread(writeAmmo) { IsBackground = true };
WA.Start();
}
}
private void writeAmmo()
{
while (true)
{
if (checkBox1.Checked)
{
assultcube.WriteMemory(RifleAmmo, "int", "80");
Thread.Sleep(2);
}
Thread.Sleep(2);
}
}
}
}
I tried updating my computer drivers, upgrading my system to Windows 11 but problem didnt fix.
I am using Gma.System.MouseKeyHook and getting the following exception:
Managed Debugging Assistant 'CallbackOnCollectedDelegate'
Message=Managed Debugging Assistant 'CallbackOnCollectedDelegate' : 'A callback was made on a garbage collected delegate of type 'Gma.System.MouseKeyHook!Gma.System.MouseKeyHook.WinApi.HookProcedure::Invoke'. This may cause application crashes, corruption and data loss. When passing delegates to unmanaged code, they must be kept alive by the managed application until it is guaranteed that they will never be called.'
I've tried to handle the function calls and subscription. However, the issue still persists. Also I try to run it many times, occasionally it gives a 'NullReferenceException' as well. It also confused me a lot, maybe those issues are correlated.
using Gma.System.MouseKeyHook;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
// Uses a MouseKeyHook Library license at
https://github.com/gmamaladze/globalmousekeyhook/blob/master/LICENSE.txt
namespace TransparentClickTest {
public partial class Form1 : Form {
public Form1() {
//GC.TryStartNoGCRegion(100);
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
BackColor = Color.Red;
TransparencyKey = Color.Red;
InitializeComponent();
OnDown();
}
protected virtual void OnUp() {
Hook.GlobalEvents().MouseUp += (sender, e) => {
try {
label1.Text = "Mouse Up!!!";
Hook.GlobalEvents().Dispose();
OnDown();
}
catch(Exception e2) {
Hook.GlobalEvents().Dispose();
OnDown();
}
};
}
protected virtual void OnDown() {
Hook.GlobalEvents().MouseDown += (sender, e) => {
try {
label1.Text = $"Mouse {e.Button} Down at {e.X}, {e.Y}";
Opacity = 1;
Hook.GlobalEvents().Dispose();
OnUp();
}
catch(Exception e1) {
Hook.GlobalEvents().Dispose();
OnUp();
}
};
}
private void PictureBox1_Click(object sender, EventArgs e) {
}
private void Label1_Click(object sender, EventArgs e) {
}
}
}
add this: private static IKeyboardMouseEvents HookEvents = null;
use HookEvents.MouseDown replace Hook.GlobalEvents().MouseDown
I did some research about this error, and all awnsers i found include removing static from the method or the property, but in my code there isnt any static, so i dont know whats happening, thanks for your help.
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;
namespace WindowsFormsApplication1
{
public partial class textoTitular : Form
{
public textoTitular()
{
InitializeComponent();
}
private void textoTitular_Load(object sender, EventArgs e)
{
textoTitular.Text = "testing"; /// prints testing on the textbox
}
}
}
Your problem is in
private void textoTitular_Load(object sender, EventArgs e)
{
textoTitular.Text = "testing"; /// prints testing on the textbox
}
You are referencing the form class in a static way.
Rather try using this. Something like
private void textoTitular_Load(object sender, EventArgs e)
{
this.Text = "testing"; /// prints testing on the textbox
}
Added bonus, you can omit the this and use the object property
private void textoTitular_Load(object sender, EventArgs e)
{
Text = "testing"; /// prints testing on the textbox
}
I'm following the example from "Programming C# 4.0, 6th edition" for working with Windows Forms, but I get to a point where I can't understand what actually happens. I have 3 files
One with Main() :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace ToDoList
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
one to work with the fields of the form:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class ToDoEntry
{
public string Title { get; set; }
public string Description { get; set; }
public DateTime DueDate { get; set; }
}
And the form itself :
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;
namespace ToDoList
{
public partial class Form1 : Form
{
private BindingList<ToDoEntry> entries = new BindingList<ToDoEntry>();
public Form1()
{
InitializeComponent();
entriesSource.DataSource = entries;
CreateNewItem();
}
private void bindingSource1_CurrentChanged(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void CreateNewItem()
{
ToDoEntry newEntry = (ToDoEntry)entriesSource.AddNew();
newEntry.Title = "New entry";
newEntry.DueDate = DateTime.Now;
entriesSource.ResetCurrentItem();
}
private void entriesSource_ListChanged(object sender, ListChangedEventArgs e)
{
switch (e.ListChangedType)
{
case ListChangedType.ItemAdded:
MakeListViewItemForNewEntry(e.NewIndex);
break;
case ListChangedType.ItemDeleted:
RemoveListViewItem(e.NewIndex);
break;
case ListChangedType.ItemChanged:
UpdateListViewItem(e.NewIndex);
break;
}
}
private void MakeListViewItemForNewEntry(int newItemIndex)
{
ListViewItem item = new ListViewItem();
item.SubItems.Add("");
entriesListView.Items.Insert(newItemIndex, item);
}
private void UpdateListViewItem(int itemIndex)
{
ListViewItem item = entriesListView.Items[itemIndex];
ToDoEntry entry = entries[itemIndex];
item.SubItems[0].Text = entry.Title;
item.SubItems[1].Text = entry.DueDate.ToShortDateString();
}
private void RemoveListViewItem(int deletedItemIndex)
{
entriesListView.Items.RemoveAt(deletedItemIndex);
}
}
}
My problem is with saying that The name entriesListView does not exist in the current context. Which is true, but for example entriesSource.DataSource = entries;
I don't have entriesSource either but for some reason I can use it. Now I'm not sure if the missing class(at least I think it should be a class) is something that VS2010 (Yes I'm using Visual Studio 2010) should generate but then - why it hasn't.
Is something that I should write manually but then, there's nothing about this in the example and I too have no idea how to define entriesListView.
These variables are being created by Visual Studio in a designer file. This is done through the use of the partial keyword, which is a feature in C# that allows you to split a class definition into two or more files.
The designer file will be called Form1.designer.cs in this instance. You can see which controls have been created by opening this file, or, if using Visual Studio, by opening the form in the Visual Studio Designer. To open the designer file in Visual Studio, expand the Form1.cs entry in the Solution Explorer TreeView, and double-click the designer file.
In your code above, the problem appears to be that the entriesListView variable does not exist. It is possible that it was created at one point, and then deleted (this can even happen inadvertently due to Visual Studio bugs). Adding a new ListView to your form and setting the Name property to entriesListView should correct the problem.
Basically what I'm trying to do is I have a string on the main form that pulls its value from a textbox.
I then generate a modal version of a second form and want to have that string (or the main forms textbox1.text value) usable in the second form for processes.
Main Form
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.Diagnostics;
using System.IO;
namespace Tool{
public partial class MainForm : Form
{
public string hostname;
public MainForm()
{
InitializeComponent();
textBox1.Text = hostname;
}
public void btn_test_Click(object sender, EventArgs e)
{
string hostname = textBox1.Text;
SiteForm frmsite = new SiteForm();
frmsite.ShowDialog();
}
}
}
'
Child Form
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.Diagnostics;
using System.IO;
namespace Tool
{
public partial class SiteForm : Form
{
public string hostname {get; set; }
public SiteForm()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
label1.Text = this.hostname;
}
}
}
Any suggestions on how I can do this? I know there has to be a simpler way, sorry I'm still a bit of a noob and am trying to teach myself C# as I go.
The result is when I click the label on the child form it is blank, because of this I am able to deduce that the string isn't passing between the two forms correctly.
The simplest way is to pass it in the constructor of the Child form, for example:
private string _hostname = "";
...
public SiteForm(string hostname)
{
_hostname = hostname;
InitializeComponent();
}
Try hooking into your child form's Load event and set the value of its hostname property in an event handler on your main form.
public void btn_test_Click(object sender, EventArgs e)
{
string hostname = textBox1.Text;
SiteForm frmsite = new SiteForm();
frmsite.Load += new EventHandler(frmsite_Load);
frmsite.ShowDialog();
}
public void frmsite_Load(object sender, EventArgs e)
{
SiteForm frmsite = sender as SiteForm;
frmsite.hostname = this.hostname;
}