locked
Trapped between VB and C# How to use a .dll RRS feed

  • Question

  • I have a dll registered with regasm, that I need to call from ancient program written in Sumerian Cuneiform. Ok, I exaggerate, it's Clarioneese.

    The extremely sketchy instructions for this dll are in VB. The instructions for making a com object I can call in Clarion are in C#. I HAVE successfully used VS 2008 to make a dll that I register with regasm and called this from Clarion, calling methods, setting and examining properties. Pretty cool, eh? Apparently it's also possible to make code in Clarion that VS can use, but I'm not worried about that for now.

    So now, I find myself trying to translate between VB and C#, using a copy of "Beginning Ancient Hebrew" for a reference. Of course, I speak English and Clarioneese fluently, and read VB with the help of many references. Most of these references send me down rabbit trails.

    So, a VB line looks like: 

    [code]
    Private WithEvents Charge AS NEW Sim.Charge("a param","another Param")
    [/code]

    How do you translate this to C#?

    Or

    [code]
    Private Sub SomethingStrange() Handles Charge.CardSwipe
    [/code]

    Help! I'm drowning in reference material!



    You can't be successful at this unless you're at least 1/2 a bubble off level.
    Thursday, March 4, 2010 6:10 PM

Answers

  • Hi Halfbubble,

    The line of VB code is creating a new object of type Sim.Charge with some parameters. (That bit's easy). The WithEvents keyword specifies that the object can generate events and they will be handled by various methods. The Charge.CardSwipe event is then handled by the SomethingStrange method. The wiring between the two is created automatically by VB when the Handles keyword is used.

    In C# you'll need to specify this event wiring explicitly:

    private Sim.Charge myCharge = new Sim.Charge("a param", "another Param");
    myCharge.CardSwipe += new Charge.CardSwipeHandler( SomethingStrange );
    
    private void SomethingStrange()
    {
    }
    or something similar.
    • Marked as answer by Halfbubble Friday, March 5, 2010 4:06 PM
    Friday, March 5, 2010 3:32 PM

All replies


  • =============================== private System.Windows.Forms.Button button1; == Friend WithEvents Button1 As System.Windows.Forms.Button =============================== =============================== button1.Click += new System.EventHandler(this.button1_Click); private void button1_Click(object sender, EventArgs e) {} == Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click End Sub ===============================


    jon.stromer.galley
    Thursday, March 4, 2010 6:31 PM
  • Hi Halfbubble,

    The line of VB code is creating a new object of type Sim.Charge with some parameters. (That bit's easy). The WithEvents keyword specifies that the object can generate events and they will be handled by various methods. The Charge.CardSwipe event is then handled by the SomethingStrange method. The wiring between the two is created automatically by VB when the Handles keyword is used.

    In C# you'll need to specify this event wiring explicitly:

    private Sim.Charge myCharge = new Sim.Charge("a param", "another Param");
    myCharge.CardSwipe += new Charge.CardSwipeHandler( SomethingStrange );
    
    private void SomethingStrange()
    {
    }
    or something similar.
    • Marked as answer by Halfbubble Friday, March 5, 2010 4:06 PM
    Friday, March 5, 2010 3:32 PM