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.
Related
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
The idea is to share code between a desktop app using Mono and a dot42 app. So my question is: Is there any way to import a Portable Class Library or even a common library in a dot42 ? If not, is there any way to share code at all between them ?
Thanks.
A dot42 project is either a Visual Studio or SharpDevelop project. There is nothing preventing you to add a class library project to your solution consisting of the same C# source code that is used in your Mono project.
The .NET types are implemented on top of the Android API. For example, the .NET Dictionary class is implemented as a wrapper of java.util.Map and System.String as a wrapper of java.lang.String. In other words, we take the API from .NET but the implementation from Java. This is in contrast to Mono.
When you refer to .NET types and compile your dot42 project to an APK, the .NET types compile to a minimum amount of wrapper DEX code that invokes the Android framework. It therefore does not require an extra runtime and makes the APKs really small.
Here is the API reference of all .NET types that are currently supported (work in progress):
http://docs.dot42.com/Reference/NS.System
We are working on adding support for Portable Class Libraries.
Disclosure: I work at dot42
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.
I have inherited an old C++ (MFC) project and will have to add new functionality.
The new functionality will mostly not conflict with the existing C++ code, like additional dialogs etc.
Having limited experience with C++ MFC, I would very much prefer to do the additional functionality in Delphi, create a DLL and use the DLL in the C++ project.
I guess this is generally possible, similar to using C++ DLLs in Delphi?
Are there limitations on what can be done this way?
Basically, there are no issues. But if you're going to use dialogs and so on, your application will be using two frameworks, MFC and the VCL, and they may not play very well together.
Delhi if I recall my history should create Dll's happily. See here 'Calling delphi DLL from MS Visual C++' for an example
I know this is a very stupid question and I'm very new to C++.
I'm developing Starcraft AI, it is DLL file. I'm trying to use XML to gather some data to the bot, however whenever I build the DLL with /clr option. The bot doesn't load properly. So, my question is what is CLR and is there a way to read/write XML without using /clr build option.
Thanks so much.
The /clr compiler option enables the
use of Managed Extensions for C++ and
creates an output file that will
require the .NET Framework common
language runtime at run time.
(from MSDN)
Starcraft is probably not developed under CLR (.NET Framework runtime).
I've used the free tinyxml library from C++ code - it was quick to get running and reasonably efficient. Well, about as efficient as it's possible for XML to be, anyway.
Starcraft probably won't run .NET binaries. You would have to either write your own XML parser, which probably isn't for you seeing as you are new to C++, or find a C++ library that can do it for you.
Example of one:
http://sourceforge.net/projects/tinyxml/