0

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?

3
  • Is there a reason for not referencing the library directly? Commented Dec 16, 2016 at 15:23
  • No real reason other than what the vendor recommended doing. Commented Dec 16, 2016 at 15:34
  • 1
    The C# code in fact does reference the library directly, that's why the using directives work. Not actually using it is, well, unwise. But requires dynamic Host and Type.GetTypeFromProgID("BlueZone.LIPI"). IntelliSense still won't show members. Commented Dec 16, 2016 at 15:39

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

You were mostly right! Its actually LipiObj Host = new LipiObj();
@LifeOf0sAnd1s Oh! Wonder why CreateObject("BlueZone.LIPI") worked?
I'm not sure. I'm running into a lot is issues because all of these are embedded in old Auto Hot Key objects with VB6

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.