How to include/import a c++ app in VB.net - c++

Link grammar is a piece of software allowing for sentence parsing. It has an API that I hope to use (Details here) however the example is written in c++ and I'm a vb.net user. I've tried adding a reference to the file named:
link-includes.h
But vs2010 doesn't allow me to select this file since it's not one of the recognised file types for a reference. I've tried adding the above file to the solution but that doesn't allow me to reference it in any way (as far as I know). Any advice/hints/suggestions would be welcome!

A VB.Net project can't directly reference a C++ header file. In order to use C++ code from VB.Net, one of the following approaches will need to be used:
Compile the C++ code to a native DLL, which the VB.Net code can then P/Invoke
Compile the C++ code to a native DLL, which is then exposed via COM
Compile the C++ code in a C++/CLI project, which the VB.Net project can reference as another managed project (i.e., via project References)
Additional information can be found here: Invoke Native C++ DLL from .NET Code

Related

unable to generate pinvoke for extern c int _clrcall ... calling convention missing in metadata

I have a challenge running my project in Visual C++, by getting the above error. I linked some 2 third party .lib files (libglorycolx2010.lib & libglyde.lib) into the project which i successfully did but still getting the error. What might be the problem or am i missing something?
You are trying to mix both C++/CLI and C++ code. These are two separate languages. What is confusing to newcomers to Visual C++ is that it is possible to put code for both in the same source file.
However, winpcap is clearly meant to be for straight C++ code. If it's alright with you, simplify your program so that it is 100% unmanaged. That is, instead of using WinForms, stick with either MFC, plain Windows, or a console program. Trying to get C++/CLI to mesh with unmanaged code is a skill that requires a strong knowledge about C++/CLI.
https://social.msdn.microsoft.com/Forums/en-US/22fd5e36-084f-4a3d-896b-4aed820066e2/visual-c-2010-express-and-winpcap-compiling-issues?forum=Vsexpressvc

Referencing a .net 4 library via COM in vs2005

I have a visual studio 2005 c++ project (that uses QT framework). I would like to reference and use a .net 4 library that I have via COM. I know that if I have a .net project (.net 2 or .net 3.5) in 2005, I cannot reference the .net 4 library but I am curious to know if I would have any issues trying to use it in a c++ project thru COM. I'm not at a point were I can create and test a proof-of-concept application yet so I was wondering if anyone else has tried this or know anything about it.
Thanks
Using COM is a fine way to get the CLR loaded so you can execute managed code. But you'll have to use COM programming techniques in the C++ code. Using Add Reference doesn't work, that's a option that's only available if you write managed code in the C++/CLI language.
One good way is to use the #import directive in your C++ code. That can load a type library and auto-generates smart pointer types and method wrappers that you can directly call in your C++ code. Generate the type library you need with the Tlbexp.exe utility or the Regasm.exe /tlb command line option. QT has built-in COM support as well, I don't know enough about it.

Migrating Net free C++ code written in VS 2005 to Visual C++ in VS2010

Our VB6 program currently calls code in a C++ dll. This dll does not need to be registered, it only needs a .def file specifiying the properties and methods. Vb6 late binds to it. The dll is written in VS2005 without a dependency on the Net framework.
As we are migrating our application to Net4 and also want to enhance the C++ dll with new functionality, I was wondering how to migrate the existing C++ code to VC++. I suppose thereafter the dll will just happily integrate in our solution which already contains C# and VB.Net libraries too.
Is there some tutorial/documentation about the do's and don'ts of this plan?
EDIT:
I think I have some basic misunderstanding about VC++, thinking that it can be ported to 100% managed code while keeping the C++ syntax. The replies I get seem to indicatie that VC++ will always produce native, unmanaged code?
From a pure C++ point of view, you should be able to convert the VS2005 solution and project to VS2010 automatically. If I recall when you load the solution or project into VS2010 it will automatically convert it for you.
If you open the VS2005 project file in VS2010, VS2010 will automatically convert the old project to the new project format and the auto-conversion will do it's very best job to get everything correct. This usually works, but not always. So the moral of the story here is, double-check all of the new project's compiler/link settings, to be on the safe side.
Also with VS2010, you have some better interop possibilities between managed and native code: P/Invoke and C++/CLI. P/Invoke is simpler, but you will find that stuff may compile but fail at runtime. C++/CLI is way more flexible, a bit more work, but makes it much easier to debug the interop, when it becomes necessary.

Is there an API for generating well-formed unmanaged C++ (similar to CodeDOM)?

Is there any library or project out there that can give me an API to generate C++ code similarly to how CodeDOM does it?
There is a C++ CodeDom provider that is part of .NET 3.5. It's in a separate DLL, and not always mentioned with the VB and C# ones, so it can be hard to find. See here

Referencing an unmanaged C++ project within another unmanaged C++ project in Visual Studio 2008

I am working on a neural network project that requires me to work with C++. I am working with the Flood Neural Network library. I am trying to use a neural network library in an unmanaged C++ project that I am developing. My goal is to create an instance of a class object within the Flood library from within another project.
There is plenty of documentation online regarding how to reference an unmanaged C++ project from within a C# project, but there is not enough information on how to reference one C++ project within another. Similar to how I would do it in C#, I added the Flood project as a reference in my other project, but I have tried all sorts of techniques to work with the object. I have attempted to use the #include directive to reference the header file, but that gives me errors stating that I need to implement the methods declared in the header file.
How to add a reference in unmanaged C++ and work with the class objects?
Yes. You need to do two things:
#include the respective header files, as you did
Add a reference (Visual C++ supports two types, "dependencies" which are outdated and should not be used anymore, and "references" which are the correct ones). Use them to reference the other project, which must be a part of your solution. Meaning, in this case you must be able to COMPILE the other project.
Alternatively, if you do not have the source code, or you do not wish to compile the 3rd-party code for any other reason, you may also reference a compiled binary. The best way to do it is pragma comment lib. If this is what you need, please comment and I will edit my response.
Looking at the provided vcproj file, the flood distribution is really weird, and builds an exe file.
As such, the supported way to use Flood in your own project is not via two projects (being your application and a "libflood" project) - But simply to add all the flood cpp files to your own project and build that.