I recently purchased the 2007 edition of Steve Dalton's Financial Applications Using Excel Add-In Development in C/C++ and am having difficulties implementing the "get time" call-a-DLL-from-a-VBA-function example in chapter 4.
What I did:
Built the DLL using Dalton's included code:
I copied the "GetTime VC6" folder from the software disc accompanying Dalton's book to a local directory. This folder includes a GetTime.cpp file containing a routine shown on page 100 of Dalton's book, a GetTime.def file that includes the following statement:
EXPORTS
Get_System_Time_C
The folder also includes a GetTime.dsp project file for Visual C++ 6.0.
I opened the GetTime.dsp using Microsoft Visual Studio C++ 2008 Express Edition, which converted the project into a 2008-compatible project.
I successfully built the project, which created the GetTime.dll and other files in the directory "C:\GetTimeExample\Debug\"
Opened Dalton's included Excel file and made file path modifications:
Next, I opened the GetTime.xls spreadsheet (included in the same Dalton CD) using Excel 2003.
I opened the VBA editor and entered in the full path of the DLL (C:\GetTimeExample\Debug\GetTime.dll") in the function declarations
The Problem:
Excel 2003 is not finding the DLL function. The spreadsheet gives me "#VALUE!" outputs in the "C run-time time function" and "C run-time clock function" cells.
While attempting to identify the problem, I created the following subroutine:
Sub Sub_Get_C_System_Time()
Call get_system_time_C(0) ' not necessary to pass trigger argument
End Sub
Then, when I attempt to run the subroutine, I get the following error:
Run-time error '453':
Can't find DLL entry point get_system_time_C in C:\GetTimeExample\Debug\GetTime.dll
Attempted But Failed Work-Arounds:
1) I prefaced an "extern "C"" command to the Get_System_Time_C function in GetTime.cpp and changed the corresponding GetTime.def entry to get_system_time_C=_get_system_time_C@4, but I got the same error.
2) In the Excel VBA window, I went to Tools/References/Browse and selected "C:\GetTimeExample\Debug\GetTime.dll". This returned the following error: "Can't add a reference to the specified file."
3) I added a "#include<windows.h>" statement to the cpp file (as shown on page 100 of the book). This made no difference.
I also searched Google for a solution, but was unable to find one.
Any suggestions?
Note:
I am experienced with Excel and fairly good with VBA. I did some C and C++ coding 20 years ago, in an old DOS environment. Although my C/C++ skills are very rusty, I want to write and link some C++ code into an Excel spreadsheet I developed (it desperately needs speed enhancements). I downloaded Microsoft's Visual Studio C++ 2008 Express Edition, but this compiler is very new to me.
What I did:
Built the DLL using Dalton's included code:
I copied the "GetTime VC6" folder from the software disc accompanying Dalton's book to a local directory. This folder includes a GetTime.cpp file containing a routine shown on page 100 of Dalton's book, a GetTime.def file that includes the following statement:
EXPORTS
Get_System_Time_C
The folder also includes a GetTime.dsp project file for Visual C++ 6.0.
I opened the GetTime.dsp using Microsoft Visual Studio C++ 2008 Express Edition, which converted the project into a 2008-compatible project.
I successfully built the project, which created the GetTime.dll and other files in the directory "C:\GetTimeExample\Debug\"
Opened Dalton's included Excel file and made file path modifications:
Next, I opened the GetTime.xls spreadsheet (included in the same Dalton CD) using Excel 2003.
I opened the VBA editor and entered in the full path of the DLL (C:\GetTimeExample\Debug\GetTime.dll") in the function declarations
The Problem:
Excel 2003 is not finding the DLL function. The spreadsheet gives me "#VALUE!" outputs in the "C run-time time function" and "C run-time clock function" cells.
While attempting to identify the problem, I created the following subroutine:
Sub Sub_Get_C_System_Time()
Call get_system_time_C(0) ' not necessary to pass trigger argument
End Sub
Then, when I attempt to run the subroutine, I get the following error:
Run-time error '453':
Can't find DLL entry point get_system_time_C in C:\GetTimeExample\Debug\GetTime.dll
Attempted But Failed Work-Arounds:
1) I prefaced an "extern "C"" command to the Get_System_Time_C function in GetTime.cpp and changed the corresponding GetTime.def entry to get_system_time_C=_get_system_time_C@4, but I got the same error.
2) In the Excel VBA window, I went to Tools/References/Browse and selected "C:\GetTimeExample\Debug\GetTime.dll". This returned the following error: "Can't add a reference to the specified file."
3) I added a "#include<windows.h>" statement to the cpp file (as shown on page 100 of the book). This made no difference.
I also searched Google for a solution, but was unable to find one.
Any suggestions?
Note:
I am experienced with Excel and fairly good with VBA. I did some C and C++ coding 20 years ago, in an old DOS environment. Although my C/C++ skills are very rusty, I want to write and link some C++ code into an Excel spreadsheet I developed (it desperately needs speed enhancements). I downloaded Microsoft's Visual Studio C++ 2008 Express Edition, but this compiler is very new to me.