Thread: VB with C++

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    5

    VB with C++

    VERY new to this, so if I start to talk about something or suggest something horribly wrong, please slap me!

    I want to begin to write some statistical software, I figured it is a good place to start. I am writing in C++ and want to write a UI with VB. If I understand things correctly from what I have been learning, Visual Basic is just the front end (although I know you can write in it as well), and my choice of program language is C++. SO... I should be able to write the C++ files and then reference them in my VB project - essentially passing values inputed through the UI of VB into the C++ files and then back into the UI.

    Do I understand this correctly?

    My next question is...

    If I am to do something similar to this - work with VB and program in C++ - what type of file am I creating? I don't want the console to pop up every time I want to pass int's or strings through a function that is separate from the main. So am I writing in Windows Console? Or Windows Application? Or what...?

    Hopefully you can see that I am lost - and hopefully I didn't misuse the nomenclature.

    Thanks in advance,

    -J

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It's certainly possible, but not always easy. What you want for your C++ project is a dynamic linked library (DLL) that exposes methods that VB can call. When writing projects with two languages, you must be careful since they're no always compatible with each other.

    Make sure that you use stdcall calling convention in C++ for one. And for second, VB uses typical COM (I think) strings, so they are not std::string or CString or char*, they are BSTR. VB also keeps track of the size of arrays, so I think VB uses some kind of structure with a member first that specifies the size of the array. You're going to have to improvise if you want C++ to accept your VB arrays. Although Microsoft recommends you pass the first element of your array when passing a VB array to a C++ dll, so maybe you can do the same and not have to worry about its format.
    Likewise, VB does not accept C++-type strings such as std::string or CString, but it can use C-style strings, char*. Any integral number is a no-brainer and is handled the same within the languages.

    There is more, but google is probably your friend. Good luck on that.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    The above is actually pretty much right.
    I think VB arrays are SAFEARRAYs.

    However, I would question your desire to use VB, which I asume to mean VB6. Yes being a VB app, it would be a Windows app, not a console one. Many of the VB6 OCX files do not work on Vista, and MS have no plans to make them work. So if your VB app uses a Winsock control for example, Vista will be a no no. I also presume you were planning on using MSVC6, since .NET wasn't considered?

    How about getting VS2005 Express (free) and doing the whole thing in .NET?
    Others will now also promptly suggest alternatives to using VB6 and C++...
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I'll add another suggestion. How about VB dot net and C# instead?
    C++ dot net is Microsoft lock-in.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    What's the point in C# here? It's pretty much the same as VB.Net, with a different syntax.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    My bad. I was interpreting...

    Quote Originally Posted by iMalc View Post
    How about getting VS2005 Express (free) and doing the whole thing in .NET?
    ...as VB dot net + C++ dot net, but perhaps it's just VB dot net which would work fine.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    I would recommend C# since interop is at least well documented on sites such as codeguru and codeproject. VB interop with C++ might be a tad hairy and may actually delay the development unnecessarily.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing an Array of Strings from VB to a C DLL
    By mr_nice! in forum Windows Programming
    Replies: 9
    Last Post: 03-08-2005, 06:16 AM
  2. C with VB ?
    By khpuce in forum Windows Programming
    Replies: 2
    Last Post: 02-21-2005, 08:00 AM
  3. Passing parameters from VB to C++ through ActiveX DLL
    By torbjorn in forum Windows Programming
    Replies: 0
    Last Post: 12-10-2002, 03:13 AM
  4. VB Calling Convention?!
    By minime6696 in forum Windows Programming
    Replies: 6
    Last Post: 03-27-2002, 04:39 PM
  5. Sending a string to C++ from VB 6.
    By VirtualAce in forum C++ Programming
    Replies: 4
    Last Post: 08-21-2001, 02:28 AM