1

我一直在 Microsoft Word 中成功使用 CoSign,但现在我正在尝试使用 Microsoft Visual Basic Studio 10 Express 自动生成报告。由于之前的客户端安装,尝试下载开发人员的软件包失败,但我确实看到我的桌面上安装了 Arx Signature API 6.20,我可以毫无问题地通过 COM 添加对 Interop.SAPILib.dll 的引用标签; Intellisense 识别所有适当的功能,所以一切似乎都已安装。但是,当我构建和调试程序时,我收到错误 80040154 Class not registered,特别是在第一个“Dim myFileHandle as New SAPILibrary.FileHandle”调用中。以前的调用没有错误;它们包括将 MySAPI 创建为新的 SAPICrypt,将 MyHandle 创建为新的 SESHandle 对象,MyFieldHandle 作为新的 SAPILib.SigFieldSettings,并调用 MySAPI.init、MySAPI.HandleAquire、MySAPI.Logon。我的代码如下。

此错误的其他论坛帖子指出,如果使用 32 位 dll,则需要确保 x86 构建。我已经确认这是我的解决方案的编译平台;我使用的是运行 Windows 7 的 64 位东芝。

这可能是一个 dll 问题,因为其他 SAPILibrary 类引用运行良好?尽管我能够在 Visual Stuio Express 中引用它,但 Arx Cosign 安装是否不会自动注册 dll?我尝试手动注册 dll 文件,但随后出现错误,即模块已加载但未找到入口点 DllRegisterServer,并检查这是否是有效的 dll。

显然我是 COM dll 的新手。我是在正确的轨道上,还是这是另一种未处理的错误?

 Private Sub SignWithSAPI()
    Dim username As String = "XXX@yahoo.com"
    Dim password As String = "passwordhere"

    'add a signature field locator string - NEED TO HIDE THIS AS IT DOESN'T GET ERASED BY SAPI
    Dim MyFieldLocatorString As String = "<<<W=200;H=120;N=Physician signature;A=&HC;>>>"
    oWord.Selection.TypeText(MyFieldLocatorString)

    'SIGN PDF HERE USING COSIGN Signature API
    Dim mySAPI As New SAPICrypt
    Dim myHandle As New SESHandle

    Dim rc As Int32

    rc = mySAPI.Init()
    If rc <> 0 Then
        MessageBox.Show("Init failed")
        Exit Sub
    End If

    rc = mySAPI.HandleAcquire(myHandle)
    If rc <> 0 Then
        MessageBox.Show("failed at handleAcquire")
        mySAPI.Finalize()
        Exit Sub
    End If

    rc = mySAPI.Logon(myHandle, userName, "", password)
    If rc <> 0 Then
        MessageBox.Show("Login failed")
        mySAPI.HandleRelease(myHandle)
        mySAPI.Finalize()
        Exit Sub
    End If

    Dim MyFieldSettings As New SAPILib.SigFieldSettings
    With MyFieldSettings
        .Invisible = 0
        .Height = 200
        .Width = 100
        .AppearanceMask = myChosenAppearancesMask 'shows graphical image, name of signer and time
        .SignatureType = SAPI_ENUM_SIGNATURE_TYPE.SAPI_ENUM_SIGNATURE_DIGITAL
    End With

    Dim myPDFfileName As String = "C:\\Users\Scott\Desktop\TestAutomation.pdf"
    Dim myFileHandle As New SAPILib.FileHandle

    rc = mySAPI.CreateFileHandleByName(myFileHandle, _
        SAPI_ENUM_FILE_TYPE.SAPI_ENUM_FILE_ADOBE, 0, myPDFfileName)
    If rc <> 0 Then
        MessageBox.Show("Error in creating FileHandlebyName")
        mySAPI.HandleRelease(myHandle)
        mySAPI.Finalize()
        Exit Sub
    End If

    'Assigns the SigFieldContext
    Dim mySigFieldContext As New SAPIContext
    Dim myNumberOfSigFields As Integer
    rc = mySAPI.SignatureFieldEnumInitEx(myHandle, mySigFieldContext, _
      SAPI_ENUM_FILE_TYPE.SAPI_ENUM_FILE_ADOBE, "", myFileHandle, 0, myNumberOfSigFields)
    If rc <> 0 Then
        MessageBox.Show("Error in SigFieldEnumInitEx")
        mySAPI.HandleRelease(myFileHandle)
        mySAPI.HandleRelease(myHandle)
        mySAPI.Finalize()
        Exit Sub
    End If

    Dim mySigFieldLocatorContext As New SAPIContext 'next line assigns its value in the function
    rc = mySAPI.SignatureFieldLocatorEnumInit(myHandle, mySigFieldLocatorContext, _
        myFileHandle, "<<<", ">>>", 0, myNumberOfSigFields)
    If rc <> 0 Then
        mySAPI.ContextRelease(mySigFieldContext)
        MessageBox.Show("Error in SigFieldLocatorContext")
        mySAPI.HandleRelease(myFileHandle)
        mySAPI.HandleRelease(myHandle)
        mySAPI.Finalize()
        Exit Sub
    End If

    Dim mySigFieldHandle As New SigFieldHandle
    rc = mySAPI.SignatureFieldEnumCont(myHandle, mySigFieldContext, mySigFieldHandle)
'assigns the first(only) value to mySigFieldHandle
    If rc <> 0 Then
        mySAPI.ContextRelease(mySigFieldLocatorContext)
        mySAPI.ContextRelease(mySigFieldContext)
        MessageBox.Show("Error in SigFieldLocatorContext")
        mySAPI.HandleRelease(myFileHandle)
        mySAPI.HandleRelease(myHandle)
        mySAPI.Finalize()
        Exit Sub
    End If

    '//Create the Field

    rc = mySAPI.SignatureFieldSignEx(myHandle, mySigFieldHandle, myChosenAppearancesMask, _
Nothing)
    If rc <> 0 Then
        MessageBox.Show("Error in sigfieldSignEx")
    End If

    'release resources
    mySAPI.HandleRelease(mySigFieldHandle)
     mySAPI.HandleRelease(myFileHandle)
   mySAPI.ContextRelease(mySigFieldContext)
    mySAPI.ContextRelease(mySigFieldLocatorContext)
    mySAPI.Logoff(myHandle)
    mySAPI.HandleRelease(myHandle)
End Sub

谢谢!

4

1 回答 1

1

FileHandle 对象可以使用CreateFileHandleByNameCreateFileHandleByMem函数创建,这是在我们的 COM 中实例化对象的正确方法。更换线路Dim myFileHandle As New SAPILib.FileHandleDim myFileHandle As SAPILib.FileHandle = Nothing解决您的问题。

于 2014-02-06T10:30:53.633 回答