Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have made a COM interface to wrap my .Net libraries as they are given data from some VB6 programs. However, now I'm unsuccessfully trying to communicate with a C++ using the same interface.

It all works fine in VB6, but I can't make it work in that .Net COM interface.

The C++ program calls the ProcessData method, expecting it to return a Long and alter the value of byteOut.

This is how it works ok in VB6:
VB
Public Function ProcessData(ByRef bytDataIn() As Byte, ByRef bytDataOut() As Byte) As Long
On Error GoTo ErrPoint
     bytDataOut = Str2ArrByte(proxy.ProcessData(bytDataIn))  '
    ProcessData = 1
    Exit Function       
ErrPoint:
    ProcessData = 0
End Function

And this is how it does NOT work in C#:
public interface IComClass1
    {
        [DispId(1)]
        string ProcessXML(ref byte[] byteIn); // this is the OK working method called from VB as seen above
        //... another methods for VB, ...
        [DispId(5)]
        long ProcessData(ref byte[] byteIn, ref byte[] byteOut); //but the direct calls from C++ do NOT work
    }

public class ComClass1 : IComClass1
    {
      ...     
      public long ProcessData(ref byte[] byteIn, ref byte[] byteOut)
        {  
             long LRet = 0;
             try
             { byteOut = processByteArray(byteIn); /* any method returning byte[] */}
              catch
             { LRet = 1; }            
             return LRet;
         }
      }

So far, I can bypass it by using the VB library as another in-between, but although working I don't find this solution optimal. Should I use marshalling? I tried already, but with no positive result...
Posted
Updated 10-Feb-10 5:36am
v3

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