The following is the code, hope anyone can help me.
This is testdll2_for_vba.h
Expand|Select|Wrap|Line Numbers
- #ifndef DLL3_H
- #define DLL3_H
- #ifdef DLL3_EXPORTS
- #define DLL3_API __declspec(dllexport)
- #else
- #pragma message("automatic link to DLL3.LIB")
- // #pragma comment(lib, "DLL3.lib")
- #define DLL3_API __declspec(dllimport)
- #endif
- // This class is exported from the Test.dll
- class DLL3_API CTest
- {
- public:
- CTest(void);
- // TODO: add your methods here.
- };
- extern DLL3_API int nTest(const int& m);
- double DLL3_API __stdcall testplus (const double& a, const double& b);
- #endif //DLL3_H
This is dllmain.cpp
Expand|Select|Wrap|Line Numbers
- // dllmain.cpp : Defines the entry point for the DLL application.
- #include "stdafx.h"
- #define TEST_EXPORTS // <=== ADD THIS LINE
- //#include "testdll2.h"
- #include "testdll2_for_vba.h"
- BOOL APIENTRY DllMain( HMODULE hModule,
- DWORD ul_reason_for_call,
- LPVOID lpReserved
- )
- {
- switch (ul_reason_for_call)
- {
- case DLL_PROCESS_ATTACH:
- case DLL_THREAD_ATTACH:
- case DLL_THREAD_DETACH:
- case DLL_PROCESS_DETACH:
- break;
- }
- return TRUE;
- }
This is my source code:
Expand|Select|Wrap|Line Numbers
- // testdll2.cpp : Defines the exported functions for the DLL application.
- //
- #include "stdafx.h"
- int nTest(const int& m){
- return m;
- }
- double testplus (const double& a, const double& b){
- return a+b;
- }
Expand|Select|Wrap|Line Numbers
- Public Declare Function testplus Lib _
- "C:\Documents and Settings\Owner.SpiritBirdV1\My Documents\Visual Studio 2008\Projects\testdll2\Debug\testdll2.dll" (ByRef a As Double, ByRef b As Double) As Double
- Sub test()
- End Sub
- Function bs_test(s As Double, k As Double, r As Double, sigma As Double, time As Double) As Double
- 'bs_test = option_price_call_black_scholes(s, k, r, sigma, time)
- bs_test = testplus(s, k)
- End Function
I read some articles about create DLL from VC++, that requires .def to alias the exported symbols. But I failed to find where to create .def in c++ express edition 2008. what should I do to fix the problem?
Thanks again