我已经成功地在Microsoft中使用了CoSign,但现在我正在尝试使用MicrosoftVisualBasicStudio10Express自动生成报告。试图下载开发人员的软件包由于前面的客户端安装而失败,但我已经看到在我的桌面上安装了Arx Signature 6.20,并且我可以通过COM选项卡添加对Interop.SAPILib.dll的引用,没有问题;Intellisense识别所有适当的功能,因此似乎所有东西都安装好了。但是,当我构建和调试程序时,我会得到没有注册的错误80040154类,特别是在第一个"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中引用它,但Arx代码的安装不会自动注册dll吗?我尝试手动注册dll文件,但随后我得到一个错误,即模块已加载,但入口点DllRegisterServer未找到,并检查这是否是一个有效的dll。
显然,我对COM dlls还不熟悉。我是在正确的轨道上,还是这是另一种未经处理的错误?
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谢谢!
发布于 2014-02-06 10:30:53
FileHandle对象可以使用CreateFileHandleByName或CreateFileHandleByMem函数创建,这是在COM中实例化对象的正确方法。用Dim myFileHandle As New SAPILib.FileHandle替换行Dim myFileHandle As SAPILib.FileHandle = Nothing将解决您的问题。
https://stackoverflow.com/questions/21588712
复制相似问题