CX25 ActiveX control in .Net windows service - c#

I have a CX25 coin dispenser ActiveX provided with test application from client (developed by unknow technology) and need to drive coin dispenser through .Net technology using Win service or API. Successfuly added the COM reference and included the namespace and created the object( See below code reference).
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CX25Lib;
namespace CX25HIDUSB
{
class Program
{
static void Main(string[] args)
{
try
{
var cx25 = new CX25();
Console.WriteLine(cx25.AmountDispensed);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
While accessing "cx25.AmountDispensed" OR any other properties ,got error like "Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))"
Please it kills my time and looking for real help OR suggestion to handle it in different way here.

Related

System.InvalidProgramException Error C# when creating CIMSession

Trying to remotly connect to another PC's WMI but when creating the CimSession I get the following error
System.InvalidProgramException:'Common Launguage Runtime detexted an invalid program'
The code I am running is as follows
using System;
using System.Text;
using System.Threading;
using Microsoft.Management.Infrastructure;
using Microsoft.Management.Infrastructure.Options;
using System.Security;
namespace SMAPIQuery
{
class Program
{
static void Main()
{
string computer = "ComputerB";
DComSessionOptions DComOptions = new DComSessionOptions();
DComOptions.Impersonation = ImpersonationType.Impersonate;
CimSession Session = CimSession.Create(computer, DComOptions);
}
}
}
Unsure as to what throws this error or how to get around it
The issue was I was using .Net Core and not .Net Framework

Opening a web page from a C# console app

i'm new in C# programming so I beg your pardon. I just tried the solution proposed in a previous question, but it didn't work. By the way I stil need help.
I'm trying to write a simple consolle app in C# that opens a web page, aka http://www.libero.it.
Here you are my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
class OpenWeb {
static void Main(string[] args) {
var prs = new ProcessStartInfo("chrome.exe");
prs.Arguments = "http://www.libero.it";
// Process.Start(prs);
try
{
Process.Start(prs);
}
catch (System.ComponentModel.Win32Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
I don't understand why my code doesn't work, there is always an exeception, without the try-catch is the following:
Unhandled Exception: System.ComponentModel.Win32Exception: The specified file
could not be found
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo
startInfo)
at System.Diagnostics.Process.Start()
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at OpenWeb.Main(String[] args) in C:\Users\p3rtp\myProve\Prove.cs:line 12
I use Windows 7x64, with .Net core sdk 2.1.301 e MS Visual Studio Code 1.24.1.
I've been using this line to launch the default browser:
System.Diagnostics.Process.Start("http://www.google.com");
The code is really simple as below:
using System
using System.Collections.Generic
using System.Text
using System.Diagnostics
namespace example
{
class examp
{
static void Main(string[] args)
{
Process.Start("http://www.google.com");
}
}
}
Ok, I found the right answer:
var prs = new ProcessStartInfo(#"C:\Program Files
(x86)\Google\Chrome\Application\chrome.exe");
The problem isn't the Path, but in the app or folder: just the quotes with "#" before the full path of chrome I finally managed to solve the problem.
Thanks to all anyway.

How can i scan and list all connected devices to my network wireless, i'm getting exception?

My pc is connected to the router of the network i want to scan but the not wireless the pc is connected with a cable to the router.
But my android device is connected to the network wireless.
So in logic in this case the results in the list should be my pc and my android device.
This is what i'm using now managed wifi api:
managed wifi api
This is my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using NativeWifi;
namespace ScanWifi
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
WlanClient client = new WlanClient();
try
{
foreach (WlanClient.WlanInterface wlanIface in client.Interfaces)
{
Wlan.WlanBssEntry[] wlanBssEntries = wlanIface.GetNetworkBssList();
foreach (Wlan.WlanBssEntry network in wlanBssEntries)
{
int rss = network.rssi;
byte[] macAddr = network.dot11Bssid;
string tMac = "";
for (int i = 0; i < macAddr.Length; i++)
{
tMac += macAddr[i].ToString("x2").PadLeft(2, '0').ToUpper();
}
listView1.Items.Add("Found network with SSID {0}." + System.Text.ASCIIEncoding.ASCII.GetString(network.dot11Ssid.SSID).ToString());
listView1.Items.Add("Signal: {0}%."+ network.linkQuality);
listView1.Items.Add("BSS Type: {0}."+ network.dot11BssType);
listView1.Items.Add("MAC: {0}.", tMac);
listView1.Items.Add("RSSID:{0}", rss.ToString());
}
Console.ReadLine();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
When running the program i'm exception on WlanApi.cs on the line:
Wlan.ThrowIfError(
Wlan.WlanOpenHandle(Wlan.WLAN_CLIENT_VERSION_XP_SP2, IntPtr.Zero, out negotiatedVersion, out clientHandle));
System.ComponentModel.Win32Exception' occurred in ManagedWifi.dll
The service has not been started
For Windows 10, the service "WLAN AutoConfig" must be started for WlanClient to work. This service should be started automatically on a computer which has a WiFi adapter present. On a computer such as a desktop which does not have a WiFi adapter, the service startup type is probably Manual and not started; you can start it anyway and WlanClient should no longer throw any exceptions, but without a WiFi adapter, it won't see any interfaces, so you won't be able to get a list of networks.
According to the documentation of the [WlanOpenHandle ][1] function, the problem is that the Wireless Zero Configuration (WZC) service is not started on your machine:
WlanOpenHandle will return an error message if the Wireless Zero Configuration (WZC) service has not been started or if the WZC service is not responsive.
However, depending on your platform, it might also might be the case that you are simply passing the wrong parameters to the WlanOpenHandle function. Have you tried passing Wlan.WLAN_CLIENT_VERSION_LONGHORN as the first parameter?

Running Python Script/application in Windows Phone 8

I want to run the Skeinforge slicer program written in Python inside my Windows Phone 8 C# application. I have determined that I should probably use IronPython to do this, I have already determined that I can run Skeinforge inside the ipy.exe terminal I got when I installed IronPython. My problem though is that I am struggling to figure out how to host and run a Python script with IronPython inside Windows Phone 8. I have also already managed to get a simple hello world script running inside a Desktop Windows Forms application that transfers the applications console output to the Debug console with the following code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
DebugWriter debugW = new DebugWriter();
Console.SetOut(debugW);
}
private void button1_Click(object sender, EventArgs e)
{
TextWriter tw = new StreamWriter("Test.py");
tw.Write(scriptBox.Text);
tw.Close();
try
{
var ipy = Python.CreateRuntime();
dynamic test = ipy.UseFile("Test.py");
}
catch (Exception ex)
{
Debug.WriteLine("Error: " + ex.Message);
}
}
}
}
And this is the DebugWriter:
class DebugWriter : TextWriter
{
private StringBuilder content = new StringBuilder();
public DebugWriter()
{
Debug.WriteLine("Writing console to debug");
}
public override void Write(char value)
{
base.Write(value);
if (value == '\n')
{
Debug.WriteLine(content.ToString());
content = new StringBuilder();
}
else
{
content.Append(value);
}
}
public override Encoding Encoding
{
get { return System.Text.Encoding.UTF8; }
}
}
I have no idea how to even add the IronPython libraries to my Windows Phone 8 application though as the standard libraries won't import. I have though tried compiling the apparently now defunct Windows Phone 7 libraries with the master source code and I can import these libraries, but I get absolutely no response on the debug terminal when I try to run my hello world script.
Do any of you have any idea how to get this woring in Windows Phone 8, if you know how to do this in Windows 8/Metro/RT then that would also probably work for WP8.
UPDATE:
I have looked at the debug output again and I seem to get this error when trying to use the WP7 libraries to run a hello world script:
A first chance exception of type 'System.NotImplementedException' occurred in Microsoft.Scripting.DLL
Error: The method or operation is not implemented.
I managed to get Skeinforge running on a modified version of IPY. You can get the source for my application here: http://skeinforgewp8.codeplex.com/

JavaScript and C# Interpolation using Microsoft.JScript

How can I add a C# object to JavaScript code?
using System;
using System.Collections.Generic;
using System.Text;
using System.CodeDom.Compiler;
using System.Reflection;
using Microsoft.JScript;
using Microsoft.JScript.Vsa;
using Microsoft.Vsa;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Program program = new Program();
program.Run();
}
public object Run()
{
VsaEngine Engine = VsaEngine.CreateEngine();
object Result = null;
try
{
//Engine.PushScriptObject(new ScriptObject());
// C# object replace with ?
Result = Eval.JScriptEvaluate("var a = 1; var b = c# object", Engine);
}
catch (Exception ex)
{
return ex.Message;
}
return Result;
}
}
}
Just compile your C# object into an assembly and load that assembly in your jscript code. all the languages that .NET supports can load each other's assemblies.
You can take a look at Script#
As they say,
"Script# brings the power and productivity of C# and .NET tools to Ajax development by compiling C# source code into regular JavaScript."

Categories

Resources