Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

We are converting a VB6 GUI application that uses C++ for it's backend to VB.net front end. We are also using C++/CLI as the interface.

In the C++ the original code was passed from VB6 as 

Public Type Npat_Stat
  Chan As Byte
  Con_stat As Byte
  Con_req As Byte
  Cur_serv As Byte
  Num_servs As Byte
  Server_id As String * 33
  Last_Error As String * 51
  Extra_error As String * 51
End Type


Where the C++ routine had the following parameter passed:

STDAPI_(short) Npat_Status(struct com_status *cs)


struct com_status
{
   unsigned char chan;          // Set channel 0=temp, 1=perm1, 2=perm2
   unsigned char con_stat;      // Connection status
   unsigned char con_req;       // Connection control byte
   unsigned char cur_serv;      // Which server is being tried
   unsigned char num_servs;     // Number of servers to try
   char server_id[33];          // Server details
   char last_error[51];         // Last error text
   char extra_error[51];        // Extended error info
};




So in VB.net I have:

Public Structure Npat_Stat
        Public Chan As Byte
        Public Con_stat As Byte
        Public Con_req As Byte
        Public Cur_serv As Byte
        Public Num_servs As Byte
        <VBFixedString(33)> Public Server_id As String
        <VBFixedString(51)> Public Last_Error As String
        <VBFixedString(51)> Public Extra_error As String
    End Structure


So I'm struggling to understand the best way to approach this problem. Do I create a ref class to hold the structure and pass it from VB.net as the following:

int Comms::O_Status(O_Stat ^cs)


and then somehow convert the ^cs passed in to com_status *cs to pass onto the original routine from this interface layer?

Is the fixed length string going to cause problems as well?

Any pointers on the best way to do this would be great as I'm a novice at C++, been on a course and asked to help out on this part of the project but I'm the VB6/VB.Net bod not C++

Thanks
Martin

What I have tried:

Reading MS C++/CLI online articles for examples
Posted
Updated 2-Jun-20 1:07am
v2

1 solution

This is a tricky issue and best is to avoid the pitfalls like handling strings not properly. They arise because VB 6 is some legacy language and so to be handled with much care. And: VB.net works completly different, a bit more like C#.

I remember using such BSTR and Variant in C++ to deal in VB6 some years ago, but today I would use a fixed char array.

This question was also answered here by me.

You need to try it out. Please write an article about it, when done or at least add here some comment.
 
Share this answer
 
Comments
Maciej Los 2-Jun-20 6:15am    
5ed!

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