Creating C++ .dll for use by Excel & C# (32/64bit Window)

后端 未结 2 1668
抹茶落季
抹茶落季 2021-01-24 04:40

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

相关标签:
2条回答
  • 2021-01-24 05:37

    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:

    1. Personally I'd start off with the "Empty Project" template - I don't like all the unnecessary headers and (seemingly) complicated initial project settings that the Win32 template provides. I would then manually add my own .c/.h/.cpp files myself and code-away.
    2. If you're just exporting functions rather than COM types then you don't need to worry about interfaces. As long as your functions are exported correctly (see here: http://msdn.microsoft.com/en-us/library/ys435b3s%28v=vs.80%29.aspx ) then they are callable from .NET (incl C# and VB.NET) and VB6/VBA, and C/C++.
    3. "other PC"?
    0 讨论(0)
  • 2021-01-24 05:44

    About #2, you don't need two sets of interfaces because C# can also use the __stdcall calling convention.

    0 讨论(0)
提交回复
热议问题