I am deploying a C# application on client machine. The Application need to access code from another program, so it can scrap text from the screen of another application. It is running fine on the development machine but on the client machine it is throwing an error "ActiveX Component cannot create Object" this is where i am getting the error from!
private ExtraSession objExtraSession;
private ExtraSessions objExtraSessions;
private ExtraScreen objExtraScreen;
private ExtraArea objExtraArea;
private ExtraSystem objExtraSystem;
protected void sessionInitializer()
{
try
{
objExtraSystem = (ExtraSystem) Microsoft.VisualBasic.Interaction.CreateObject("Extra.system");
if (objExtraSystem == null)
{
MessageBox.Show("Could not create system");
return;
}
objExtraSessions = objExtraSystem.Sessions;
if (objExtraSessions == null)
{
MessageBox.Show("Could not create sessions");
return;
}
if (!System.IO.File.Exists("C:\\Users\\" + userid + "\\Documents\\Attachmate\\EXTRA!\\Sessions\\SAS.edp"))
{
MessageBox.Show("File does not exist");
return;
}
objExtraSession = (ExtraSession) Microsoft.VisualBasic.Interaction.GetObject("C:\\Users\\"+ userid + "\\Documents\\Attachmate\\EXTRA!\\Sessions\\SAS.edp");
if (objExtraSession == null)
{
MessageBox.Show("Could not create session");
return;
}
if (objExtraSession.Visible == 0)
{
objExtraSession.Visible = 1;
}
objExtraScreen = objExtraSession.Screen;
}
catch (Exception ex)
{
MessageBox.Show(ex.StackTrace, "Failed to initialize Attachmate sessions");
}
}
The error is generated from objExtraSession = (ExtraSession) Microsoft.VisualBasic.Interaction.GetObject("C:\Users\"+ userid + "\Documents\Attachmate\EXTRA!\Sessions\SAS.edp");
Am I missing some step. Please help me out. Thanks in advance.
The most likely explanation is that your development machine has the ActiveX control installed, but the client machine does not. Read the deployment documentation for the control and do what is says is required to deploy to the client machine.
Thanks for all your responses... The method GetObject was creating an object whose activex component was not registered... I resolved by finding the corresponding *.ocx file and calling Regsvr32 on the file this resolved the problem...
Related
I installed ZKtecoFingerprint SDK and I'm trying to run the demo of this SDK but I got this exception!
System.DllNotFoundException: 'Unable to load DLL 'libzkfp.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)'
Exception
References
How can I use the Zketco demo application??
Code :
private void bnInit_Click(object sender, EventArgs e)
{
cmbIdx.Items.Clear();
int ret = zkfperrdef.ZKFP_ERR_OK;
if ((ret = zkfp2.Init()) == zkfperrdef.ZKFP_ERR_OK)
{
int nCount = zkfp2.GetDeviceCount();
if (nCount > 0)
{
for (int i = 0; i < nCount; i++)
{
cmbIdx.Items.Add(i.ToString());
}
cmbIdx.SelectedIndex = 0;
bnInit.Enabled = false;
bnFree.Enabled = true;
bnOpen.Enabled = true;
}
else
{
zkfp2.Terminate();
MessageBox.Show("No device connected!");
}
}
else
{
MessageBox.Show("Initialize fail, ret=" + ret + " !");
}
}
Finally I found the solution. You have nothing to do. You just need to install the driver comes with sdk. I know this is too much late but I am writing this answer if later anyone found the solution. Thanks
Many of these, which connect to devices using SDKs, are 32/64bit related. Change your project configuration to x86 (32bit) and check it again.
I've been working on trying to get scanned data from Motorola MC2180. I know this is basic but I am a beginner and never touched a PDA before. I can get it to scan but the result data is still null. I use the following code:
{
public Symbol.Barcode.Reader SymbolReader = null;
public Symbol.Barcode.ReaderData SymbolReaderData = null;
public static System.EventHandler SymbolEventHandler = null;
/// <summary>
/// MyReaderData property provides access to the ReaderData
/// </summary>
public Symbol.Barcode.ReaderData MyReaderData
{
get { return SymbolReader.GetNextReaderData(); }
}
public static System.EventHandler MyEventHandler
{
get { return SymbolEventHandler; }
set { SymbolEventHandler = value; }
}
public bool InitScanner()
{
try
{
SymbolReader = new Symbol.Barcode.Reader();
SymbolReaderData = new Symbol.Barcode.ReaderData(Symbol.Barcode.ReaderDataTypes.Text, Symbol.Barcode.ReaderDataLengths.MaximumLabel);
SymbolReader.Actions.Enable();
SymbolReader.Parameters.Feedback.Success.BeepTime = 0;
SymbolReader.Parameters.Feedback.Success.WaveFile = "\\windows\\alarm3.wav";
}
catch(Exception ex)
{
ex.ToString();
}
return true;
}
public void TermReader()
{
try
{
if (SymbolReader != null)
{
SymbolReader.Actions.Disable();
SymbolReader.Actions.Dispose();
SymbolReader = null;
}
}
catch (Exception ex)
{
ex.ToString();
}
}
private bool ReadData()
{
{
try
{
// Submit a read
SymbolReader.ReadNotify += SymbolEventHandler;
// Prevent duplicate reads
if (!SymbolReaderData.IsPending)
{
SymbolReader.Actions.Read(SymbolReaderData);
return true;
}
else
return false;
}
catch (Exception ex)
{
ex.ToString();
return false;
}
}
}
public string StopRead()
{
if (SymbolReader != null)
{
try
{
// Flush (Cancel all pending reads)
SymbolReader.ReadNotify -= SymbolEventHandler;
SymbolReader.Actions.Flush();
return "Closed";
}
catch (Exception ex)
{
return ex.ToString();
}
}
else
return "Already Closed";
}
public string ToggleTrigger()
{
this.InitScanner();
SymbolReader.Actions.ToggleSoftTrigger();
this.ReadData();
return SymbolReaderData.Text;
}
}
I tried to use the EMDK support site but it keeps locking me out as its on maintenance.
My main issues are:
1. Getting the data after a scan - I'm not sure how it decodes the barcode data
2. How do I get the scanner to trigger for longer? because I can Barcode2.Config.TriggerMode allows me to scan for longer than Barcode.Reader.ToggleSoftTrigger();
I might need an explanation as I can't access EMDK guide or documentation doesn't help :(
Thank you in advance! :)
Note that Zebra Technologies acquired Motorola Solutions enterprise business in October 2014. This is why I'm talking here about Zebra, even the devices may be branded Motorola or Symbol.
Your best option is to start from the sample application included in the Zebra Technologies' EMDK for .NET, latest one is v2.9 available on Zebra support site. Here's a direct link to that page.
The EMDK and the standalone guide are public software and you are not required to login to download them.
Keep in mind that to use the EMDK to write application for the MC2180, you need VisualStudio 2005 + SP1 or VisualStudio 2008. This are the only two version of the Microsoft development tools supporting Windows CE 6.0. Newer version of Microsoft VisualStudio don't support this operative system.
Try http://support.symbol.com. You need to download the current EMDK from there and install it. With it, you will get a lot of samples where you can try different things. Also a helpfile in the installed EMDK is contained.
I want to make an application - license plate recognition from image. I use OpenCvSharp and Puma.NET.
But when I start my application,writes that the number is not found.
When I use breakpoints - Exception - "Recognition engine halted with code:0"
I loaded three dll - dibapi.dll, puma.net.dll, puma.interop.dll.
Why numbers are not recognized?
public void RecognizePlate() //
{
plateList.Clear();
int i = 1;
foreach(var plateImage in plate)
{
plateList.Add(i.ToString()+ " ) " + RunPuma(plateImage));
i++;
}
}
string RunPuma(IplImage img) //
{
PumaPage Image = new PumaPage(img.ToBitmap());
using (Image)
{
Image.FileFormat = PumaFileFormat.RtfAnsi;
Image.AutoRotateImage = true;
Image.FontSettings.DetectBold = true;
Image.FontSettings.DetectItalic = true;
Image.EnableSpeller = false;
Image.Language = PumaLanguage.English;
try
{
string s = Image.RecognizeToString();
return s;
}
catch(Exception e)
{
return "This is NOT NUMBER";
}
}
return "Error";
}`
You will need to restart Visual Studio as Administrator and you should be able to work then.
The problem is an unsuccessful registration.
According the documentation, apuma.dll component should be registered during the installation. But *.bat file seems to be wrong, at least for my computer.
I solved problem with:
moving all files from Puma.NET\COM Server\Register to Puma.NET\COM Server
open console in Puma.NET\COM Server directory.
Typing this command: regsvr32 APuma.dll
If you get a successful registration message, George is your uncle!!
I am using visual studio 2010 and I am having a .DWG file which I want to open in autocad. Till now I have used this.
Process p = new Process();
ProcessStartInfo s = new ProcessStartInfo("D:/Test File/" + fileName);
p.StartInfo = s;
p.Start();
But what I want is to close the file inside the Autocad but not the autocad itself. (Means atocad.exe should be kept running).
Till now I hve used this but its closing the acad.exe not the file.
foreach (Process Proc in Process.GetProcesses())
{
if (Proc.ProcessName.Equals("acad"))
{
Proc.CloseMainWindow();
Proc.Kill();
}
}
Take the Autocad .NET libraries from Autodesk Sites (http://usa.autodesk.com/adsk/servlet/index?id=773204&siteID=123112)
Then you will be able to use Application and Document classes.
They will give you full control over opening and closing documents within the application.
You can find many articles on that, and can ask further questions.
AutoCAD does have an api. there are 4 assemblys. Two for in-process and two for COM.
inprocess :
acdbmgd.dll
acmgd.dll
COMInterop :
Autodesk.Autocad.Interop.dll
Autodesk.Autocad.Interop.Common.dll
this is a method that will open a new instance of AutoCAD or it will connect to an existing running instance of AutoCAD.
you will need to load these .dlls into your project references.
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;
namespace YourNameSpace {
public class YourClass {
AcadApplication AcApp;
private const string progID = "AutoCAD.Application.18.2";// this is AutoCAD 2012 program id
private string profileName = "<<Unnamed Profile>>";
private const string acadPath = #"C:\Program Files\Autodesk\AutoCAD 2012 - English\acad.exe";
public void GetAcApp()
{
try
{
AcApp = (AcadApplication)Marshal.GetActiveObject(progID);
} catch {
try {
var acadProcess = new Process();
acadProcess.StartInfo.Arguments = string.Format("/nologo /p \"{0}\"", profileName);
acadProcess.StartInfo.FileName = (#acadPath);
acadProcess.Start();
while(AcApp == null)
{
try { AcApp = (AcadApplication)Marshal.GetActiveObject(progID); }
catch { }
}
} catch(COMException) {
MessageBox.Show(String.Format("Cannot create object of type \"{0}\"",progID));
}
}
try {
int i = 0;
var appState = AcApp.GetAcadState();
while (!appState.IsQuiescent)
{
if(i == 120)
{
Application.Exit();
}
// Wait .25s
Thread.Sleep(250);
i++;
}
if(AcApp != null){
// set visibility
AcApp.Visible = true;
}
} catch (COMException err) {
if(err.ErrorCode.ToString() == "-2147417846"){
Thread.Sleep(5000);
}
}
}
}
}
closeing it is as simple as
Application.Exit();
and forgive the code. its atrocious, this was one of my first methods when i just started developing...
I doubt you will be able to do this unless AutoCAD has an API that you can hook into and ask it to close the file for you.
Your c# app can only do things to the process (acad.exe) , it doesn't have access to the internal operations of that process.
Also, you shouldn't use Kill unless the process has become unresponsive and certainly not immediately after CloseMainWindow.
CloseMainWindow is the polite way to ask an application to close itself. Kill is like pulling the power lead from the socket. You aren't giving it the chance to clean up after itself and exit cleanly.
There is one other possibility - this will only work if your C# code is running on the same machine as the AutoCAD process and it is not really recommended, but, if you are really stuck and are prepared to put up with the hassle of window switching you can send key strokes to an application using the SendKeys command.
MSDN articles here:
http://msdn.microsoft.com/EN-US/library/ms171548(v=VS.110,d=hv.2).aspx
http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.send.aspx
Using this you could send the key strokes to simulate the user using the menu commands to close the file.
To perform the closing of file, best way out is to follow the steps at this ObjectARX SDK for c# and change the following code with the below code.
[CommandMethod("CD", CommandFlags.Session)]
static public void CloseDocuments()
{
DocumentCollection docs = Application.DocumentManager;
foreach (Document doc in docs)
{
// First cancel any running command
if (doc.CommandInProgress != "" &&
doc.CommandInProgress != "CD")
{
AcadDocument oDoc =
(AcadDocument)doc.AcadDocument;
oDoc.SendCommand("\x03\x03");
}
if (doc.IsReadOnly)
{
doc.CloseAndDiscard();
}
else
{
// Activate the document, so we can check DBMOD
if (docs.MdiActiveDocument != doc)
{
docs.MdiActiveDocument = doc;
}
int isModified =
System.Convert.ToInt32(
Application.GetSystemVariable("DBMOD")
);
// No need to save if not modified
if (isModified == 0)
{
doc.CloseAndDiscard();
}
else
{
// This may create documents in strange places
doc.CloseAndSave(doc.Name);
}
}
}
I am using p4.net API to generate some reports from the metadata.
In one of the reports, I need to generate then number of the changes lines for each changeset report.
As a reporting tool, I am using MS SQL Reporting services 2008, and I have written a custom dll that uses p4.net API to calculate the number of changed lines. it works on the local without any problem. However, when I run the code on the server, it calculates let's say first %20 part then starts throwing Unable to connect to the Perforce Server!
Unable to connect to Perforce! exception.
I try same credentials on the local, it works.. I use commandline with same credentials on the server, it works.
Could anyone help me with that please, if encountered before?
Here is the code I use. If needed
public static class PerforceLib
{
public static P4Connection p4conn = null;
private static void CheckConn()
{
try
{
if (p4conn == null)
{
p4conn = new P4Connection();
p4conn.Port = "address";
p4conn.User = "user";
p4conn.Password = "pwd*";
p4conn.Connect();
p4conn.Login("pwd");
}
else if (p4conn != null)
{
if(!p4conn.IsValidConnection(true, false))
{
Log("Check CONN : Connection is not valid, reconnecting");
p4conn.Login("pwd*");
}
}
}
catch (Exception ex )
{
Log(ex.Message);
}
}
public static int DiffByChangeSetNumber(string ChangeSetNumber)
{
try
{
CheckConn();
P4Record set = p4conn.Run("describe", "-s",ChangeSetNumber)[0];
string[] files = set.ArrayFields["depotFile"].ToArray<string>();
string[] revs = set.ArrayFields["rev"].ToArray<string>();
string[] actions = set.ArrayFields["action"].ToArray<string>();
int totalChanges = 0;
List<P4File> lstFiles = new List<P4File>();
for (int i = 0; i < files.Count(); i++)
{
if (actions[i].ToString() == "edit")
lstFiles.Add(new P4File() { DepotFile = files[i].ToString(), Revision = revs[i].ToString(), Action = actions[i].ToString() });
}
foreach (var item in lstFiles)
{
if (item.Revision != "1")
{
string firstfile = string.Format("{0}#{1}", item.DepotFile, (int.Parse(item.Revision) - 1).ToString());
string secondfile = string.Format("{0}#{1}", item.DepotFile, item.Revision);
P4UnParsedRecordSet rec = p4conn.RunUnParsed("diff2", "-ds", firstfile, secondfile);
if (rec.Messages.Count() > 1)
{
totalChanges = PerforceUtil.GetDiffResults(rec.Messages[1].ToString(), item.DepotFile);
}
}
}
GC.SuppressFinalize(lstFiles);
Log(string.Format("{0} / {1}", ChangeSetNumber,totalChanges.ToString() + Environment.NewLine));
return totalChanges;
}
catch (Exception ex)
{
Log(ex.Message + Environment.NewLine);
return -1;
}
}
}
your help will be appreciated
Many thanks
I have solved this issue. we identified that the code is circling through the ephemeral port range in around two minutes. once it reaches the maximum ephemeral port, it was trying to use same port again. Due to each perforce command creates a new socket, available ports were running out after it processed about 1000 changesets.
I have set the ReservedPorts value of HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters default(1433,143) that gave me larger range of ephemeral port.
and also implemented singleton pattern for P4Conn which helped as I dont close the connection. I only check the validity of the connection, and login if the connection is not valid.
Please let me know if any of you guys needs any help regarding this