Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

VB and C++ workin together

baby shellbaby shell Member Posts: 2
im new to vb but a good c progrmmer, and i want to create the functions and classes on C++ and the interface with vb then link the buttons to the functions. how do i do that.plz detailed info with baby steps.

Comments

  • BitByBit_ThorBitByBit_Thor Member Posts: 2,444
    : im new to vb but a good c progrmmer, and i want to create the
    : functions and classes on C++ and the interface with vb then link the
    : buttons to the functions. how do i do that.plz detailed info with
    : baby steps.
    :

    I think (am pretty sure) that if you want to use C++ classes you need to expose them through the COM model.

    VB also allows you to reference external functions that are defined like the Windows API's.

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • baby shellbaby shell Member Posts: 2
    : : im new to vb but a good c progrmmer, and i want to create the
    : : functions and classes on C++ and the interface with vb then link the
    : : buttons to the functions. how do i do that.plz detailed info with
    : : baby steps.
    : :
    :
    : I think (am pretty sure) that if you want to use C++ classes you
    : need to expose them through the COM model.
    :
    : VB also allows you to reference external functions that are defined
    : like the Windows API's.
    :
    : Best Regards,
    : Richard
    :
    : The way I see it... Well, it's all pretty blurry
    thanks Richard but i want more detailed guide.guide me step by step
  • BitByBit_ThorBitByBit_Thor Member Posts: 2,444
    : thanks Richard but i want more detailed guide.guide me step by step

    Well, as I indicated in my previous post you have to make sure your C++ program exposes the functions in a to VB understandable way.

    I don't know enough about COM classes to help you with that, sorry.
    And I forgot how to declare 'public' functions in C dll's. I think it was as easy as using "extern __stdcall", or was it "extern __cdecl"?
    You'll need to check how the Windows API's are defined in the C headers for Windows. I believe they use a pre-processor defintion of WINAPI at times, which should be declared as either __stdcall or __cdecl.

    Then the part you need to know in VB:
    Put this in a module. If you put it into a form, make it private
    [code]
    Public Declare Function CSuperFunction Lib "superc.dll" ( _ &
    ByVal x As Integer, ByVal y As Integer, ByVal szData As String) As Long
    [/code]
    This is a typical declaration of the C function:
    [code]
    LONG CSuperFunction(int x, int y, char* szData);
    [/code]
    In the file superc.dll

    Basically, you replace the names and the parameters by what suits your function.

    After this line, you can use it as if it were a VB function :)

    Not that the type conversion etc isn't as easy at it might look!
    Best is that you post the functions you want to export and I'll give you the VB equivalent.

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • BitByBit_ThorBitByBit_Thor Member Posts: 2,444
    I did some testing myself.

    Follow all the instruction on that site and combine it with the VB code I gave in the previous post.

    Site: http://www.codeguru.com/forum/showthread.php?t=231254

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
Sign In or Register to comment.