Passing Structures from C++ to a VB .NET DLL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gstarr
    New Member
    • Feb 2010
    • 2

    Passing Structures from C++ to a VB .NET DLL

    I'm having trouble getting the correct syntax for passing a structure from C++ to VB .NET.

    I have a VB .Net DLL program with the following code:
    [code=vb]
    Public Structure testParams
    Public iFirst As Integer
    Public iSecond As Integer
    End Structure

    Public Class clsKpdUI
    Public Function ShowForm(ByVal Param1 As testParams) As Integer
    ' Code
    End Function
    End Class
    [/code]

    I have C++ program with the following code:
    [code=c]
    struct testParams {
    int iFirst;
    int iSecond;
    };

    kpdUI::clsKpdUI myUI;
    testParams tp;
    tp.iFirst = 4;
    tp.iSecond = 3;
    myintR = myUI.ShowForm3( tp);
    [/code]
    When I try to compile the C++ code, I get the following Error:
    Error 1 error C2664: 'kpdUI::clsKpdU I::ShowForm' : cannot convert parameter 1 from 'testParams' to 'kpdUI::testPar ams' c:\test\Form1.h 133 TestKpdUIcpp

    How do I correct this error?

    Thank,
    Gary
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    You might read up in MSDN about VB/C++ interoperabilit y. There is sample code there for how to do this.

    Comment

    • gstarr
      New Member
      • Feb 2010
      • 2

      #3
      Thanks for the response. Someone else pointed out what I was doing wrong. Turns out that I need to reference the Structure that is defined in VB when I'm declaring the variable in C++

      instead of this in C++
      testParams tp;
      I needed to do this:
      kpdUI::testPara ms tp;

      Now it works like a champ.

      Thanks again... Gary

      Comment

      Working...