Tech Off Thread

3 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

VB6 Fails calls .net dll return no value for method...

Back to Forum: Tech Off
  • User profile image

    Hi I do not know how to describe my problem at the topic.

    This thing related to vb6 calls -> com interop -> C# dll -> c dll

    I had fail miserably in VB6. I had get it work in c# and

    I had a C function:

    EXTERN int WINAPI CallValue(LPBYTE var1, LPBYTE var2, LPBYTE var3, int size);

    I do in C# dllimport:

    // will perform some calculations
    [DllImport("wenching.dll", EntryPoint="#1", ExactSpelling=true, CharSet=CharSet.Unicode)]
    private extern static int CallValue(byte[] var1, byte[] var2, byte[] var3, int size);

    In C# or VB.NET, i will do this:

    char [] var1value = Var1TextBox.Text.ToCharArray();
    char [] var2value = Var2TextBox.Text.ToCharArray()

    byte [] newvar1value = Encoding.ASCII.GetBytes(var1value);
    byte [] newvar2value = Encoding.ASCII.GetBytes(var2value);
    byte [] newvar3value = new byte [100];

    int size = 10;

    WenChingCls.Checker wcchua = new WenChingCls.Checker();
    int i = wcchua.CallValue(newvar1value, newvar2value, newvar3value, size);

    For loop ...
    str += newvar3value[i]

    It works in C# or VB.NET!

    Now in VB6.

    I used this code:

    dim var1value as String
    var1value = Var1TextBox.Text ' I enter 11
    dim var2value as String
    var2value = Var2TextBox.Text ' I enter 11

    dim newvar1value() as Byte
    newvar1value = (my_own_string_2_byte_func)(var1value) 'string 1, byte 49
    dim newvar2value() as Byte
    newvar2value = (my_own_string_2_byte_func)(var2value)

    dim newvar3value(100) as Byte

    dim wcchua as new WenChingCls.Checker

    dim i as integer

    dim size as integer
    size = 10

    i = wcchua.CallValue(newvar1value, newvar2value, newvar3value, size)

    Fail to see any value from newvar3value:

    during debugging watch:

    newvar1value[0] = 49
    newvar1value[1] = 49

    newvar2value[0] = 49
    newvar2value[1] = 49

    newvar3value[3] = 0
    newvar3value[1] = 0 // no output value! why?

    I am not sure why it cannot get the value? I am using vb6 app to call a COM References of my .net library. I can confirm that i had called a c# dll from vb6 before.

    Any tips for me please? Is this vb6 weaknesses?


  • User profile image

    hi chuawenching

    I'm not a vb or an interop expert, so could be way off the mark here.... From what you describe it could be how you are declaring your c# WenChingCls.Checker.CallValue method.

    Do you declare the third parameter to this as ref byte[]. If not then the COM interop layer would discard the output params before the vb client sees them...

  • User profile image

    Oh yeah. Thanks. Fix it.

    I noticed that c# out and ref have huge problems when vb6 calls them. Only will happen on arrays.

    So i better re-create that function that returns an array.


Conversation locked

This conversation has been locked by the site admins. No new comments can be made.