LifeOf0sAnd1s
LifeOf0sAnd1s

Reputation: 113

Properly Setting an instance of a COM Object in C#

I have a VB based block of code I need to rewrite in C# and I'm writing a function which creates an instance of a COM object and creates a new terminal session, goes out, reads a screen and returns the contents of the screen. Right now though I feel like I'm not taking the right approach in C# and would appreciate some feedback.

VB Code

set bzlipi = CreateObject("BlueZone.LIPI")
bzlipi.Username = "myuserid"
bzlipi.Password = "mypassword"
bzlipi.HostAddress = "101.122.0.138"
bzlipi.ShowTransferStatusWindow = False
bzlipi.LocalPromptBeforeOverwrite = False
result = bzlipi.ReceiveFile( "local.txt", "MYLIB/F4101" )
MsgBox bzlipi.ErrorMessage

C#

    using BZLIPILib;
    using BZWHLLLib;

    public void Connector() {
    object Host = Activator.CreateInstance(Type.GetType("BZLIPILib.LIPI"));
    //Set Host properties
    }

As it stands, this is not not recognizing any properties within Host as its
VB counterpart does above. I've made all the available COM object
references within package manager of my VS project. What should I be
doing differently?

Upvotes: 0

Views: 495

Answers (1)

user585968
user585968

Reputation:

Change:

using BZLIPILib;
using BZWHLLLib;
...
object Host = Activator.CreateInstance(Type.GetType("BZLIPILib.LIPI"));

...to:

using BZLIPILib;
using BZWHLLLib;
...

LIPI Host = new LIPI();

...then intellisense will work as expected.

Update: It appears that the actual code required is:

using BZLIPILib;
using BZWHLLLib;
...

LipiObj Host = new LipiObj(); 

...as per OP's comment below.

Upvotes: 2

Related Questions