lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

I also found more interesting things regarding VC 6.0
>From a dll, I needed to export some functions to be
used from VBA. As may be known, VBA cannot call
c++ functions, because ´mangling´, but the main module
of the library is essencially c++ because it defines and
uses a class, and uses a class defined into another module.
The whole thing was not easy to uncover, and in the mean
time a had the intended interface routines inside the main
module. When I started to understand what was on the
way, I tried a first, simple approach: changing only the
´calling convention´ for the VBA´s interfaces, but leaving
all them in the same header and module.
And it worked !!!
Atacched is the header. May be ( I not tried it ) the
only place to declare these routines as _stdcall could be
the header. But the whole thing is that VC is able to
generate mangled and unmangled names from a unique
module, and also, with two different calling conventions.
It´s a crazyness !
I hope this migth help to VC developers ... I use it only
for this kind of things, By the way, I am attaching also
the def file . The only routines this file must mention are
the ones to serve VB or VBA. If you are to call the
library from a C/C++ program, it´s enough to include
the header !!! and call the functions prefixed with c,
of course

----- Original Message -----
From: "Pyrogon Public" <>
To: "Multiple recipients of list" <>
Sent: Wednesday, November 06, 2002 6:19 PM
Subject: RE: problems linking with lua...

> > Sorry, but IIRC, it's the orther way around. You can compile
> > Lua in two ways. Either you compile Lua as C++ (Lua is valid
> > C++), and then you don't need
> > the extern "C" anywhere. Or, you compile lua as C, and then you'll
> > need the extern "C".
> You are correct, I misspoke.
> Lua will compile as either ANSI C or as C++.  By default most compilers
> determine the form to compile based on the extension - .c is treated as
> ANSI C.  However, you can override this with various command line
> switches (e.g. /TP with MSVC).
> You just have to be very careful that you're aware what's going on and
> that you're consistent.
> An error I've made more than once was doing this:
> extern "C"
> {
> #include "lua.h"
> }
> In a C++ file that uses Lua, but forgetting that I was compiling Lua as
> C++.  Or, conversely, compiling Lua as C++ and accidentally putting the
> "extern C" around the include statement from another source file.
> Brian

Attachment: qnxdxl.h
Description: Binary data

Attachment: qnxdxl.def
Description: Binary data