Recently I would like to start building a .dll maths library with Visual C++ Express 2010.
I would like to use the .dll as library reference for BOTH Excel VBA
& C#
applications. I expect it will work in both 32bit/64bit
Window. The .dll should also be able to be used by other PC after build.
Am I correct to start by using Win32 Project? (it seems I cannot use
ATL / MFC
in Express version)Do I need to specify in the .dll 2 different sets of interface for VBA & C# to load functions? (VBA require using __stdcall)
Any deployment settings for using the .dll in other PC? (need any regsvr32 cmd process?)
Any beginner example for making a C++ DLL to export a class? (e.g. VBA / C# can instantiate a new class from this dll) ...
Because I am not sure if I can instantiate ClassA & ClassB in VBA / C# with below .header file in the c++ .dll:
#pragma once
#ifdef DLLDIR_EX
#define DLLDIR __declspec(dllexport) // export DLL information
#else
#define DLLDIR __declspec(dllimport) // import DLL information
#endif
class DLLDIR ClassA
{
public:
void AMethod1();
void AMethod2();
};
class DLLDIR ClassB
{
public:
void BMethodi();
void BMethodii();
};
You cannot use C++ to build a DLL file that exports COM types or C-style functions and have it work in both a 32-bit and 64-bit environment. DLL files are a kind of PE/COFF image, and PE only supports one ISA per file (compare to the Macintosh executable format which allows for multiple ISAs in the same image file). You have to recompile twice, one for x86, the other for x64. The only exception to this rule are .NET "AnyCPU" DLLs, but that's another story.
According to this comparison table, C++ Express 2010 does not include the x64 compiler, nor does it include the MFC and ATL libraries, though you can download these as part of the Windows SDK separately.
In response to your questions:
About #2, you don't need two sets of interfaces because C# can also use the __stdcall calling convention.