Is it possible for MinGW g++ to understand the type library of a COM server? - com

Since the command-line tools x86_64-w64-mingw32-widl on Linux and widl on Windows both are able to produce type libraries, the .tlb files, for COM clients to import, it's reasonable to surmise that it might be doable to use MinGW toolset to build a COM client that is able to acquire COM interfaces by using smart pointers offered by the .tlb file, instead of calling function CoCreateInstance to get the interfaces. The question is how?
Visual C++ has its nonstandard directive #import to introduce the smart pointer types (and other stuff) to C++ code. What is the counterpart when we are using MinGW g++?
By the way, I've been googling all day and found it difficult to find useful information about "MinGW + COM". Most of them use Visual C++. If you know somewhere out there a good online tutorial on this topic is, please let me know. Thanks.

Related

How to specify a binary to use some specific dll files?

We are developing audio plugins which are dynamic libraries. This made it very hard to use 3rd-party libraries such as Qt, as our product DLL would search for Qt's DLL on host DAW program's executable directory, and it is impossible to install our dependent DLLs to that position (you don't know which host will be used, and host may even be installed later than the plugin).
I've made some brief search on this problem, the few answers direct me to a Microsoft technology called side-by-side assembly, and I'm almost drawn in the huge documentation and concepts on that. So my question is:
How to make my DLL to load several specific dependent DLLs located at path_to_plugin/MyPlugin_dependents/xxx.dll?
Or is there any examples to side-by-side assembly that simply do this and is much simpler than the official example?

Compile Solution without DLL's Visual Studio Managed C++

I'm very new at C++ Managed and Visual Studio keep this in mind. Ive programmed an application that makes it easy for users to bind keys in counterstrike, found here:
https://sites.google.com/site/intrepidprojects/
The first error I ran into with my friends testing the program was "msvcr120D.dll is missing". Which lead me to finding that I have to set the runtime library to Multi-threaded (/MTd), if I don't want the users to download the Visual Studio c++ dll's . When I choose this option I was given the error that /MTd and /clr are incompatible. So I turned the common runtime support to no support. Now all of the namespaces are invalid such as 'System', 'Collections', etc.
My question is how do I produce a stand alone application without needing the dll's? Every solution I have come across leads me to more errors I do not understand.
Again, the language I am using is c++/cli. Sorry If I am not using the proper lingo to communicate my errors I am teaching this on my own.I am aware that this question has been asked many times before, but the answers are not leading me to solutions.
My question is how do I produce a stand alone application without needing the dll's? basically: you don't. Just have them install the CRT runtime - the'll need it anyway sooner or later as you're not the only one writing programs targetting that toolset (btw, you tagged the question VS2012 but those dlls are normally for VS2013?). As an alternative you could look for all the needed dlls (msvcr120.dll, msvcp120.dll etc, use Dependency Walker) on your filesystem and put them in the same directory as your executable, that works as well because of how the path is searched for dlls. But it's a bit messy.
Furtermore missing msvcr120D means you are building your project with the Debug configuration (that is what the D stands for), but you should build with Release configuration when shipping to users as the runtime installer only installs release versions.
Select MT without DLL in VC++/C Code generation section in solution properties. Worked for me.

Why implicit linking to DLL needs a lib file on Windows

On Linux platforms you need only the .so file when you want to implicitly link to it.
Why Microsoft developed the approach where you need a .lib file also. Doesn't the DLL contain all the information for the linker to be able to link to it?
From my experience the "Windows way" is more clumsy and creates problems when you want to mix different compilers and linkers.

LoadLibrary MSVCRT Issue

There are two questions that confuse me:
I read from the Microsoft website that we can not use different C runtime in the same project. Say I have a dll compiled with /MT flag, then I can not use the dll in a /MD compiled project. My question is that if I use LoadLibrary() to load the dll, is it also necessary that I have the same C Runtime? What's the potential danger if I don't?
I think with the /MT flag, the runtime is statically linked into the binary file. But for one of my dll project, I made a dll with /MT. However, when I dumpbin.exe /dependents mydll, it shows that MSVCR100.dll is a dependent. My question is that why the dll is still dependent on MSVCR100.dll?
1) No, that's not a requirement. This happens in any program, the Windows DLLs use their own CRT for example. Mixing CRTs in one program is however very dangerous and can cause very hard to diagnose problems. The Windows apis were carefully designed to avoid those problems, they never require code to release memory that was allocated in a DLL, don't use exceptions, don't use standard C++ library classes, don't depend on locale or any other kind of shared CRT state. The kind of things that go wrong when you mix. Restricting yourself to a C or COM api helps a lot to avoid these traps.
2) This will happen when you link code that was compiled with /MD. Common with .libs you link.
You stay out of trouble by always using /MD when you have DLLs in your project and compiling all code with the exact same compiler and options. Static libraries you didn't build yourself are very troublesome, avoid them.
Regarding your 2. question, the dependency is indirect. Your DLL uses a DLL which depends on MSVCR100.dll. Using Dependency walker you can see the dependency tree of your component and see which library is directly and indirectly dependent.

How to Compile a c++ program using .NET Framework libraries

i want comile a my c++ program using .NETFRAMEWORK libraries only at command prompt.how can i do this ??
Download the free Visual C++ Express tools from Microsoft and use the C++/CLI language (based on C++ but allows access to the whole .Net Framework) and go from there.
Basically, you're talking about Visual C++. As for using the command prompt, once you have a working program you should just be able to use something like:
cl MyProgram.cs /clr
with any other relevant options, and be up and running. If that doesn't help, give a more specific question.