Help C++ and VB

Im trying to integrate some C++ into a large VB project using .NET 2003
if someone can help me integrate this into the VB project that would be amazing.

basicaly i want:

=========C++=========
public class CppClass{
public:
    CppClass();
    int go(ObjVB *oVB){
       oVB->function1();
       oVB->function2();
       .....
    };
    ~CppClass();
};

=========C++=========
=========VB=========

Sub VBsub()
Dim myCppClass As New CppClass
Dim myObjVB As New ObjVB
Dim num as Integer

num = myCppClas.go(myObjVB)

End Sub
=========VB=========

so far i am able to create the .Net C++ object in VB by adding a refference to the C++ class but im still fuzzy on how to pass the myObjVB to the C++ class because the c++ class does not know what a ObjVB is...

Thanx in advance..


Answer this question

Help C++ and VB

  • Chris242

    has anyone ever used vb and c++ in the same solution before

  • mjhadden

    I forgot to add that the VB code and C++ code are 2 projects in the same solution, i have added refferences to both projects. i have allready made an instance of the C++ class in vb and had it return a number and msgbox the value.


    example:
    =========VB==========

    MsgBox(CppObj.go())

    =========VB==========

    =========C++==========
    int go(){

        return 5;

    }

    =========C++==========

    Basicly it made a msg box with the number 5.

    I guess my question is, is it possible to pass a instance of a VB class object to a C++ function and make calls to it in the c++ function, if you need any other information just let me know or if you know where this should be posted in the forums.

    Thanks again.


  • Den1se

    i see what your saying, the only problem is that my objVB is very complex and cannot be mirrored. also im not using a .dll, its a C++ project

    my solution is set up:

    Solution
     | --vbProject
     |             |-----References
     |                             |-----cppProject
     |                             |-----mscorlib
     |--cppProject
     |             |-----References
     |                             |-----vbProject
     |                             |-----mscorlib

    i've also been playing around, keeping it simple
    right now i get complier" error C2065 'objVB' : undeclared identifer"

    my code is like this:
    -----------------------
    int cppClass::go(){
       
        objVB *test;

    }
    -------------------------
    and if i hover the mouse over objVB it says "__gc class vbProject::objVB" in a popup bubble. now should i have some type of "using vbProject" im a little new at this cross compiling with vb and c++ in the same solution....

    ------------------------------------------------------------------------------------------
    here's the actual code
    c:\Programming\haDBX\haDBX.cpp(10): error C2065: 'clsLogging' : undeclared identifier

    --------haDBX.h-----------
    #using <mscorlib.dll>

        public __gc class haDBX
        {
        public:
            haDBX();       
            int go();
        };
    --------haDBX.h-----------

    --------haDBX.cpp-----------
    #include "haDBX.h"

    haDBX::haDBX(){

    }

    int haDBX::go(){
        clsLogging *bob;

    }
    --------haDBX.cpp-----------

    im thinking im missing some includes/using/somthing

  • HarrisTL

    Can anyone help

  • Zak Jensen

    I recommend Passing a structure to the C++ dll that is mirrored in C++

    like this

    --------vb---------

    <DLLImport "TEST.DLL"> Private Shared Function Test (byref _OBJStructure as objStructure) as integer

    public structure objStructure
     dim x as integer
    dim y as integer
    end structure

    public function invokeDLL(val as integer) as integer

    dim xObj as objStructure
    xObj.x = 1
    Test (xObj)
    return xObj.y


    end function

    -----------c++----------------

    struct objStruct
    {
    int x;
    int y;
    };

    int __stdcall Test(objStruct *xObj)
    {
       xObj->y == xObj->x + 1;
    }

    ---------------------------------

    Try that

  • Help C++ and VB