none
Structure Basic to work with Interoperability

    Pertanyaan

  • Folks


        I would like to know what would be the basic way of working with interoperability in the question of structure and even the question of compilation?
        Because I'm thinking of creating just one form in .dot (using vb.net or C #) and use it inside vb 6, this is using interoperability.
        If anyone knows anything that can send me, I will be very grateful, because there I can exchange some information based on some that I already research only that I am in doubt of the basic structure.

    Sabtu, 08 September 2018 20.43

Jawaban

  • Hello neibala,

    1. I am making a guess here :

    - I think that as you are writing your client as a VB6 program, you want to be able to create your COM-Visible C#/VB.NET object in VB6 code.

    - You may be wondering how to instantiate your COM visible C#/VB.NET class via the class' GUID in VB6 code.

    2. If my guess above is correct, then one relatively simple way to instantiate your C#/VB.NET class is to use the CreateObject() VB function and using a ProgID instead of using a GUID.

    3. First off, make sure that your C#/VB.NET class has the ProgIdAttribute :

    [ComVisible(true)]
    [Guid("...")]
    [ProgId("MyServer.MyClass")]
    public class MyClass
    {
       ...
    }

    - Note the ProgIdAttribute and the string value for it.

    - This ProgId value will be associated with the class' GUID (also known as its CLSID).

    4. In your VB6 code, you instantiate the class using the CreateObject() function :

    Dim m_MyClass As Object
    
    Set m_MyClass = CreateObject("MyServer.MyClass")

    5. When the above VB6 code is run, the VB6 runtime engine will lookup the registry for a ProgId entry named "MyServer.MyClass". Then the CLSID associated with the ProgId is looked up from the registry and then used to instantiate the C#/VB.NET component.

    6. Note that the CLSID (a 16-byte) numeric value will be universally unique. The ProgID (a string) may not be universally unique but needs to be unique to the local machine.

    7. Hope this helps.

    - Bio.


    Please visit my blog : http://limbioliong.wordpress.com/


    • Diedit oleh Lim Bio Liong Jumat, 21 September 2018 03.16 Typo error.
    • Ditandai sebagai Jawaban oleh neibala Rabu, 17 Oktober 2018 01.20
    Senin, 17 September 2018 17.12

Semua Balasan

  • I can't quite tell what you're asking; you've mixed a lot of concepts.  Are you trying to embed some code into a Word document, and then trigger that code within a VB 6 application?  Which version of Word?

    And are you aware that VB 6 is literally a 20-year-old product?  Development tools do not age like wine, they age like milk.  Badly.


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Senin, 10 September 2018 05.08
  • Tim Roberts / Group

         Since I want to thank you for your attention in this matter, on the issue of using interoperability, I would create a form inside Visual Studio (where it could be using vb.net or C #) and then be used inside vb6.
         For the project that I am participating in, we are trying to migrate slowly.
         So I need to know a basic structure on the interoperability issue.

       

    Selasa, 11 September 2018 23.43
  • Hello neibala,

    1. The only way to accomplish this (with VB6.0) is to use COM Interop.

    2. You would need to create a COM-visible class in VB.Net or C# and produce a .Net assembly.

    2.1 After that, you will need to register the assembly using regasm.exe.

    2.2 As part of calling regasm.exe, a COM type library will be produced.

    2.3 In VB6.0, reference this type library.

    2.4 In VB6.0 code, call a method of the managed class to display the managed form.

    3. For more detailed instructions on this, see :

    Creating a COM Server Using C#

    - Bio.


    Please visit my blog : http://limbioliong.wordpress.com/


    • Diedit oleh Lim Bio Liong Rabu, 12 September 2018 08.20 Typo error.
    Rabu, 12 September 2018 03.53
  • Lim Bio / Group

       

      As I have been studying this subject for months and talking to several friends, colleagues and group.
     What I am looking for would be the basic structure that would   of interoperability, where your link, your blog and your explanation helped a lot to validate what I have so far.

      But based on your data, would I need to use TLBIMP.EXE or TlbExp?

      What about the compilation issue, do I really need to use the / codebase parameter when using regasm.exe?

      I would need to use Strong Names (snk) to have a more secure registry inside windows, so in this case how should I proceed?

    And as I will be using Visual Basic 6 or even another environment (VBA) that is not unmanageable and as within Visual Studio (.NET) the data is manageable, what would be the recommendations and tip that you would indicate or should I take based on your knowledge   to avoid future problems?

    And you would have some example or tip, where based on its structure I would be creating a form inside Visual Studio, using (C # or vb.net) and then using it inside Visual Basic or another environment so that I can compare and clear the doubts of what I have been studying
    until now ?

    Your link:
      https://limbioliong.wordpress.com/2011/08/30/creating-a-com-server-using-c/
    
    
      And a link that helped me a lot because of his didactic was the below:
      https://www.youtube.com/watch?v=Mhflq38d3CU&index=5&list=LLQ9Rslfg579yURKn5ZnZchQ&t=0s
    

      

        

         

    Kamis, 13 September 2018 20.25
  • Hello neibala,

    1. >> But based on your data, would I need to use TLBIMP.EXE or TlbExp?

    - There is no need to use either one.

    2. >> What about the compilation issue, do I really need to use the / codebase parameter when using regasm.exe?

    - If you want to store the assembly in the GAC (global assembly cache), then there is no need to use /codebase.

    - If you do not store the assembly in the GAC, then /codebase will be a necessity in order that your VB6.0 client be able to locate the assembly at runtime.

    3. >> I would need to use Strong Names (snk) to have a more secure registry inside windows, so in this case how should I proceed?

    - Strong names will be required if you store your assembly in the GAC.

    - Othewise no need for strong names.

    4. >> what would be the recommendations and tip that you would indicate or should I take based on your knowledge   to avoid future problems?

    - Check out :

    -- Tip for Creating a COM Server Using C# – Apartment Marshaling and the Type Library.

    -- Tip for Supporting COM Events from a Managed Class : Use DispIds for Event Methods.


    - Bio.


    Please visit my blog : http://limbioliong.wordpress.com/

    Jumat, 14 September 2018 18.28
  •      Lim Bio / Group

        
      From now on I want to thank you for all your attention on this subject and your tips were very important to me.
      Only that some items would like to analyze better with you and to leave a little more clear to my doubt.


    1. >> But based on your data, would I need to use TLBIMP.EXE or TlbExp?
    - There is no need to use either one.
    1.1) Return - Doubt: The sense that I use tlbimp.exe (and or) TlbExp in my case would I bring greater security to my interoperability process or would it not or would it be to attend to which aspect of interoperability?


    2. >> What about the compilation issue, do I really need to use the / codebase parameter when using regasm.exe?
    - If you want to store the assembly in the GAC (global assembly cache), then there is no need to use /codebase.
    2.1) Return - Doubt: And in case of storing the assembly in the GAC (global assembly cache), what would be the command ?

    - If you do not store the assembly in the GAC, then /codebase will be a necessity in order that your VB6.0 client be able to locate the assembly at runtime.
    2.2) Return - Doubt: But would I be missing something related to interoperability security or not, what would be the disadvantage and consequence that can occur from just using the / codebase parameter ?


    3. >> I would need to use Strong Names (snk) to have a more secure registry inside windows, so in this case how should I proceed?
    - Strong names will be required if you store your assembly in the GAC.
    - Othewise no need for strong names.
    3.1) Return - Doubt: In my case I was thinking of using Strong Names, in this case what would be the procedure (basic and safe) of compilation, because I was seeing exists how to generate within Visual Studio (Signing later in Sign the assembly) or by outside (and in this case which would be the most indicated al.exe or sn.exe), would you have some  example or something to pass me in this direction ?
    3.2) Return - Doubt: And in case of using Strong Names where there is no GAC this would have some negative or positive impact ?


    4. >> what would be the recommendations and tip that you would indicate or should I take based on your knowledge to avoid future problems?
    - Check out :
    -- Tip for Creating a COM Server Using C# – Apartment Marshaling and the Type Library.
    4.1) Return - Doubt: Ok
    -- Tip for Supporting COM Events from a Managed Class : Use DispIds for Event Methods.
    4.2) Return - Doubt: Ok


    5. What would be the best way to create a property, method or something like this within interoperability, where then I can take the (guid) of my interoperability, in this case the number of (guid) of this my dll ?
    • Diedit oleh neibala Jumat, 14 September 2018 20.21 Error
    Jumat, 14 September 2018 20.17
  • Hello neibala,

    1. >> 1.1) Return - Doubt: The sense that I use tlbimp.exe (and or) TlbExp in my case would I bring greater security to my interoperability process or would it not or would it be to attend to which aspect of interoperability?

    - There is no need to use tlbimp.exe because it is used when your COM class is unmanaged (i.e. written in an unmanaged language, e.g. C++) and your client is a managed application (e.g. written in C#).

    - In your case, your client is written in VB6.0. Hence in your VB6.0 IDE, you need to reference the type library which is generated for your managed C# class library by regasm.exe (using the /tlb option). An because the type library will be created by regasm with the /tlb option, there is no need to run tlbexp.exe.

    - In VB6.0, reference the type library by using the Project menu and then navigating to the "References" item. A "References" dialog box will appear. Click the "Browse" button and an "Add Reference" file selection dialog box will appear. Navigate to your type library and select it.

    2. >> 2.1) Return - Doubt: And in case of storing the assembly in the GAC (global assembly cache), what would be the command ?

    - The command is :

    gacutil /i <path to your assembly>

    >> 2.2) Return - Doubt: But would I be missing something related to interoperability security or not, what would be the disadvantage and consequence that can occur from just using the / codebase parameter ?

    - Because you are developing your component in C# as a managed assembly, I think it would be better for you to use the GAC and not use regasm.exe with /codebase. The reason is that version control would then be much more flexible and natural. The .NET framework is designed specially to accommodate side-by-side installation of multiple versions of assembles. See Redirecting Assembly Versions for more info.

    3. >> 3.2) Return - Doubt: And in case of using Strong Names where there is no GAC this would have some negative or positive impact ?

    - No problem even if you sign your assembly and do not store your assembly in the GAC.

    4. >> 5. What would be the best way to create a property, method or something like this within interoperability, where then I can take the (guid) of my interoperability, in this case the number of (guid) of this my dll ?
    - Hmm... not sure I understand the question. Can you re-phrase it ?

    - Bio.


    Please visit my blog : http://limbioliong.wordpress.com/

    Sabtu, 15 September 2018 09.54
  •   Lim Bio / Group

      

          In question 5 which would be the best way to get the GUID of the interoperability dll, did 2 examples below, what would be the most correct or would it have another more efficient and correct way to get the guid of a dll when interoperability is being used ?

    5.1)
    
     Public ReadOnly Property GuidValueNew As String Implements iInteropx21.GuidValueNew
             Get
                Dim GuidAttribute As GuidAttribute = CType(GuidAttribute.GetCustomAttribute(Me.[GetType]().Assembly, GetType(GuidAttribute)), GuidAttribute)
                Return GuidAttribute.Value.ToString
             End Get
          End Property
    
    5.2)
         Public Function GetCurrentAssemblyGuid2() As String Implements iInteropx21.GetCurrentAssemblyGuid2
             Dim GuidAttribute As GuidAttribute = CType(GuidAttribute.GetCustomAttribute(Me.[GetType]().Assembly, GetType(GuidAttribute)), GuidAttribute)
             Return GuidAttribute.Value.ToString
          End Function   
    
    5.3) 
    Or another way more efficient and correct?

    Minggu, 16 September 2018 00.19
  • Hello neibala,

    1. I have no comments on which (5.1 or 5.2) is the best or most efficient way to get the GUID of the "interoperability dll".

    2. But I think that since the GUID of a class is a property of the class, it ought to be accessed as a read-only property.

    - Bio.



    Please visit my blog : http://limbioliong.wordpress.com/

    Minggu, 16 September 2018 05.41
  • Lim Bio / Group

        Just to better finalize the subject, my main question would be to know, to get the guid number of a dll, what would be the best way, since I am doubt if there would be another way to get this number in an easier way, would it exist ?

    Senin, 17 September 2018 13.39
  • Hello neibala,

    1. I am making a guess here :

    - I think that as you are writing your client as a VB6 program, you want to be able to create your COM-Visible C#/VB.NET object in VB6 code.

    - You may be wondering how to instantiate your COM visible C#/VB.NET class via the class' GUID in VB6 code.

    2. If my guess above is correct, then one relatively simple way to instantiate your C#/VB.NET class is to use the CreateObject() VB function and using a ProgID instead of using a GUID.

    3. First off, make sure that your C#/VB.NET class has the ProgIdAttribute :

    [ComVisible(true)]
    [Guid("...")]
    [ProgId("MyServer.MyClass")]
    public class MyClass
    {
       ...
    }

    - Note the ProgIdAttribute and the string value for it.

    - This ProgId value will be associated with the class' GUID (also known as its CLSID).

    4. In your VB6 code, you instantiate the class using the CreateObject() function :

    Dim m_MyClass As Object
    
    Set m_MyClass = CreateObject("MyServer.MyClass")

    5. When the above VB6 code is run, the VB6 runtime engine will lookup the registry for a ProgId entry named "MyServer.MyClass". Then the CLSID associated with the ProgId is looked up from the registry and then used to instantiate the C#/VB.NET component.

    6. Note that the CLSID (a 16-byte) numeric value will be universally unique. The ProgID (a string) may not be universally unique but needs to be unique to the local machine.

    7. Hope this helps.

    - Bio.


    Please visit my blog : http://limbioliong.wordpress.com/


    • Diedit oleh Lim Bio Liong Jumat, 21 September 2018 03.16 Typo error.
    • Ditandai sebagai Jawaban oleh neibala Rabu, 17 Oktober 2018 01.20
    Senin, 17 September 2018 17.12
  • I'm going to express an opinion that might not be popular here.

    There is such a VAST gulf between VB6 and .NET that it may not be practical to "migrate slowly".  Although it may be possible to create a C# DLL and access it from a VB6 program, that does not automatically make it possible to host Windows Forms.  That requires support that VB6 may not be providing.

    I suggestion that you re-evaluate your plan.  Consider starting your main program in C# and creating skeletons for the forms you will eventually need.  Do a side-by-side conversion, rather than a slow migration.


    Tim Roberts | Driver MVP Emeritus | Providenza &amp; Boekelheide, Inc.

    Senin, 17 September 2018 21.49
  • Lim Bio / Group

            First of all I just have to thank you for your attention on this issue, on the structure question, it's really close to what I'm doing, but for automation I'd like to know if there would be any command that when I was inside vb 6 eu I managed to get the guid of my dll, even if I created a property inside c # or vb.net and by vb6 I call this property and had access to it.

    Selasa, 18 September 2018 14.54
  • Tim Roberts

           Firstly, I just have to thank you for your confirmation, as this helps me to show my Director and my project team that we are on the right track, as you said and for your training and knowledge, but this project needs to have this option due to to other features and we know of the risks that can occur due to the issue of manageable and unmanageable environment and that we know we should take some care so we do not have future problems as you pointed out.
           More with the information I'm getting, I'm trying to do the best possible so that within a safe environment everything happens, using the settings and recommendations that should be followed.
    Selasa, 18 September 2018 15.06
  • Hi neibala,

    If the reply is helpful for you, please mark it as answer, it will beneficial to other communities who have the similar issue.

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Rabu, 19 September 2018 01.47
  • Zhanglong Wu / Tim Roberts / Lim Bio / Group

         I, in a way, even considering its intensity, more due to the knowledge of Lim Bio, if it gets or has something in this sense would help me a lot in my main doubt, otherwise if it does not have this knowledge I see how I will proceed in this case, then I'm waiting for the contact of Lim Bio or someone in the group?

    Kamis, 20 September 2018 17.35
  • Hi neibala,

    According to your description, you want to use C# or Vb.net in VB6, it is more related to VB6, I would suggest that you could post your issue on VB6 forum for suitable support.

    http://www.vbforums.com/forumdisplay.php?1-Visual-Basic-6-and-Earlier

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Jumat, 21 September 2018 07.29

  •      Zhanglong Wu / Tim Roberts / Lim Bio / Group


          The main concept in my doubt would be to use this interoperability in the most basic basic concept, where afterwards I could use any language, plus I would need to know what the correct structure would be, where as an example I ended up demonstrating the use with vb6, the use of interoperability.
          And I saw that Lim Bio came very close to what I was wanting and for the knowledge of it, I was in doubt as to how within the interoperability I could create a company, method or function that returns me the guid number?


     

    Kamis, 27 September 2018 14.56