Solved

DLL 16bits creation for Excel use

Posted on 1997-03-26
3
247 Views
Last Modified: 2010-04-10
I need to build a basic DLL: f(x)=x*x in Borland 4.52 in W31
I call this DLL from a Visual Basic macro in Excel5 to get
the result of the calculation.
I know how to call this DLL from Excel, but I don't know how to create the DLL in Borland.
For the moment my .cpp file contains:
#include <windows.h>
extern double _export FAR test_calc (double x);

double FAR _export test_calc (double x)
{
return x*x;
}

int FAR PASCAL LibMain (HANDLE, WORD, WORD, WORD, LPSTR)
{
return 1;
}
But the macro returns:"Not definied function in the specified DLL" (I know the Visual Basic macro is correct).

Is the .cpp file correct to idenfiy the entry variable and
to return this simple result ?
0
Comment
Question by:chiarelli
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 1162461
Since your file name is *.cpp, you should use C linkage.

extern "C" double _export FAR test_calc (double x);

extern "C" double FAR _export test_calc (double x)
                  {
                  return x*x;
                  }
0
 

Author Comment

by:chiarelli
ID: 1162462
This answer does not resolve the problem.
The question is still the same.
Thanks

0
 

Accepted Solution

by:
meinn earned 50 total points
ID: 1162463
chensu is correct that you must use the C++ construct
  extern "C"
to force the compiler to treat your function as a C, rather than
a C++, function. (See any book on C++ for a discussion).

However, there are a number of "C" calling conventions used in the DOS/Windows world - PASCAL, CDECL, FASTCALL and STDCALL. By default, your C++ compiler will be generating a CDECL function (probably called something like _test_calc), while Excel is looking for a PASCAL function (called TEST_CALC).

The conventional solution is something like:

// ----- In your .h header file -----

#ifdef __cplusplus
extern "C" {
#endif

#ifdef BUILDING_DLL
#define PUBLIC FAR PASCAL EXPORT
#else
#define PUBLIC FAR PASCAL
#endif

double PUBLIC test_calc(double x);

// more functions...

#ifdef __cplusplus
}
#endif

// ------ In your .cpp implementation file -----

#define BUILDING_DLL
#include "whatever.h"

double PUBLIC test_calc(double x)
{
// ...
}

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question