How To Deploy a C++ DLL - c++

I have written a dll in visual studio community 2017. To be used as a general purpose library. Which could be ideally used for any c++ program for any compiler.
How will I best deploy it. (An installer)
In Visual Studio, I can simply add the project and reference it through settings in my IDE, but for it to work in any IDE, what kind of installer project should i use and what all files should be included and how.

You can't deploy a C++ DLL for all compilers. C++ doesn't have an ABI. Not even MSVC++ is compatible across versions, let alone compilers from different vendors.
The Windows solution for binary compatibility is COM. Conveniently, MSVC++ will use the COM ABI for classes that inherit from IUnknown, although you'll also have to adhere to other COM rules for full compatibility. E.g. you can't rely on dynamic_cast, you need QueryInterface.

Related

Why the standard of naming of C++ functions is not exist?

I write the plugins for AutoCAD. If I write the managed (i.e. .net) plugins, then I can use any Visual Studio version which can work with .NET Framework version which are used by AutoCAD (it is very convenient):
AutoCAD 2009 can use .NET 3.0, 3.5
AutoCAD 2010 can use .NET 3.5.
...
AutoCAD 2016 can use .NET 4.5, 4.5.1
So, through Visual Studio 2013 I can write the .net plugins for AutoCAD 2009-2016.
But sometimes I need to write unmanaged plugins for AutoCAD, because its managed .net API covers unmanaged API (ObjectARX SDK) not complettely. ObjectARX is API for C++. At this case I can't use the same Visual Studio for each AutoCAD version. For example, I am to use VS 2005 for AutoCAD 2009 plugins writting. Therefore I have installed VS 2005-2013 on my virtual machine. It is very unconvenient in my opinion.
I know, this problem exists because the standard of C++ functions naming is not exist and each version of VS has own rules of the name generation for the functions which aren't marked by external "C".
But why this standard is not exist still? What the reason of it? I am sure this reason is exists. Such behaviour is unconvenient is not for me only (I asked other programmers about it). But they don't know why each new VS version has own rules of C++ function naming and why standard of nameing of C++ functions is not exist.
Thank you.
A standard does exist, see https://mentorembedded.github.io/cxx-abi/abi.html#mangling
But not all compilers use it, because they have their own mangling conventions that they have used for many years, and they don't want to change them for various reasons.
In your case the differences between different versions of Visual Studio are not just name mangling, there are changes in the C++ runtime library and the standard library.

Is it possible to use vs2010 c++ and use Qt for all platforms?

What i hear about Qt, is that it is providing an operating system independent layer.
To do well most tasks a coder normally does. To perform at best the code has to be c++
While there is also mono providing some translation to c++ and there Dot24 an android c# kernel.
Currently the things we do, cannt be done in mono, for hardware reasons.
So i am thinking of going back to pure C++ and QT instead of C#.
Now what i am wondered about
By itself c++ is a standard and should also be idenpendent for linux/windows/unix/microboards/Ce devices etc etc.
But if i would write using VS2010 c++ and QT would i still have advantage my code would run on a wide range of platforms ? . As visual studio, creates a windows based exe? Or should i use also another IDE to write truely independent c++ with Qt?
C++ is a compiled language, whatever IDE/compiler you'll use it will produce executables for a certain platform. But the point of Qt is that, as far as you avoid platform-specific code, your sources can be recompiled on the various platforms, generating a different executable for each supported platform. So, using VC++ is not a limitation as far as sources are concerned.
The limitation comes instead from the build system: Visual C++ uses its own format for project files, which is not compatible with makefiles & co. So, if you started your project as a VC++ project, you would have to re-create manually a Makefile or similar to compile on other platforms.
To avoid this kind of problems, Qt provides qmake, a tool that, provided a .pro file (roughly equivalent to a .vcproj), is able to generate build files for various platforms: .vcproj/.dsp on Windows, Makefile on Linux and OS X, XCode projects on OS X and probably others.
So the point is: you can use Visual Studio, but you should use Qt's build system to be able to port your application to other platforms without any fuss.
Also, you can consider using Qt Creator, which supports directly .pro files, has particularly good integration with the Qt features and works on Windows, Linux and OS X; on the downside, I noticed that the debugger in Visual Studio tends to be way better.
If you have cross-platform C++ code using Qt, you can edit and compile the Windows version using Visual C++ (the compiler that comes in Visual Studio).
Visual C++ still only creates Windows executables, though, so to actually build and run on other platforms, you'll have to get another compiler (but feed in the same source code).
One pain point will be with makefiles: visual Studio has its own project format and cannot process standard makefiles. Neither do other platforms use Visual Studio projects. Visual Studio does come with a tool called nmake which is similar to POSIX or GNU make, but still not compatible except for the most trivial features. And of course cl.exe uses different command-line switches than other compilers. So you'll end up maintaining one set of C++ files but two or more sets of makefiles.
Yes it is possible to develop Qt applications in Visual Studio that can be used on other platforms. For example for my work in medical imaging research, I develop all of my Qt based applications in Visual Studio 2010 with the visual studio project files generated using CMake and at times build some of these applications in linux under QtCreator or KDevelop using the same CMakeLists.txt to generate project files for for these IDEs. As long as I stay away from platform specific code the porting is not that difficult.
In order to develop qt apps qtcreator is the best ide, qtcreator available on linux and mac, so you can open your qt project and build on any platform easily.

VC++ 2010 SDK for VC++ 2008, 2005 clients

I want to write SDK using Visual C++ 2010, which can be used by VC++ 2010 clients, and also old VC++ version clients. Let's say, I want to have it compatible for 2005 and 2008 versions. SDK contains several h, lib and dll files. Libraries have exported C++ classes and global functions. Public SDK interface (h-files) doesn't contain any feature that is not supported in previous VC++ versions. Internal SDK implementation may contain such features (like Lambda expressions, rvalue references etc.).
Some public SDK methods have callback interface parameters. Callback interfaces are defined in my h-files, implemented in the client code and passed to my methods. Can this be a problem?
I made several small tests and found that it works. Does anyone know any problem with using VC++ 2010 SDK by C++ clients, written in old VC++ versions?
Key principles:
You cannot expose any objects from the standard C++ library (std::string etc), their layout is not compatible
You cannot use exceptions, SEH is okay
You cannot return any pointers that require the client code to release the pointed-to resource
You should build with /MT so the client doesn't have a headache digging up the required CRT version
You are generally okay with object layout between 2003 through 2010 as long as you can ensure it is not affected by compiler settings other than /Zp. Virtual inheritance has been troublesome. Verify that sizeof yields the same size regardless of the selected configuration.
COM is a good way to ensure maximum compatibility.

Using a pure C++ compiler versus Visual C++

I searched around for the answers to these questions, but I have had little luck. So, I thought I would post them here to get some clarification. If this is a duplicate, please let me know, and I will close this.
Okay, with that said, I would like to begin learning C++. I come from a C# background and I have a great respect for Visual Studio and what it can do. Now, my question is. How well does Visual Studio's compiler work for C++ as opposed to a non-Microsoft version (such as MinGW)?
My thing is this. I have nothing wrong with Microsoft, but I would really like to learn C++ in a "pure" form and not scewed by any particular implementation. How reliant is Visual C++ on the .NET Framework? Can a "pure" C++ application be created through Visual Studio without any .NET usage or overhead? Does the Visual Studio compiler compile C++ into CIL like it does with C#/VB, or does it compile it all the way down as others do?
Thanks for any help anyone can provide!
The Visual C++ compiler will compile C++ code into standalone EXEs that have nothing to do with the .NET framework.
The only way to get the .NET baggage thrown in is to compile the C++ as "managed".
If you create a new project (File|New|New Project) Then choose "Win32" from the Visual C++ submenu in the project types and choose "Win32 Console Application" Visual studio will create a simple project with a couple of source files that will compile to a little executable.
Most of the time, Visual C++ is very similar to other compilers. Avoid #pragmas, microsoft libraries (MFC, ATL) and you should be fine.
Edit (thanks Cheeso) - Documentation of where Visual C++ diverges from standard.
In general I would advise using boost libraries for threads and networking because they work on many platforms (i.e linux). Also if your code can compile in GCC and Visual Studio then you are doing a good job keeping it portable.
The most recent versions of VC++ have become significantly more compliant to the C++ standard, so it's not really an issue to write "pure" C++ using Visual Studio, presuming that you stay out of the Windows API, COM+ and ATL. In fact, the documentation with Visual Studio is very rich, with details on the standard libraries and the STL, so it can help you learn a great deal. It can't teach you everything, but it's certainly loaded up with a wealth of information that is portable to any compiler and it is very easily accessbible inside the IDE.
If you create a new solution you should choose new Win32 Project, or Win32 Console Application, and check the 'Empty Project' option. Then you can add a main.cpp file, and add your standard C++ code.
If you like Visual Studio, go ahead and use it to learn C++ -- I haven't used the very latest version, but even the previous one was pretty standards-compliant, C++-wise, and I assume the latest one can only have gotten better. You can have many different kinds of project in Visual Studio, including "console apps", which are the "plain vanilla" kind you could make on any platform, and also many other kinds, such as, windows apps using the good old win32 api, ones made with MFC or other frameworks older than .NET, .NET ones using "managed code", etc.
Just make sure you always work in a "console app" project, and you'll be operating pretty closely to how you would be on other platforms and/or with other C++ IDEs.
If you limit yourself to writing ANSI C++ compliant code then what you write in VS will work in other compilers, until you have to interact with a graphic interface or IO. Then you need to make certain that you are using something that is portable, such as OpenGL, and not DirectX.
To set your project the steps here may be useful:
http://bytes.com/topic/net/answers/447572-strict-ansi-c
Microsoft Visual Studio 2005 comes with a very good, C++98 standard compliant pure C++ compiler. If you are interested in pure C++, don't forget to disable language extensions in project settings and you are good to go. Nobody is going to force you to use .NET framework, MFC or anyting like that. Just pure core C++ language and C++ standard library.
Of course, just like any other compiler, it has known non-compliance issues, but in general it is, again, surprisingly good. Older versions of their compiler (MS VS 6.0 specifically) suffered from many non-compliance problems and could not even compile its own header files with language extensions disabled. In 2005 version they fixed a lot of these issues.
After creating a standard Win32 project, you can turn up the compliance a bit more. On the project properties sheet, there's a C/C++ category, with a Language entry. This lists a number of cases where VC++ can differ from the standard. Here, you'd want to turn OFF language extensions, and turn ON "wchar_t as built-in type", "for-loop conformance" and "RTTI support".

What is the difference between "VC++" and "C++"?

Someone asked me how familiar I am with VC++ and how familiar I am with C++. What is the difference?
C++ is the actual language, VC++ is Microsoft's Visual C++, an IDE for C++ development.
From stason.org:
C++ is the programming language, Visual C++ is Microsoft's implementation of it.
When people talk about learning Visual C++, it usually has more to do with learning how to use the programming environment, and how to use the Microsoft Foundation Classes (MFCs) for Windows rather than any language issues. Visual C++ can and will compile straight C and C++.
C++ is the name of a programming language that has been approved by international standards committees (ANSI/ISO).
VC++ (“Visual C++”) is the product name of Microsoft's C++ compiler and sometimes, but not officially, the IDE it's shipped with (“Visual Studio”).
Well, Visual C++ used to stand for the Microsoft C++ compiler plus the MFC library. Basically there's no difference in the language itself, but VC++ includes a library, and some IDE support, for easily building GUIs.
vc++ is a development environment and c++ is a language
VC++ means different things to different people. You can use the Visual Studio environment to build (almost) standard C++ applications. You can also use it for Micrososft-specific additions - which vary from version to version. For example, the MFC components for windows applications, or the newer C++/CLI for .NET applications
VC++ is short for Visual C++, and is an IDE (integrated development environment) developed by Microsoft, included as part of Visual Studio. C++ is a language.
C++ is a language, VC++ (Visual C++) is a Microsoft development environment which was a forerunner to Visual Studio which helps you write C++.
You can know everything there is to know about C++ and never have seen VC++.
VC++ is IDE developed by Microsoft using microsoft c++ compiler.while C++ is the programming language.
Visual C++ and C++ are two entirely different things. They are related, though.
C++ is a high-level programming language that a compiler translates into machine code a computer can understand and execute.
Visual C++ is a tool created by Microsoft to make writing, compiling and debugging C++ source code easier. Visual C++ is an Integrated Development Environment (IDE).
http://www.cplusplus.com/forum/beginner/172353/
In some cases, they refer to its corresponding C++ implementation and its compilers.
C++ refers to standard headers/functions and its GCC C++ compiler.
VC++ refers to Microsoft implementation of C++ standard and its VC++
compiler.
They are not compatible with each other. Linux network/threading functions, numeric data types are different than its Windows counterpart. You can't compile Linux C++ code directly in Windows without using third-party GCC ports such as Cygwin/MinGW.
Most academic/research tools and libraries are written in C++ (GCC), and one will have the hard time to compile those in VC++.