Interop with VC dlls

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • swapna_munukoti@yahoo.co.in

    Interop with VC dlls

    Hi all,

    I am new to .net and that c#. I am currently working for a project
    that includes migration from vb6 application to c#.

    VB6 application communicates with a modules developed in VC++.

    Now, the same logic I am trying with c#. That is c# application to
    interact with VC++ modules.

    I have 2 VC++ dlls, like m1 and m2, in which I used to interact with
    class c1 in m1 and class c2 in m2.
    something like m1.c1, m2.c2...
    In m2.c2, there are functions that needs parameters (byref) of type
    ic1.
    where ic1 interface which includes all the definitions of m1.c1

    Now the current vb6 application passes parameters of type m1.c1 to the
    functions in m2.c2 and it is working fine.

    But when tried to write the same in c#, it is throwing an error. It is
    expecting only parameters of type ic1 interface...

    Why is it so? Wont there be any other way to pass that argument of
    m1.c1 type????

    Thanks,
    Swapna.

  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Interop with VC dlls

    Swapna,

    In VB6, the only way you would be able to work with objects written in
    VC++ is through calls to API functions, or through COM. This is the same
    way that .NET deals with unmanaged code (although in a much better manner,
    IMO). From your post, I can't tell which you are doing.

    Can you show some VB6 code in which you are calling your objects?


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    <swapna_munukot i@yahoo.co.inwr ote in message
    news:1180521752 .904809.200820@ o11g2000prd.goo glegroups.com.. .
    Hi all,
    >
    I am new to .net and that c#. I am currently working for a project
    that includes migration from vb6 application to c#.
    >
    VB6 application communicates with a modules developed in VC++.
    >
    Now, the same logic I am trying with c#. That is c# application to
    interact with VC++ modules.
    >
    I have 2 VC++ dlls, like m1 and m2, in which I used to interact with
    class c1 in m1 and class c2 in m2.
    something like m1.c1, m2.c2...
    In m2.c2, there are functions that needs parameters (byref) of type
    ic1.
    where ic1 interface which includes all the definitions of m1.c1
    >
    Now the current vb6 application passes parameters of type m1.c1 to the
    functions in m2.c2 and it is working fine.
    >
    But when tried to write the same in c#, it is throwing an error. It is
    expecting only parameters of type ic1 interface...
    >
    Why is it so? Wont there be any other way to pass that argument of
    m1.c1 type????
    >
    Thanks,
    Swapna.
    >

    Comment

    • swapna_munukoti@yahoo.co.in

      #3
      Re: Interop with VC dlls

      VB6 code is like this

      Dim objDataWrapper as DataWrapper.DWr apper
      Dim objFrameWorkWra pper as FrameWork.clsFr ameWork

      public function getData() as long

      objDataWrapper = new DataWrapper.DWr apper
      objFrameWorkWra pper = new FrameWork.clsFr ameWork

      getData = objFrameWorkWra pper.getData(ob jDataWrapper)

      end function

      In c#, objFrameWorkWra pper.getData() function is expecting the
      parameter as IDDataWrapper, which is an interface of
      DataWrapper.DWr apper in FrameWork dll.
      And if I am trying to create an object of type IDDataWrapper, it is
      throwing an error stating "Instance cannot be created for abstract
      class or interface".

      In Vb6 also, it was expecting the the parameter as IDDataWrapper. But
      then if I pass an object of type DataWrapper.DWr apper, it is allowing
      and functioning correctly.

      What shall I need to do, to achieve the functionality I am expecting.

      Thanks,
      Swapna.

      Comment

      • swapna_munukoti@yahoo.co.in

        #4
        Re: Interop with VC dlls

        And forgot to mention, its VC++ com dll

        Comment

        • swapna_munukoti@yahoo.co.in

          #5
          Re: Interop with VC dlls

          Hi all,

          I found the solution for my problem in some trial n error.

          In c# I have declared the variable as,

          FrameWork.Inter nfaceName objDataWrapper;

          objDataWrapper = (FrameWork.Inte rnfaceName) new
          DataWrapper.DWr apper();

          I dont know whether it is correct or not. But it is working fine for
          me.

          Regards,
          Swapna.

          Comment

          Working...