Dynamic Invoke of Sysmon.OCX Member "AddCounter" via reflection/interop failsCSV to XML, With dynami

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,<br/>
<br/>
running this code to set a property on the hosted Sysmon.ocx ActiveX control and calling a parameterless method works fine:<br/>
<br/>
<pre lang="x-c# using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Reflection;


namespace TestApplication
{
public partial class Form1 : Form
{
private AxHostingControl axHost;
private object ocxObject;

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
ocxObject.GetType().InvokeMember("DisplayProperties", BindingFlags.InvokeMethod, null, ocxObject, null);
}

private void Form1_Load(object sender, EventArgs e)
{
Application.OleRequired();
this.axHost = new AxHostingControl(Type.GetTypeFromProgID("Sysmon",true).GUID.ToString());
this.Controls.Add(this.axHost);
this.ocxObject = axHost.GetOcx();
}

private void button2_Click(object sender, EventArgs e)
{
ocxObject.GetType().InvokeMember("ShowToolbar", BindingFlags.SetProperty, null, ocxObject, new object[] { false });
}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
this.axHost.Dispose();
}

private void button3_Click(object sender, EventArgs e)
{
object[] Parameters = new object[2];
Parameters[0] = "\Process(*)\% Processor Time";
Parameters[1] = new object();

try
{
ocxObject.GetType().InvokeMember("AddCounter", BindingFlags.InvokeMethod, null, ocxObject, Parameters);
}
catch (Exception err)
{
if (err.InnerException is COMException)
{
MessageBox.Show((err.InnerException as COMException).Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);

}
else
{
MessageBox.Show(err.ToString(), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
}
}

internal class AxHostingControl : AxHost
{
public AxHostingControl(
string clsidProgId)
: base(clsidProgId)
{

}
}
}
[/code]
<br/>
<br/>
<br/>
But how do i call "AddCounter" dynamically like the ones above? The given call here fails with E_FAIL. I cant use a wrapper assembly like a Sysmon.interop.dll or something like that. I have to do this at runtime via reflection. Any idea?<br/>
<br/>
Thanks in advance,...<br/>
<br/>
K.<br/>
<
------------------------- Beste GrÃsse / Best regards / Votre bien devoue Kerem GÃmrÃkcà http://entwicklung.junetz.de ------------------------- "This reply is provided as is, without warranty express or implied."<br/> Good Evening,
So essentially what Im attempting to do is to use BizTalk to map between a csv file to an XML file, the problem is the csv file schema can change depending on the document so I cannot seem to just use a pipeline like everyone suggests (you need to specify
the schema, but the schemas are dynamic so it will not let me do that).
My first attempt was to use the dynamic mapping in BizTalk, as thats what were using to do the XML to XML files, but the problem is you seem to need to pass it an XML document or I get a random error about a child having errors. Ive tried wrapping
the CSV in a message as well with no luck.
I attempted to use a pipeline, but short of writing my own pipeline component that will go and figure out the incomming schema, and map to it to create an XML Im not sure how exactly to do this.
Any assistance would be greatly appreciated,
Thank you,
Tony.

View the full article
 
Back
Top