Click here to Skip to main content
15,899,314 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
VB
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

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.
Posted
Updated 22-Jul-13 5:17am
v2
Comments
[no name] 22-Jul-13 10:45am    
Huh? What?
Have you tried
Dim serverName as String = "\\Server02"
oFaxserver.Connect(serverName)
?
auguy 22-Jul-13 10:50am    
Yes I have, I don't have the error number or the error text in front of me right now, but that didn't work. I believe it gave me a connection error. I will try and get the error information.
auguy 22-Jul-13 11:00am    
It gives me a Fax Connection Error: 35, Operation Failed. when I use a variable as the server name in the Connect().
[no name] 22-Jul-13 11:10am    
Try Dim serverName as String = "\\\\Server02" and see what happens
auguy 22-Jul-13 11:22am    
With "\\\\Server02" I get a Fax Connection Error: 800706AB, Operation Failed.

1 solution

VB
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


My VB sucks, so don't hold me to that compiling. If the input function requires a BSTR, then the above should get you what you need. You will need to import the System.Runtime.InteropServices namespace.
 
Share this answer
 
Comments
auguy 22-Jul-13 11:45am    
When I try to put the bstrPtr in the Connect(), VB tells me "Value of type 'System.IntPtr' cannot be converted to 'String'". Maybe due to .Net 1.1?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900