I'm trying to use MSWinSock in C# 2008, but it doen't work.
I keep on getting this Exception:
System.Runtime.InteropServices.COMException (0x80040112): Het maken van een exemplaar van het COM-onderdeel met CLSID {248DD896-BB45-11CF-9ABC-0080C7E7B78D} uit de IClassFactory is mislukt door de volgende fout: 80040112.
I use this as my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MSWinsockLib;
using Info.Kernel.Logging;
namespace InfoEmu.Kernel.OldSock
{
public class WinSockListener
{
private WinsockClass Winsock;
private WinsockClass[] Clients = new WinsockClass[1000];
public WinSockListener(int port)
{
try
{
Winsock = new WinsockClass();
Winsock.LocalPort = port;
Winsock.Listen();
}
catch (Exception e)
{
Cout.WriteLine("[ERROR!] {0} {1}", Environment.NewLine, e);
}
}
}
}
I've looked for a long time without good solution. Please help.
0x80040112 CLASS_E_NOTLICENSED "Class is not licensed for use". The error suggests that COM class requires a design-time license. See details here: Licensing ActiveX Controls - Design-Time Licensing. That is you need either a license for this control, or an alternate (and perhaps a better) solution to implement sockets.
Related
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.
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.
I am using Unity 3D for an application I need to use Serial Port but in Unity, there's a missing implementation of event DataReceived and others linked functions.
Therefore I think the solution is to make my own DLL that can manage Serial Port data and call it from unity as an external DLL.
I wrote the code below. the code in my class library project (just a serial port froze opening for the test)
Code:
using System;
using System.IO.Ports;
namespace serialPortManager2
{
public class laserManager
{
private SerialPort laserComPort;
public bool open()
{
bool laserSerialPortDetected = false;
// ouverture du port série pour pilotage du laser
foreach (string portName in SerialPort.GetPortNames())
{
if (portName == "COM4") laserSerialPortDetected = true;
}
if (laserSerialPortDetected)
{
laserComPort = new SerialPort("COM4", 9600, Parity.None, 8, StopBits.One);
laserComPort.Open();
if (laserComPort.IsOpen)
{
// timeout de lecture d'une mesure laser
laserComPort.ReadTimeout = 5000;
return true;
}
else return false;
}
else return false;
}
}
}
Code to reference DLL in Unity:
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;
public static class SPNativePlugIn {
// The name of the external library containing the native functions
private const string LIBRARY_NAME = "serialPortManager2";
[DllImport(LIBRARY_NAME)] public static extern bool open();
}
My problem is that I get this error: EntryPointNotFoundException: open
I guess I have to integrate the laserManager class somewhere but I do not know the syntax, I tried quite a few things but I can not find it.
Create a folder named "Plugins" in the "Assets" Folder then put your .dll file in the "Plugins" folder and import it in your script in this way
using dllFileName;
This works for every .dll not include in the unity default library
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?
I am trying to connect to R from c# using the following code. It looks like C# is not reading the R dll files. My R installation directory is this:
C:\Users\R-2-13\R-2.13.0\bin\i386
and I also downloaded and put the R.NET.dll in the same directory. In Visual Studio, I set the reference to R.NET.dll file. When I run the following code, the code goes the the catch section "unable to find the R Installation". Any ideas? Has anybody got this working?
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 RDotNet;
namespace RNet_Calculator
{
public partial class Form1 : Form
{
// set up basics and create RDotNet instance
// if anticipated install of R is not found, ask the user to find it.
public Form1()
{
InitializeComponent();
bool r_located = false;
while (r_located == false)
{
try
{
REngine.SetDllDirectory(#"C:\Users\R-2-13\R-2.13.0\bin\i386");
REngine.CreateInstance("RDotNet");
r_located = true;
}
catch { MessageBox.Show(#"Unable to find R installation's \bin\i386 folder. Press OK to attempt to locate it.");
MessageBox.Show("error");
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
This is http://rdotnet.codeplex.com/ (RDotNet) to develop Winform applications. While I know Shiny and all the other Web-like R-tools quite well, the combination of c# and R still is my preferred end-user combinations. Try simple things like disabling buttons with Shiny...
Too bad rdotnet is quite buggy; in the current version, it crashes on R exeptions, even in try-catched ones.
This said: please make absolutely sure that you use version 1.5, not the stupidly called "stable" (=early beta) version on the page. Best download it via NuGet. Also check if you did not mix 32bit R with 64 bit c#.
Using the Helper-functions of 1.5, initialization is:
Helper.SetEnvironmentVariables();
engine = REngine.CreateInstance(EngineName);
engine.Initialize();
# Assuming you want to catch the graphic window, use my RGraphAppHook
# on the rdotnet site http://rdotnet.codeplex.com/workitem/7
cbt = new RGraphAppHook { GraphControl = GraphPanelControl };