INVOKE錯誤

vileboy 2018-11-01 11:56:44
下面的代碼報錯,InterfaceOperator.HY_Print這句報錯。提示出下。

textBox1.Text = Application.StartupPath & "\" & txtLaxFileFullName.Text.Trim()
If Not IsNumeric(txtPrintSetup.Text) Then
Throw New Exception("打印份數出錯")
End If
printSetup = txtPrintSetup.Text
If Not FileIO.FileSystem.FileExists(textBox1.Text) Then
Throw New Exception("打印模板不存在")
End If
If InterfaceOperator.HY_OpenLax(textBox1.Text) Then
InterfaceOperator.HY_SetVariable("barcode", txtVarWord.Text.Trim(), "A", "B") '
InterfaceOperator.HY_SetVariable("T文字2", txtVarBarcode.Text.Trim(), "a", "c") '
InterfaceOperator.HY_Print(printSetup, txtPrinterName.Text.Trim(), cbPageWindowsShow.Checked) '《--------------這句報錯
Else
Throw New Exception("模板打開失敗")
End If

...全文
132 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
vileboy 2018-11-05
  • 打赏
  • 举报
回复
上面錯了,下面才是對的 VB是根據C#修改來的。 C#聲明: [DllImport(InterfaceDllName)] public static extern void HY_Print(int printSetup, string printerName, bool pageWindowsShow); VB聲明: <System.Runtime.InteropServices.DllImport(InterfaceDllName, EntryPoint:="HY_Print")> _ Public Shared Function HY_Print(ByVal printSetup As Integer, ByVal printerName As String, ByVal pageWindowsShow As Boolean) End Function
vileboy 2018-11-05
  • 打赏
  • 举报
回复
VB是根據C#修改來的。 VB聲明是這樣 <System.Runtime.InteropServices.DllImport(InterfaceDllName, EntryPoint:="HY_PrintPic")> _ Public Shared Function HY_PrintPic(ByVal outDirectory As String, ByVal outFirstName As String, ByVal outDpiH As Integer, ByVal outDpiV As Integer, ByVal outColor As Integer) As Integer End Function C#聲明是這樣: [DllImport(InterfaceDllName)] public static extern int HY_PrintPic(string outDirectory, string outFirstName, int outDpiH, int outDpiV, int outColor);
vileboy 2018-11-05
  • 打赏
  • 举报
回复
解決了。 把API聲明改為: <System.Runtime.InteropServices.DllImport(InterfaceDllName, EntryPoint:="HY_Print")> _ Public Shared Sub HY_Print(ByVal printSetup As Integer, ByVal printerName As String, ByVal pageWindowsShow As Boolean) End Sub 或 <System.Runtime.InteropServices.DllImport(InterfaceDllName, EntryPoint:="HY_Print")> _ Public Shared Function HY_Print(ByVal printSetup As Integer, ByVal printerName As String, ByVal pageWindowsShow As Boolean) As Integer End Function
yishumei 2018-11-05
  • 打赏
  • 举报
回复
楼主,请问DllImport(InterfaceDllName)引用的时哪个dll?
stherix 2018-11-02
  • 打赏
  • 举报
回复
InterfaceOperator.HY_Print应该是个native方法吧 你最好把它的c语言方法签名发一下,肯定是参数类型没对上
vileboy 2018-11-02
  • 打赏
  • 举报
回复
請各位大神看看啊

16,722

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧