[DGD]Calling CPP Functions from an Extension

Michael J. Bacon mj.bacon at gte.net
Thu Jan 18 04:40:52 CET 2001


	Hi Felix.  Thanks for the response.

	Actually, the code you provided matches the stuff I put in my extension
file almost exactly.  My extensions file is a C file though, so I keep all
the CPP code in another file, call it "openx.cpp".  The main difference I
decode everything using the macros in dgd_ext.h, then pass them to the C
function which passes them to the C++ function.

	I added this to the makefile in the same manner that windgd.cpp is in
there.  I can get everything to link but when I added the line 'bstr_t
strCnn("Provider=sqloledb;Data Source=MyServer;Initial Catalog=pubs;User
Id=sa;Password=;")'

	I get the following link errors:

---------
No configuration specified.  Defaulting to windgd - Win32 Debug.
        link.exe @C:\WINDOWS\TEMP\nma00163.
nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator
new(unsigned int)" (??2 at YAPAXI@Z) already defined in LIBCMTD.lib(new.obj)
nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void
*)"
(??3 at YAXPAX@Z) already defined in LIBCMTD.lib(dbgdel.obj)
.\Debug/dgd.exe : fatal error LNK1169: one or more multiply defined symbols
found
NMAKE : fatal error U1077: 'D:\PROGRA~1\MICROS~1\VC98\BIN\link.exe' : return
code '0x491'
Stop.
---------

	If I comment out that line, it links.  Any idea what I am doing wrong?  Try
not to laugh at me, I'm sure its something really stupid, but I am new to
this. :-)


Thanks!
Michael.

-----Original Message-----
From: Felix A. Croes [mailto:felix at dworkin.nl]
Sent: Wednesday, January 17, 2001 10:21 AM
To: dgd at list.imaginary.com
Subject: Re: [DGD]Calling CPP Functions from an Extension


"Michael J. Bacon" <mj.bacon at gte.net> wrote:


>[...]
> 	Anyway, I've been playing around with dgd1.2's extension capabilities.
> Very neat I must say.  For convoluted reasons I find myself needing to
call
> C++ functions from an extension.  I realize I will be unable to directly
> access class objects or advanced C++ constructs from an extension, but I
> have devised a few functions which, in theory, should act as a layer
between
> the C++ objects and methods and the procedural C calls any extension would
> make.  I wrote a simple extension to test this theory, and I'm glad I did,
> because I can't get things to link.

C and C++ need a special interface to work together.  You have to do
something like:

    extern "C" {

    # include "dgd_ext.h"

    }

    void this_is_the_cpp_function(DGD_FRAME_T f, int nargs, DGD_VALUE_T
*retval)
    {
	// do something
    }

    extern "C" {

    void this_is_the_relay(DGD_FRAME_T f, int nargs, DGD_VALUE_T *retval)
    {
	this_is_the_cpp_function(f, nargs, retval);
    }

    }


You may actually be able to inline this_is_the_cpp_function into
this_is_the_relay; I think the `extern "C"' stuff only affects linkage.

Regards,
Dworkin


List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list