Can't find DLL entry point error w/ Dalton's GetTime example

  • Thread starter Thread starter EricC
  • Start date Start date
Joined
8/31/09
Messages
3
Points
11
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.
 
post all the code (and the XLS) here so we can get an idea

---------- Post added at 02:08 PM ---------- Previous post was at 02:07 PM ----------

BTW, there are various discussions on how to call C++ from Excel in QN. Just search for it.
 
Out of respect for Dalton's copyrights, I hope it is sufficient for me to post the relevant code pieces here:

From the GetTime.cpp file:

Code:
#include <time.h>
#define SECS_PER_DAY (24 * 60 * 60)
 
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]long[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] current_system_time([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2]time_t time_t_T;[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]struct[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] tm tm_T;[/SIZE]
[SIZE=2]time(&time_t_T);[/SIZE]
[SIZE=2]tm_T = *localtime(&time_t_T);[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] tm_T.tm_sec + 60 * (tm_T.tm_min + 60 * tm_T.tm_hour);[/SIZE]
[SIZE=2]}[/SIZE]
 
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]__stdcall[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Get_System_Time_C([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]long[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] trigger)[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] current_system_time() / ([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])SECS_PER_DAY;[/SIZE]
[SIZE=2]}[/SIZE]

From the GetTime.def file:

Code:
[SIZE=2][SIZE=2]EXPORTS[/SIZE]
[SIZE=2]  Get_System_Time_C[/SIZE]
[/SIZE]

From the GetTime.xls spreadsheet:
Code:
Declare Function get_system_time_C Lib "C:\GetTimeExample\Debug\GetTime.dll" (ByVal trigger As Long) As Double
 
Option Explicit
 
Function Get_C_System_Time(trigger As Double) As Double
    Get_C_System_Time = get_system_time_C(0) ' not necessary to pass trigger argument
End Function

The spreadsheet includes a cell that has the following:
Code:
=Get_C_System_Time(0)

Which returns the "#VALUE!" error.

I also created the following subroutine in a VBA module:

Code:
Sub Sub_Get_C_System_Time()
    Call get_system_time_C(0) ' not necessary to pass trigger argument
End Sub

When I run that 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

---------- Post added at 12:24 PM ---------- Previous post was at 11:23 AM ----------

I solved the problem.

The problem had to do with case sensitivity.

In Dalton's Excel spreadsheet, the "get_system_time_C" in the VBA function declaration needs to be changed to "Get_System_Time_C"

Then it works.

---------- Post added at 12:30 PM ---------- Previous post was at 12:24 PM ----------

I found and solved the problem -- it is an issue of case sensitivity

In the Excel spreadsheet on the Dalton disk, the VBA Function declaration is as follows:

Declare Function get_system_time_C Lib "GetTime.dll" (ByVal trigger As Long) As Double


It worked after I changed the declaration to:

Declare Function Get_System_Time_C Lib "GetTime.dll" (ByVal trigger As Long) As Double

I find it interesting that I wasn't able to find anything on the net noting the same problem -- even though scores of people, no doubt, try the same exercise after getting Dalton's book. Oh well, perhaps future users who run into this problem will find this thread.

Best regards,
Eric

 
Back
Top Bottom