I’ve progressed somewhat in my recent efforts with regards to utilizing a virtual channel between receiver and the VDA. I’ve converted the driver to C++ which makes utilizing C-type syntax easier – I can declare variables and assign them in between the code for example. Anyway, the real issue I was having right was calling the C/C++ DLL from WPF/C# which establishes the connection to the driver.
So the first time I call the function in the C++ DLL that initiates the connection to the client driver, this all works, do it again and it failed. But I fixed it by doing a little googling: I was doing this from c#:
[DllImport("VDAAPPV.dll", EntryPoint = "SendAndRecieve", SetLastError = true)] private static extern int SendAndRecieve(string message, int messageLength, StringBuilder response, int responseLength); private void btnCreateVC_Click( object sender, RoutedEventArgs e ) { try { var sb = new StringBuilder(100); SendAndRecieve("Stuart Mathews is a dude","Stuart Mathews is a dude".Length, sb, sb.Capacity); Status.Content = sb.ToString(); MessageBox.Show("Result was " + sb); } catch (Exception ex) { MessageBox.Show("Error sendreceive: "+ ex.Message); } }
The problem was that the DllImport should have been like this:
[DllImport("VDAAPPV.dll", EntryPoint = "SendAndRecieve", SetLastError = true, CharSet = CharSet.Ansi)] private static extern int SendAndRecieve(string message, int messageLength, StringBuilder response, int responseLength);
Note the CharSet = CharSet.Ansi part. Thats because the C function looks like this:
extern "C" EXPORT_ME int SendAndRecieve(const char* message, int messageLength, char* responseBuf, int responseLength) { ... }
A pointer to a char is ANSI. Because I’m a fool, I forgot about this for a full day. Anyway, the results are that I can send a message to receiver from the VDA and get a response:
And that’s probably the most important step in working with the Citrix Virtual Channel SDK.
So onwards and upwards!