I am trying to connect to a domain using the NetJoinDomain API. I can successfull use it to change the workgroup. But when trying to change the domain I get one of two errors, using the same input. I either get "No such domain" or "No mapping for the Unicode character exists in the target multi-byte code page." This is using the same exact inputs, I have hard coded the inputs in for debuging purposes.

What am I doing wrong?

Also for some reason I have to convert the strings into char arrays and insert a null value between each character. Anybody know why?

VB Code:
  1. Private Declare Function NetJoinDomain _
  2.     Lib "NETAPI32.dll" (ByVal lpServer As String, _
  3.     ByVal lpDomain As String, ByVal lpAccountOU As String, _
  4.     ByVal lpAccount As String, ByVal lpPassword As String, _
  5.     ByVal fJoinOptions As Int32) As Int32
  6.  
  7.  
  8. Public Sub ChangeDomain()
  9.         Dim d() As Char
  10.         Dim u() As Char
  11.         Dim p() As Char
  12.  
  13.         ' I replaced what the actual values are, since they were my username and password to the company domain
  14.         'InsertNulls is a function that I created to convert the strings to char arrays and insert null chars between each value
  15.         d = insertNulls("myDomain")
  16.         u = insertNulls("myUserName")
  17.         p = insertNulls("MyPassword")
  18.  
  19.  
  20.         err = NetJoinDomain("", d, "", u, p, JoinOptions.NETSETUP_DOMAIN_JOIN_IF_JOINED Or JoinOptions.NETSETUP_JOIN_DOMAIN)
  21. End Sub