Mary Enuit | 2 May 2004 09:26
Picon
Favicon

programmable COM objects / automation

Hi, all.

I would like to retrofit a couple of large existing
C++ libraries with OLE automation in order to better
support emerging Windows technologies.  Does SWIG
provide facilities for doing so?  The process of
wrapping a library for use as an extension for
"languageX" seems similar to wrapping it as a
programmable COM object.

Thanks in advance,
Mary

	
		
__________________________________
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs  
http://hotjobs.sweepstakes.yahoo.com/careermakeover 
_______________________________________________
Swig maillist  -  Swig <at> cs.uchicago.edu
http://mailman.cs.uchicago.edu/mailman/listinfo/swig

William S Fulton | 3 May 2004 14:21
Picon
Favicon
Gravatar

Re: programmable COM objects / automation

Mary Enuit wrote:
> Hi, all.
> 
> I would like to retrofit a couple of large existing
> C++ libraries with OLE automation in order to better
> support emerging Windows technologies.  Does SWIG
> provide facilities for doing so?  The process of
> wrapping a library for use as an extension for
> "languageX" seems similar to wrapping it as a
> programmable COM object.
> 
No one has ever written a COM wrapper, but it would be entirely feasible using
SWIG. The only thing SWIG can offer you right now is to wrap your C++ library
using the C# module. This of course provides a .NET wrapper. However, it is dead
easy to produce COM Callable Wrappers (CCW) of any .NET class through a simple
tickbox in Visual Studio .NET (Register for COM interop). The downside is your
users will have to install the .NET framework if not present and there is the
extra overhead of going through .NET wrappers.

William

_______________________________________________
Swig maillist  -  Swig <at> cs.uchicago.edu
http://mailman.cs.uchicago.edu/mailman/listinfo/swig

Scott Greig | 3 May 2004 15:51
Favicon

Has anyone looked into LUA?

I’m currently using ‘tolua’ which is not as robust as swig.

 

Thanks

- Scott

David Cannings | 4 May 2004 19:18

Is SWIG appropriate

I am no great programmer in either C or Perl but am trying to convert a C 
header file into a Perl module.  I have one that was made by somebody 
else using an old version of h2xs and old versions of the header files 
but now want to update it and document it properly.  The header files are 
from the MTA Exim and I want to be able to call certain functions from 
the C file from Perl.

I have tried using h2xs to convert the header file without success so have 
given up trying to use it.  Its behaviour isn't consistent with the 
manual page and there are bugs in perlbug that are three years old 
relating to my problems.  I get no response from Perl mailing lists 
either, because of this I found SWIG.  

The defines a number of functions, an enum and some other variables such 
as "extern uschar *message_id".  I decided to start small and get one 
method working so have created myself a file called LocalScan.i that 
contains:

-- File: LocalScan.i --
%module LocalScan
 %{
 /* Includes the header in the wrapper code */
 #include "local_scan.h"
 %}

 /* Parse the header file to generate wrappers */

extern void    header_add(int, char *, ...);
-- End file --

The above was got from reading the tutorial on the website.  I have copied 
the declaration for header_add() straight from the .h file.  I now run:

# swig -perl5 LocalScan.i

Which generates the files LocalScan_wrap.c and LocalScan.pm, so I run:

# gcc -c LocalScan_wrap.c local_scan.c -I/usr/lib/perl/5.8/CORE 
-I../exim4-4.31/src

I link to the Exim sources as other files are included by local_scan.h.  I 
get the following errors however:

-- Errors --
In file included from /usr/lib/perl/5.8/CORE/op.h:484,
                 from /usr/lib/perl/5.8/CORE/perl.h:2346,
                 from LocalScan_wrap.c:237:
/usr/lib/perl/5.8/CORE/reentr.h:611: error: field `_crypt_struct' has 
incomplete type
In file included from /usr/lib/perl/5.8/CORE/perl.h:3554,
                 from LocalScan_wrap.c:237:
/usr/lib/perl/5.8/CORE/proto.h:199: error: parse error before "off64_t"
/usr/lib/perl/5.8/CORE/proto.h:201: error: parse error before 
"Perl_do_sysseek"
/usr/lib/perl/5.8/CORE/proto.h:201: error: parse error before "off64_t"
/usr/lib/perl/5.8/CORE/proto.h:201: warning: data definition has no type 
or storage class
/usr/lib/perl/5.8/CORE/proto.h:202: error: parse error before 
"Perl_do_tell"
/usr/lib/perl/5.8/CORE/proto.h:202: warning: data definition has no type 
or storage class
/usr/lib/perl/5.8/CORE/proto.h:1307: error: parse error before 
"Perl_PerlIO_tell"
/usr/lib/perl/5.8/CORE/proto.h:1307: warning: data definition has no type 
or storage class
/usr/lib/perl/5.8/CORE/proto.h:1308: error: parse error before "off64_t"
In file included from local_scan.h:16,
                 from LocalScan_wrap.c:586:
../exim4-4.31/src/mytypes.h:17:1: warning: "FALSE" redefined
In file included from /usr/lib/perl/5.8/CORE/perl.h:1807,
                 from LocalScan_wrap.c:237:
/usr/lib/perl/5.8/CORE/handy.h:47:1: warning: this is the location of the 
previous definition
In file included from local_scan.h:16,
                 from LocalScan_wrap.c:586:
../exim4-4.31/src/mytypes.h:18:1: warning: "TRUE" redefined
In file included from /usr/lib/perl/5.8/CORE/perl.h:1807,
                 from LocalScan_wrap.c:237:
/usr/lib/perl/5.8/CORE/handy.h:46:1: warning: this is the location of the 
previous definition
-- End errors --

Am I going about this the right way or can SWIG not do what I suggest?  Is 
it possible to fix the above?  They seem to be errors with the Perl 
sources as opposed to SWIG or Exim.

My apologies for the lengthly mail,

David
_______________________________________________
Swig maillist  -  Swig <at> cs.uchicago.edu
http://mailman.cs.uchicago.edu/mailman/listinfo/swig

John Lenz | 4 May 2004 20:18
Picon

Re: Is SWIG appropriate

On 2004.05.04 12:18, David Cannings wrote:

> # gcc -c LocalScan_wrap.c local_scan.c -I/usr/lib/perl/5.8/CORE
> -I../exim4-4.31/src

Sigh.
http://www.swig.org/Doc1.3/Perl5.html#n9

Read the part that starts with "If you see errors having to do with  
_crypt_struct, ..."

perl -e 'use Config; print $Config{ccflags};'

John
_______________________________________________
Swig maillist  -  Swig <at> cs.uchicago.edu
http://mailman.cs.uchicago.edu/mailman/listinfo/swig

David Cannings | 4 May 2004 20:27

Re: Is SWIG appropriate

On Tuesday 04 May 2004 19:18, John Lenz wrote:
> On 2004.05.04 12:18, David Cannings wrote:
> > # gcc -c LocalScan_wrap.c local_scan.c -I/usr/lib/perl/5.8/CORE
> > -I../exim4-4.31/src
>
> Sigh.
> http://www.swig.org/Doc1.3/Perl5.html#n9
>
> Read the part that starts with "If you see errors having to do with
> _crypt_struct, ..."
>
> perl -e 'use Config; print $Config{ccflags};'

My apologies, I hadn't seen the FAQ.  This fixes the problem and I now 
have a .o file.

Thank you,

David
_______________________________________________
Swig maillist  -  Swig <at> cs.uchicago.edu
http://mailman.cs.uchicago.edu/mailman/listinfo/swig

Jake Janovetz | 4 May 2004 22:39

SWIG C++/Python and inheritance.

I posted this a little earlier and it didn't go through...  Not sure why.

I've used SWIG to wrap a C++ class I have in the most direct manner.  I 
haven't used typemaps or anything fancy.  The C++ class is a derived 
class and has a pure virtual called "OnTrigger()".  In Python, I'm 
trying to call a function that takes the C++ base class and it's not 
working.  Here's a little diagram of what's going on...

-----------------------------
C++:
class A;
class B : public A {
   virtual void OnTrigger() = 0;
};
class funkyclass {
   void RegisterComponent(A *a);
};
-----------------------------
Python:
class C(mylib.B) {
   def OnTrigger():
      print "Triggered!"
};

x=mylib.funkyclass();
x.RegisterComponent(C);
-----------------------------

I'm getting a TypeError: Expected a pointer.  I'm new to both Python and 
SWIG, so if there is more information I can provide please let me know. 
  I've looked back through the archives and seen a few things about 
derived classes across C++/Python and it seems SWIG can handle them just 
fine, but this one has me snookered.

Incidentally, I -can- call x.RegisterComponent with an instance of class 
A within Python.

   Jake

_______________________________________________
Swig maillist  -  Swig <at> cs.uchicago.edu
http://mailman.cs.uchicago.edu/mailman/listinfo/swig

David Beazley | 4 May 2004 22:44
Favicon

SWIG C++/Python and inheritance.

Jake Janovetz writes:
 > I posted this a little earlier and it didn't go through...  Not sure why.
 > 
 > I've used SWIG to wrap a C++ class I have in the most direct manner.  I 
 > haven't used typemaps or anything fancy.  The C++ class is a derived 
 > class and has a pure virtual called "OnTrigger()".  In Python, I'm 
 > trying to call a function that takes the C++ base class and it's not 
 > working.  Here's a little diagram of what's going on...
 > 
 > -----------------------------
 > C++:
 > class A;
 > class B : public A {
 >    virtual void OnTrigger() = 0;
 > };
 > class funkyclass {
 >    void RegisterComponent(A *a);
 > };
 > -----------------------------
 > Python:
 > class C(mylib.B) {
 >    def OnTrigger():
 >       print "Triggered!"
 > };
 > 
 > x=mylib.funkyclass();
 > x.RegisterComponent(C);
 > I'm getting a TypeError: Expected a pointer.  

If I read that code right, "C" is a Python class definition, not an
*instance* of any kind of object.   That's almost certainly part of
the problem.

-- Dave

_______________________________________________
Swig maillist  -  Swig <at> cs.uchicago.edu
http://mailman.cs.uchicago.edu/mailman/listinfo/swig

Jake Janovetz | 4 May 2004 23:03

Re: SWIG C++/Python and inheritance.

Not sure where the reply went...

My posting was in error.  My code builds an instance of C:

y = C();
x.RegisterComponent(y);

    Jake

David Beazley wrote:

> Jake Janovetz writes:
>  > I posted this a little earlier and it didn't go through...  Not sure why.
>  > 
>  > I've used SWIG to wrap a C++ class I have in the most direct manner.  I 
>  > haven't used typemaps or anything fancy.  The C++ class is a derived 
>  > class and has a pure virtual called "OnTrigger()".  In Python, I'm 
>  > trying to call a function that takes the C++ base class and it's not 
>  > working.  Here's a little diagram of what's going on...
>  > 
>  > -----------------------------
>  > C++:
>  > class A;
>  > class B : public A {
>  >    virtual void OnTrigger() = 0;
>  > };
>  > class funkyclass {
>  >    void RegisterComponent(A *a);
>  > };
>  > -----------------------------
>  > Python:
>  > class C(mylib.B) {
>  >    def OnTrigger():
>  >       print "Triggered!"
>  > };
>  > 
>  > x=mylib.funkyclass();
>  > x.RegisterComponent(C);
>  > I'm getting a TypeError: Expected a pointer.  
> 
> If I read that code right, "C" is a Python class definition, not an
> *instance* of any kind of object.   That's almost certainly part of
> the problem.
> 
> -- Dave
> 
> _______________________________________________
> Swig maillist  -  Swig <at> cs.uchicago.edu
> http://mailman.cs.uchicago.edu/mailman/listinfo/swig
_______________________________________________
Swig maillist  -  Swig <at> cs.uchicago.edu
http://mailman.cs.uchicago.edu/mailman/listinfo/swig

Rolf Wester | 5 May 2004 09:09
Picon
Favicon

How to use a C++ std::string from Python

Hi,

a have a C++ module with functions that have std::string parameters. The 
build works fine but
I don't know how to call such a method. When using a Python string as 
function parameter I get
an error message:

>>> im.read_bmp_file("dvac001.bmp",0)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "image.py", line 423, in read_bmp_file
    def read_bmp_file(*args): return _image.Image_read_bmp_file(*args)
TypeError: Type error. Got dvac001.bmp, expected _p_std__string

How can I call this function from Python? I would be very appreciative 
for any help.

With kind regards

Rolf Wester

_______________________________________________
Swig maillist  -  Swig <at> cs.uchicago.edu
http://mailman.cs.uchicago.edu/mailman/listinfo/swig


Gmane