Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The following is how I was able to get MinGW to build a DLL to be used in Excel 2003 VBA.</p> <p><strong>fooBar.cpp</strong></p> <pre><code>int __stdcall Foo(int x) { return x * x; } double __stdcall Bar(double x) { return x * x; } </code></pre> <p>1) Start MinGW shell and create a directory called <code>fooBar</code> . Close the Excel Workbook (if open).</p> <pre><code>mkdir -p fooBar cd fooBar rm *.a *.dll *.def </code></pre> <p>2) Compile and generate a .def file - <strong><em>Note: this dll will not work because it has mangled symbols.</em></strong> </p> <pre><code>gcc -shared -o fooBar.dll fooBar.cpp -Wl,--output-def,fooBar.def,--out-implib,libfooBardll.a </code></pre> <p>The generated fooBar.def will look something like:</p> <pre><code>EXPORTS _Z3Bard@8 @1 _Z3Fooi@4 @2 </code></pre> <p>3) Modify the generated fooBar.def file by adding clean symbol aliases for the generated symbols. fooBar.def should now look something like:</p> <pre><code>EXPORTS _Z3Bard@8 @1 _Z3Fooi@4 @2 Bar = _Z3Bard@8 Foo = _Z3Fooi@4 </code></pre> <p>4) Cleaup again (except for the modified fooBar.def) </p> <pre><code>rm *.a *.dll </code></pre> <p>5) Compile with .def file with clean symbol aliases for the generated symbols.</p> <pre><code>gcc -shared -o fooBar.dll fooBar.cpp fooBar.def -Wl,--out-implib,libfooBar_dll.a </code></pre> <p>6) Open Excel and add the following VBA code <strong><em>(make sure to use the proper path, doubt it will have mmorris in it)</em></strong>:</p> <pre><code>Private Declare Function Foo Lib _ "C:\MinGW\msys\1.0\home\mmorris\fooBar\fooBar.dll" _ (ByVal x As Long) As Long Private Declare Function Bar Lib _ "C:\MinGW\msys\1.0\home\mmorris\fooBar\fooBar.dll" _ (ByVal x As Double) As Double </code></pre> <p>7) If you want to call the functions from an Excel Workbook, in a cell type <code>=Foo(5)</code> or <code>=Bar(5)</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload