我一直在Microsoft Word中成功使用CoSign,但现在我正在尝试使用Microsoft Visual Basic Studio 10 Express自动生成报告。由于以前的客户端安装,尝试下载开发人员的软件包失败,但我已经看到我的桌面上安装了Arx Signature API 6.20,我可以通过COM添加对Interop.SAPILib.dll的引用而没有任何问题标签; Intellisense识别所有适当的功能,所以似乎都安装了所有功能。但是,当我构建和调试程序时,我收到错误80040154 Class未注册,特别是在第一个“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位Toshiba。
这可能是一个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
谢谢!
答案 0 :(得分:1)
可以使用CreateFileHandleByName
或CreateFileHandleByMem
函数创建FileHandle对象,这是在COM中实例化对象的正确方法。用Dim myFileHandle As New SAPILib.FileHandle
替换行Dim myFileHandle As SAPILib.FileHandle = Nothing
将解决您的问题。