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,
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.
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++...
I'll add another suggestion. How about VB dot net and C# instead?
C++ dot net is Microsoft lock-in.
What's the point in C# here? It's pretty much the same as VB.Net, with a different syntax.
My bad. I was interpreting...
...as VB dot net + C++ dot net, but perhaps it's just VB dot net which would work fine.
Originally Posted by iMalc
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.