locked
Com Interop RRS feed

  • Question

  • I want to use iTextSharp in a VB6 application. So I created a ClassLibrary named PdfCom and then I coded this:

    Imports iTextSharp.text
    Imports iTextSharp.text.pdf
    Imports System.IO
    
    Public Interface Ipdf
     Sub GeneratePdf(ByVal path As String)
    
    End Interface
    
    Public Class pdf
     Implements Ipdf
    
     Public Sub GeneratePdf(path As String) Implements Ipdf.GeneratePdf
      Dim doc As New Document
      PdfWriter.GetInstance(doc, New FileStream(path, FileMode.Create))
      doc.Open()
      doc.Add(New Paragraph("Hello world"))
      doc.Close()
     End Sub
    End Class
    

    Then I went to the Properties of the ClassLibrary:
    - on the Tab "Application", I clicked "Assembly Information..." and checked the Checkbox "Make assembly COM-Visible".
    - On the Tab "Compile", I Checked the Checkbox "Register for COM interop"
    - On the Tab "Signing", I checked the Checkbox "Sign the assembly", and a created a Strong Name Key

    I saved all files and build the application Succesfully. In the Bin\Release folder I see 5 files:
    itextsharp.dll
    PdfCom.dll
    PdfCom.pdb
    PdfCom.tlb
    PdfCom.xml


    So far so good, but when I want to make a reference to the PdfCom.dll in VB6, I get an error:

    "Can't ad a reference to the specified file."

    I think I need to register this register this file (using regsvr32???), but is it enough? And what if I want to deploy the Vb6 application to other computers? What do I need to do to make this work on other computers I also read that on the computers where I want to use this the .NET framework which I used to develop the ClassLibrary needs to be installed also.

    What I would like is to make an installer that installs all necessary files and the framwework if needed. I googled a lot but can't find any good resources....

    Saturday, March 19, 2011 6:45 PM

Answers

  • OK,

    after reading som articles in this forum things starting to become more clear to me. I found this article:

    http://support.microsoft.com/kb/817248/en-us

    It explains to me that I better use the ComClass template, which I did. After buidling the application, I was able to add a reference to this project in VB6 and indeed, I can call the method and it creates the pdf as expected. But that's where the article ends and things starting to confuse me Because when I make a exe in vb6, it doesn't worrk. And I want to deploy this to other computers, but I don't inderstand which files I need to deploy and register on other computers??? Because I not only have to deal with the dll I created, but also with the itextsharp dll..

    Saturday, March 19, 2011 7:42 PM
  • The target computers need to have the .NET Framework installed. Not sure which version of Visual Studio you are using so I can't tell you which .NET Framework version will be required. If ITextSharp is a separate component you will need that as well (although no registration is required for use from your component).

    Keep in mind that your deployment package will need to register your component for COM Interop, or, you will need to do this manually using the Regasm utiity.


    Paul ~~~~ Microsoft MVP (Visual Basic)
    Monday, March 21, 2011 1:51 PM

All replies

  • I want to use iTextSharp in a VB6 application. So I created a ClassLibrary named PdfCom and then I coded this:

    Imports iTextSharp.text
    Imports iTextSharp.text.pdf
    Imports System.IO
    
    Public Interface Ipdf
      Sub GeneratePdf(ByVal path As String)
    
    End Interface
    
    Public Class pdf
      Implements Ipdf
    
      Public Sub GeneratePdf(path As String) Implements Ipdf.GeneratePdf
        Dim doc As New Document
        PdfWriter.GetInstance(doc, New FileStream(path, FileMode.Create))
        doc.Open()
        doc.Add(New Paragraph("Hello world"))
        doc.Close()
      End Sub
    End Class

    Then I went to the Properties of the ClassLibrary:
    - on the Tab "Application", I clicked "Assembly Information..." and checked the Checkbox "Make assembly COM-Visible".
    - On the Tab "Compile", I Checked the Checkbox "Register for COM interop"
    - On the Tab "Signing", I checked the Checkbox "Sign the assembly", and a created a Strong Name Key

    I saved all files and build the application Succesfully. In the Bin\Release folder I see 5 files:
    itextsharp.dll
    PdfCom.dll
    PdfCom.pdb
    PdfCom.tlb
    PdfCom.xml

    So far so good, but when I want to make a reference to the PdfCom.dll in VB6, I get an error:

    "Can't ad a reference to the specified file."

    I think I need to register this register this file (using regsvr32???), but is it enough? And what if I want to deploy the Vb6 application to other computers? What do I need to do to make this work on other computers I also read that on the computers where I want to use this the .NET framework which I used to develop the ClassLibrary needs to be installed also.

    What I would like is to make an installer that installs all necessary files and the framwework if needed. I googled a lot but can't find any good resources....

    Saturday, March 19, 2011 2:44 PM
  • Since you are not asking help in using Windows Form classes your question is off-topic here. You may get help in COM-interop in the CLR forum under the .Net development category but if you don't modify PDF you can use other native libraries. Check Where to post your VB 6 questions and search in vb6 communities listed there using the keyword "PDF". 

     

     



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    Saturday, March 19, 2011 5:04 PM
  • This is defintly not a VB6 question, because I'm building a .NET class Library. The COM-interop forum is for questions on "how to do upgrades of VB6 code to VB.NET", but that's also not what I want to do. Not only is it hard to find any tutorial on this matter, I also can't find a forum that covers this question.. If anybody knows the answer or can direct me to a forum whare my question isn't off-topic, I would ve very gratefull....
    Saturday, March 19, 2011 6:43 PM
  • OK,

    after reading som articles in this forum things starting to become more clear to me. I found this article:

    http://support.microsoft.com/kb/817248/en-us

    It explains to me that I better use the ComClass template, which I did. After buidling the application, I was able to add a reference to this project in VB6 and indeed, I can call the method and it creates the pdf as expected. But that's where the article ends and things starting to confuse me Because when I make a exe in vb6, it doesn't worrk. And I want to deploy this to other computers, but I don't inderstand which files I need to deploy and register on other computers??? Because I not only have to deal with the dll I created, but also with the itextsharp dll..

    Saturday, March 19, 2011 7:42 PM
  • The target computers need to have the .NET Framework installed. Not sure which version of Visual Studio you are using so I can't tell you which .NET Framework version will be required. If ITextSharp is a separate component you will need that as well (although no registration is required for use from your component).

    Keep in mind that your deployment package will need to register your component for COM Interop, or, you will need to do this manually using the Regasm utiity.


    Paul ~~~~ Microsoft MVP (Visual Basic)
    Monday, March 21, 2011 1:51 PM
  • Sorry I think you misunderstood. The place to discuss COM Interop for .Net in general is the CLR forum not the VB interop forum.

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    Monday, March 21, 2011 11:36 PM
  • Hi Hans,

    Any update?

     

    How about your program? If it works, you can share your solutions & experience here, it will be very beneficial for other community members who have similar questions. Thanks.

     

    Best regards,


    Mike Feng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, March 25, 2011 6:00 PM
    Moderator
  • Hi Hans,

     

    Thanks for posting in the MSDN Forum.

     

    Any update? I have marked your own and Paul's reply as answer, if you think it provides no help, please unmark it.

     

    Thank you for your understanding and support.

     

    Best Regards,


    Mike Feng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, March 29, 2011 6:15 AM
    Moderator