Video Screencast Help

PCA 12.5 and OLE Automation in .NET

Created: 25 Jul 2010 • Updated: 24 Mar 2011 | 2 comments
This issue has been solved. See solution.

I'm trying to build an application that at one point works as an OLE client for PCAnywhere 12.5.

The problem I'm having is importing the two TLB files that come with PCA into a .net project. If I try to add the files directly as a reference in my project through the solution explorer I get the error:

---------------------------
Microsoft Visual Studio
---------------------------
A reference to 'E:\Dev\PcaOle\awrem32.tlb' could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component.
---------------------------
Aceptar
---------------------------

I get this error try to add any of the two files.

I also tried creating DLL's for the files using Tlbimp and this way I managed to add these to the .net project just fine. I wrote the following code:

CRemoteDataManager mng = new CRemoteDataManager();
RemoteDataEx data = null;
data = (RemoteDataEx)mng.RetrieveObjectEx("temp.chf", (short)2, null);
if (data == null)
data = (RemoteDataEx)mng.CreateObjectEx("temp.chf");
data.ConnectionType = "TCP/IP";
data.PhoneNumber = host.IP;
data.AutoLoginName = host.user;
data.AutoDomain = host.domain
data.WriteProtection = false;
data.WriteObject(null);
DocumentClass doc = new DocumentClass();
doc.awConnect("temp.chf");

all these classes are from the DLLS. problem is I get an excpetion on ANY method call i make on the objects. for example on the first line, if I leave the DLL references' option Ember Interop Types as true i get an InvalidCastException:

Unable to cast COM object of type 'System.__ComObject' to interface type 'winawsvr.CRemoteDataManager'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{82A1A806-8BA9-11CF-B95F-00A02412C812}' failed due to the following error: Interfaz no compatible (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

if I set that option to false it doesn't fail until the third line also with an InvalidCastException:

Unable to cast COM object of type 'winawsvr.CRemoteDataManagerClass' to interface type 'winawsvr.IRemoteDataManager'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{82A1A806-8BA9-11CF-B95F-00A02412C812}' failed due to the following error: Interfaz no compatible (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

I'm stuck.

The weird thing is if I do:

if (mng is IRemoteDataManager)
data = (RemoteDataEx)mng.RetrieveObjectEx("temp.chf", (short)2, null);

the if statement validates to true, but then the next line still fails.
Has anyone had any luck with this?

Comments 2 CommentsJump to latest comment

Screenbert's picture

I've been hitting my head against a similair problem for the last week. This has to do with the fact the C# does late binding where as C++ and VB do not. I found a way around this and I'll post an article soon describing it.

Screenbert

Screenbert's picture

This article explains why you are getting the above error and at the end of the article is a link to the DLL you can use to skip this error. It also shows the basic code you need to create your own custom DLL.

https://www-secure.symantec.com/connect/articles/using-c-and-symantec-pcanywhere-ole-automation?om_ext_cid=biz_con_cmgr_cp_20110322_pm

Screenbert

SOLUTION