title: Imported C-function works in C# but not in VB6
body: <p>I'm working on a problem for a few days now and can't seem to find the answer. I have a third party dll written in C, which i have to use in an VB6 application.</p>
  
  <p>The function inside dll looks something like this:</p>
  
  <pre><code>someFunction(WContext* context, const unsigned char* seed, int seedLength, const unsigned char* name, int nameLength, 
               const unsigned char* pin, int pinLength, const char* description)
  </code></pre>
  
  <p>I have an example written in c#. I tried it out and it works just fine. This is what it looks like in C#</p>
  
  <pre><code>[DllImport("Filename.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
  private static extern int someFunction(IntPtr context, byte[] seed, int seedLength, byte[] name, int nameLength, 
                                         byte[] pin, int pinLength, string description)
  </code></pre>
  
  <p>This is later used in the example like this:</p>
  
  <pre><code>byte[] seed = Encoding.ASCII.GetBytes("seed")
  byte[] name = Encoding.ASCII.GetBytes("name")
  byte[] pin = Encoding.ASCII.GetBytes("1234")
  string description = "description"
  
  int result = someFunction(context, seed, seed.length, name, name.Length, pin, pin.Length, description)
  </code></pre>
  
  <p>Now this works just fine in C#. I get 0 as a result which means in that case that the operation was a success.
  I want to make this work in VB6. I tried it with some other functions of the dll and they work just like they should. This one gives me a headache. Here is what I tried just like with any other function:</p>
  
  <p>First I imported the function into my code so I could use it later. I did this with a few other functions the same way and it worked fine.</p>
  
  <pre><code>Private Declare Function someFunction Lib "C:\DllPath\Filename.dll" (ByVal context As Long, ByRef seed as Byte, _
                                                                       ByVal seedLength As Integer, ByRef name As Byte, _
                                                                       ByVal nameLength As Integer, ByRef pin As Byte, _
                                                                       ByVal pinLength As Integer, ByVal description As String) As Integer
  </code></pre>
  
  <p>Next Step was for me to call the function. I did it this way:
  (I do get the context from another function earlier so this already has a value. Other functions work fine with that variable)</p>
  
  <pre><code>Dim seed() As Byte
  Dim seedLength As Integer
  Dim name() As Byte
  Dim nameLength As Integer
  Dim pin() As Byte
  Dim pin As Integer
  Dim description As String
  Dim result as Integer
  
  seed = StrConv("seed", vbFromUnicode)
  seedLength = UBound(seed) + 1
  name = StrConv("name", vbFromUnicode)
  nameLength = UBound(name) + 1
  pin = StrConv("1234", vbFromUnicode)
  pinLength = UBound(pin) + 1
  description = "description"
  
  result = someFunction(context, seed(0), seedLength, name(0), nameLength, pin(0), pinLength, description)
  </code></pre>
  
  <p>The value for result is 1. By the documentation I got this means invalid parameter. Now I researched a lot. Read that in VB6 I have to give the first element of the byte array just like I did in my code. Tried it first with the whole array, got the same result. I think it has something to do with the arrays since its the first function that I've taken over to my code that had those. I'm also not really that native with VB6 but I have to do this. Maybe some of you guys know why this doesn't work. Probably just a minor mistake by myself.</p>