Using VC++ 2010 Express
I am creating a dll to export a simple Multiply function so I can use it in Excel/VBA
These e are the steps I am following :
. Create a Win32 C++ Project and give a name. For example: CallDllFromVBA
. Select the DLL option in the Wizard and click Finish
. In the CPP file (here CallDllFromVBA.cpp), add the following code
1 2 3 4 5
|
#include "stdafx.h"
int _stdcall Multiply(int x, int y)
{
return x * y;
}
|
. Add a .def file and add the following contents
LIBRARY CallDllFromVBA
EXPORTS
Multiply
. Build the project
The Build output show everything is ok as follows :
1 2 3
|
CallDllFromVBA.cpp
CallDllFromVBA.vcxproj -> c:\documents and settings\administrateur\mes documents\visual studio 2010\Projects\CallDllFromVBA\Debug\CallDllFromVBA.dll
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
|
In VBA, I insert a module and add the following code:
1 2 3 4 5 6 7
|
Declare Function Multiply Lib _
"c:\documents and settings\administrateur\mes documents\visual studio 2010\Projects\CallDllFromVBA\Debug\CallDllFromVBA.dll" _
(ByVal x As Long, ByVal y As Long) As Long
Sub test()
MsgBox Multiply(2, 4)
End Sub
|
When I run the Test sub I get the error: 453 - Can't find dll entry point
I also opened the CallDllFromVBA dll with
Dependency walker and I can't find the Multiply export function - In fact, the dependency walker doesn't show any function exports at all for the CallDllFromVBA dll !
Any thoughts what the problem might be ?
Thanks