使用变量作为服务器名称连接到传真服务器 [英] Connect to Fax Server With a Variable as the Server Name

查看:83
本文介绍了使用变量作为服务器名称连接到传真服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用网络服务器上的传真服务器从我的应用程序(VB.net 2003)成功传真。现在我想将Connect()中的ServerName更改为变量,这样我就可以使用不同的服务器而无需更改代码。这是我现在使用的代码。修改后显示使用变量。

I'm successfully faxing from my app (VB.net 2003) using a fax server on the network server. Now I want to change the ServerName in the Connect() to a variable so I can use different servers without having to change the code. Here's the code I'm using now. Revised to show using a variable.

Dim oFaxServer As New FAXCOMEXLib.FaxServer
Dim oFaxDocument As New FAXCOMEXLib.FaxDocument
Dim oJobID As Object
Dim sRealJobId As String

Try
  oFaxServer = New FAXCOMEXLib.FaxServer

  Dim gFaxServerName as String
  gFaxServerName = "\\Server02"

  ' Connect to the fax server
  If gSystemLoc = "Local" Then
    oFaxServer.Connect("")
  Else
    oFaxServer.Connect(gFaxServerName)
  End If
  ... Everything else from here on works fine



oFaxServer.Connect()中的服务器名称应该是bstrServerName as String,但我无法弄清楚如何更改我的服务器名称(字符串)进入bstr。


The Server Name within the oFaxServer.Connect() is supposed to be a "bstrServerName as String", but I cannot figure out how to change my server names (strings) into the bstr.

推荐答案

Dim gFaxServerName as String
  gFaxServerName = "\\Server02"
 
  ' Connect to the fax server
  If gSystemLoc = "Local" Then
    oFaxServer.Connect("")
  Else
    Dim bstrPtr as IntPtr
    bstrPtr = Marshal.StringToBSTR(gFaxServerName)
    oFaxServer.Connect(bstrPtr)
    Marshal.FreeBSTR(bstrPtr)
  End If
  ... Everything else from here on works fine





我的VB糟透了所以不要抱我编译。如果输入功能需要BSTR,那么上面的内容应该可以满足您的需求。您需要导入 System.Runtime.InteropServices 命名空间。


这篇关于使用变量作为服务器名称连接到传真服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆