New fpSpread error "creating window handle" in an Add-in to MS Oficce

Posted by: jraceituno on 8 September 2017, 3:23 pm EST

  • Posted 8 September 2017, 3:23 pm EST

    I have a form that create a Spread in an Addin to MSProject in VB.Net. In my computer, every thing Ok. I Publish the addin, and deploy in an other computer and the addin works (the other funcionality of the addin) but when I try to show the form with the spread: error creating window handle.
    Can help me, Thanks
  • Replied 8 September 2017, 3:23 pm EST


    Please go through these links for the same:-

    Hope it helps. Else please provide us with a sample replicating the issue so that we can investigate this issue further and also let us know which version of Spread are you using?

    Please confirm.

  • Replied 8 September 2017, 3:23 pm EST

    StackTrace error:

    at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp) at System.Windows.Forms.Control.CreateHandle() at System.Windows.Forms.Control.get_Handle() at FarPoint.Win.Spread.FpSpread..ctor() at Unitario_Project.rb_Proyecto.cmd_sp_Click(Object sender, RibbonControlEventArgs e)"
  • Replied 8 September 2017, 3:23 pm EST

    '---- Spread for Windows ver. 5.0.3522

    NOTE: the app is published and after is installed like an AddIn of MSOficce/Project.
    I believe this could be the reason of de error.

    '--- The code with the error is:
    '--- Click on ribbonbutton ---
    Private Sub cmd_testFp_Click(sender As System.Object, e As Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs) _
    Handles cmd_testFp.Click

    Dim newFp As FpSpread = Nothing

    newFp = New FpSpread '--- Error message: "err creating window handle"

    Catch ex As Exception
    MessageBox.Show(ex.Message, "Creating fp " & vbCrLf & ex.StackTrace.ToString)
    End Try

    newFp.Name = "FSpread1"
    MessageBox.Show("fp Created OK: " & newFp.Name, "test fp")

    End Sub

    Stacke Trace:
    at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
    at System.Windows.Forms.Control.CreateHandle()
    at System.Windows.Forms.Control.get_Handle()
    at FarPoint.Win.Spread.FpSpread..ctor()
    at Unitario_Project.rb_Proyecto.cmd_testFp_Click(Object sender, RibbonControlEventArgs e)

  • Replied 8 September 2017, 3:23 pm EST


    I am not sure it is possible to use Spread directly that way, because of the way that licensing works and the way that VBA works.
    The problem is, VBA does not support the distinction between run-time and design-time -- VBA is always operating in design-time mode, even when you are running forms and interacting with controls. There is simply no support for the concept of "compiling" or "building" in VBA (since everything is interpreted dynamically) and all controls are always created in "design mode."
    Because of this, third-party licensed controls like Spread cannot work in VBA, as the developer license cannot be embedded in the VBA code.

    I think even if you create a licensed add-in component, it would not work to use Spread inside VBA, as the component licensing implementation for your add-in component would fail for the same reason that Spread's licensing fails, as described above.

    The way that the .NET component licensing works, if you create a UserControl component which contains an instance of FpSpread, then that UserControl will require the license for Spread on the machine where it is used in design time (e.g. if a developer tries to use the UserControl DLL without the FpSpread license, it will fail to create in design time). However, if the UserControl is licensed (using LicenseProvider attribute) and Spread is licensed in the UserControl DLL project (inside its LICX), then it should work to use that UserControl in run-time in an application that was created without the license for Spread but with the license for the UserControl. The application would need to be built on a machine that is actually licensed for Spread development (since the UserControl's design-time license check will recursively call Spread's design-time license check), but the Spread's license does not need to be built directly into the application EXE (e.g. you do not need to include the type for FpSpread in the LICX for the application, as this will be included automatically by the UserControl's license). When the application is built, the license resource generated by lc.exe from the LICX will contain all the licenses required by the types listed in the LICX including any contained types, but only the run-time license keys for those components, for creating them in run-time mode.

    Since VBA always creates components and controls in design-time mode, there is not any way to make any component or control create in VBA unless the design-time license is present on the machine (e.g. you have installed Spread for development on the machine).

    Sorry for the inconvenience! I do not think there is any workaround for this, but you can post a sample showing the problem if you would like us to look into it some more and try to make it work.

  • Replied 8 September 2017, 3:23 pm EST


    Like you said, I make a usercontrol DLL with license, in this component I created the fpSpread that is called from the AddIn application. The error, again, is produced at “new fpSpread”
    Any way, I show you my code for the ucControlDll:

    Public Class ucFPSpread
    Dim m_sp As FpSpread

    Public Sub New()

    ' This call is required by the designer.

    ' Add any initialization after the InitializeComponent() call.
    Dim _license As License = Nothing

    _license = LicenseManager.Validate(GetType(ucFPSpread), Me)

    If _license Is Nothing Then
    MessageBox.Show("No Licencia", "ucFPSpread")
    End If

    m_sp = New FpSpread
    m_sp.Sheets.Add(New SheetView)

    m_sp.Dock = DockStyle.Fill
    Catch ex As Exception
    MessageBox.Show(ex.Message, "ucFPSpread")
    End Try

    End Sub

    But, if VBA run in design-time mode and check the design license, there are no way to create the fpSpread.
    I belive, I have to use a grid control, or raise, from the addIn, process of apps.exe compiled in the machine.

    Thank for your help
  • Marked as Answer

    Replied 8 September 2017, 3:23 pm EST

    Hi Roberto,

    It is not possible to make code like that work because the logic to validate the design-time license context for the UserControl will recursively call into the validate logic for the embedded ActiveX controls to validate the design-time license context, which would always fail for the Spread control on the target machine (unless it happens to have that particular version Spread control already installed for development and licensed on the machine). So it might work well on your development machine in testing, but not when you deploy the add-in to another user who does not have Spread installed and licensed for development.

    To get around this issue, you would need to create the UserControl using only embedded ActiveX controls which are not licensed.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels