help-octave
[Top][All Lists]
Advanced

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

Re: call c++ dlls in octave


From: Michael Goffioul
Subject: Re: call c++ dlls in octave
Date: Fri, 19 Dec 2008 09:20:11 +0000

Just to give an example, here's how you could wrap
your TWUsetuserAgent function (untested):

#include <octave/oct.h>

DEFUN_DLD(TWUsetUserAgent, args, , "")
{
  octave_value retval;

  if (args.length() == 1)
  {
    std::string ua = args(0).string_value();

    if (! error_state)
    {
      retval = std::string(TWUsetUserAgent(ua.c_str()));
    }
  }
  else
    print_usage();

  return retval;
}

You can have multiple DEFUN_DLD definition in a single
source file, but you then need to add a PKG_ADD file to
let octave know about them (using autoload facility).

In your case, I think the tricky thing is that you're using some
context structure that needs to be passed between your function
calls. You cannot return such structure directly to octave, so you
need a way to manage them. One solution is to index your
contexts in a map within your octfile, and simply return the index
(an integer) to octave. Any other function will be able to retrieve
the context object from the index. This is typically what is done to
manage figure objects within octave: figures are referenced using
a handle, which is simply an index into a given map.

Michael.


2008/12/18 Tatsuro MATSUOKA <address@hidden>:
> --- address@hidden wrote:
>
>> Date:Thu, 18 Dec 2008 21:54:30 +0900 (JST)
>> From:address@hidden
>> Subject:Re: call c++ dlls in octave
>> To:address@hidden
>>
>> Oh you are using theoctave-mingw!  My instruction is for octave-msvc.
>>
>> Your problem is more general so that I cannot answer at the moment.
>>
>> --------------------------------------
>> Power up the Internet with Yahoo! Toolbar.
>> http://pr.mail.yahoo.co.jp/toolbar/
>>
> --- Allahyari Rahim <address@hidden> wrote:
>
>> Hi,
>> �
>> I have to call a lot of function from a folder for example TWUClib
>> In this folder are my head and source files. Is it possible to call all this 
>> directly from
>> octave or I have to copy all into octave listing?
>> ��
>> What can I do with  �#include <octave/oct.h> �
>> and function� DEFUN_DLD (oregonator, args, ,� "The `oregonator'.")
>> do I need to include all my function with #include <octave/oct.h>
>> or can I build a file for example myfile.cc and and call all function from 
>> this file�//
>> myfile.cc#include� <octave/oct.h> #include <TWUClib.h>DEFUN_DLD (oregonator, 
>> args, ,�
> "The
>> `oregonator'."){��� ��.��� TWUopenSignal2(char const * a,
> char const * b, char const * c,
>> int d );���
> ��.����������� }
>> �I apropos �tested ��oregonator file. �it is running. Without any
> problem.
>> �
>> �
>>
> �[.]��������������
> hello.oct��������
> [MSYS]����������� [share]
>>
> [..]�������������
> [include]��������
> octave-core������ testOrego2.m
>>
> [bin]������������
> [lib]������������
> oregonator.cc���� [tools]
>>
> [doc]������������
> [libexec]��������
> oregonator.o����� uninstaller.exe
>> hello.cc���������
> [license]�������� oregonator.oct
>> hello.o����������
> [mingw32]�������� README.txt
>>
> �������������
> 10 Datei(en)������� 206.844 Bytes
>>
> �������������
> 12 Verzeichnis(se), 23.336.656.896 Bytes frei
>> octave-3.0.2.exe:3:C:\Programme\Octave\3.0.2_gcc-4.3.0
>> > testOrego2
>> ans =� 0.15625
>> octave-3.0.2.exe:4:C:\Programme\Octave\3.0.2_gcc-4.3.0
>> >
>> �thanks
>> --- Tatsuro MATSUOKA <address@hidden> schrieb am Do, 18.12.2008:
>>
>> Von: Tatsuro MATSUOKA <address@hidden>
>> Betreff: Re: call c++ dlls in octave
>> An: "Michael Goffioul" <address@hidden>, address@hidden
>> CC: address@hidden
>> Datum: Donnerstag, 18. Dezember 2008, 1:58
>>
>> Hello
>>
>> The url is described at
>> the Note of 1.1. Octave-Forge: GNU Octave Repository
>> in
>> http://wiki.octave.org/wiki.pl?OctaveForWindows
>>
>> You can see it from
>> http://www.tatsuromatsuoka.com/octave/Eng/Win/index.html#0004
>> msvcoct.html,4,602 bytes, 2008-11-25, md5 c76eaead3a6c2fe151403875459d31c4,
>> Note for mkoctfile (and
>> pkg install) for MSVC-octave 3.0.3.
>>
>> Regards
>>
>> Tatsuro
>>
>> --- Michael Goffioul <address@hidden> wrote:
>> > Tatsuro has made a nice page will all information needed
>> > to compile oct-file under Windows (Tatsuro, can you post
>> > the link?).
>>
>>
>>
>> --------------------------------------
>> Power up the Internet with Yahoo! Toolbar.
>> http://pr.mail.yahoo.co.jp/toolbar/
>>
>>
>>
>>       > /* 
>> ------------------------------------------------------------------------ */
>> /*
>>  * This header declares the public, standard-C interfaces of
>>  * the TWUClib, the "TEC Web-Umbrella Client" library
>>  *
>>  * Author: Jon Krom, Forschungszentrum Juelich, Institut fuer Plasmaphysik.
>>  * $Id: TWUClib-base.h,v 2.15 2008/11/14 13:20:46 jgk Exp $
>>  * Copyright (c) 2000,...,2008  Forschungszentrum Juelich GmbH.
>>  * All rights reserved.
>>  */
>> /* ------------------------------------------------------------------------ 
>> */
>>
>> #ifndef TWUCLIBBASE_H
>> #define TWUCLIBBASE_H
>>
>> #ifdef  __cplusplus
>> extern "C"
>> {
>> #endif
>>
>>     /* -------------------------------------------------------------------- 
>> */
>>     /* Local types and forward declarations */
>>
>>     struct TWUlinkContext;              /* Open link context */
>>
>>     typedef struct TWUlinkContext * TWUContext;
>>
>>     enum TWUClib_Open_Options           /* A bit map of options */
>>     {
>>         TWOO_no_options     = 0,
>>         TWOO_propertiesOnly = 0x1,      /* Pre-fetch at most the properties 
>> */
>>         TWOO_keepHTTPhead   = 0x2,      /* Keep the HTTP header visible     
>> */
>>         TWOO_allowbinary    = 0x4,      /* Allow binary IEEE float 
>> transfers*/
>>         TWOO_dont_fake      = 0x8,      /* Do not fake equidistant signals  
>> */
>>         TWOO_default        = TWOO_allowbinary
>>     };
>>
>>     /* -------------------------------------------------------------------- 
>> */
>>     struct TWUlinkContext *
>>     TWUopenURL(
>>         char const *        ,           /* URL */
>>         enum TWUClib_Open_Options );    /* Open options */
>>
>>     /* -------------------------------------------------------------------- 
>> */
>>
>>     struct TWUlinkContext *             /* Context pointer */
>>     TWUopenSignal2(
>>         char const *,                   /* URL */
>>         char const *,                   /* bulk query string */
>>         char const *,                   /* properties query string */
>>         int );                          /* enum TWUClib_Open_Options  */
>>
>>     /* -------------------------------------------------------------------- 
>> */
>>     int
>>     TWUhasError(
>>         struct TWUlinkContext const *); /* Context pointer */
>>
>>     /* -------------------------------------------------------------------- 
>> */
>>     char const *
>>     TWUerrorInfo(
>>         struct TWUlinkContext const *,  /* Context pointer  */
>>         int                         *,  /* Last HTTP status */
>>         char const *                *,  /* TWUerror text (static const)  */
>>         char const *                *); /* errno - text from strerror(3) */
>>
>>     /* -------------------------------------------------------------------- 
>> */
>>     char const *                        /* ptr to property value */
>>     TWUgetproperty(
>>         struct TWUlinkContext *,        /* Context pointer */
>>         char            const *);       /* Required property keyword */
>>
>>     /* -------------------------------------------------------------------- 
>> */
>>     char *
>>     TWUgetline(
>>         struct TWUlinkContext *);       /* Context pointer */
>>
>>     /* -------------------------------------------------------------------- 
>> */
>>     int
>>     TWUgetsingles(
>>         struct TWUlinkContext *,        /* Context pointer */
>>         float *                ,        /* floatArray      */
>>         int                    );       /* floatArraySize  */
>>
>>     /* -------------------------------------------------------------------- 
>> */
>>     int
>>     TWUgetdoubles(
>>         struct TWUlinkContext *,        /* Context pointer */
>>         double *               ,        /* floatArray      */
>>         int                    );       /* floatArraySize  */
>>
>>     /* -------------------------------------------------------------------- 
>> */
>>     void
>>     TWUreleaseLink(
>>         struct TWUlinkContext **);      /* Context pointer */
>>
>>     /* -------------------------------------------------------------------- 
>> */
>>     char const *
>>     TWUsetUserAgent(
>>         char const * );                 /* A new "user agent" program name */
>>
>>     /* -------------------------------------------------------------------- 
>> */
>> #ifdef  __cplusplus
>> }
>> #endif
>>
>> #endif /* TWUCLIBBASE_H */
>> /* End of: $Id: TWUClib-base.h,v 2.15 2008/11/14 13:20:46 jgk Exp $ */
>> /* ------------------------------------------------------------------------ 
>> */
>> > /* 
>> > ------------------------------------------------------------------------ */
>> /*
>>  * This file defines the high-level TWU-client operations for
>>  * opening a TWU-signal URL.
>>  *
>>  * Author: Jon Krom, Forschungszentrum Juelich, Institut fuer Plasmaphysik.
>>  * $Id: TWUopenSignal.c,v 2.12 2008/11/14 13:20:45 jgk Exp $
>>  * Copyright (c) 2000 Forschungszentrum Juelich GmbH.
>>  * All rights reserved.
>>  *
>>  * For change history use the cvs log command.
>>  */
>> /* ------------------------------------------------------------------------ 
>> */
>>
>> #include <string.h>
>>
>> #include "TWUClib.h"
>> #include "TWUClibInternal.h"
>> #include "TWUlinkContext.h"
>>
>> #ifdef WIN32
>> #   define  LOCALCONST              /* Keep silly Microsoft compiler quiet */
>> #else
>> #   define  LOCALCONST const        /* Standard-C compilers understand this 
>> */
>> #endif
>>
>>
>> /* ------------------------------------------------------------------------ 
>> */
>> struct TWUlinkContext *
>> TWUopenSignal2( char const *              LOCALCONST URL,
>>                 char const *              LOCALCONST bulk_query,
>>                 char const *              LOCALCONST prop_query,
>>                 int                       LOCALCONST options)
>> {
>>     struct TWUlinkContext * context ;
>>
>>     if (options & TWOO_propertiesOnly )
>>     {
>>         context = TWUopenURLQ( URL, prop_query, options );
>>     }
>>     else
>>     {
>>         context = TWUopenURLQ( URL, prop_query ? prop_query : "terse", 
>> options );
>>
>>         TWUcloseLink(context);
>>
>>         if ( ! TWUhasError(context) &&
>>              ! fakingPrepared(context, URL, bulk_query, options ) )
>>         {
>>             char const * bulkname = TWUgetproperty( context, "Bulkfile.URL" 
>> );
>>
>>             if(bulkname)
>>             {
>>                 struct TWUlinkContext * bulkfile ;
>>
>>                 bulkfile = TWUopenURLQ( bulkname, bulk_query, options);
>>                 bulkfile->associate = context;
>>
>>                 if (TWUhasError(bulkfile) )
>>                   TWUcloseLink(bulkfile);
>>
>>                 context = bulkfile;
>>             }
>>         }
>>     }
>>     if ( !(options & TWOO_keepHTTPhead ) && !TWUhasError(context) )
>>       TWUjumpHead(context);
>>
>>     return context;
>> }
>>
>> /* ------------------------------------------------------------------------ 
>> */
>> /* Deprecated function - Not to be used anymore
>>  * Only provided here to satisfy linking against user codes
>>  * that still depend on it.
>>  */
>> struct TWUlinkContext * TWUopenSignal(char const * , char const * , int );
>>
>> struct TWUlinkContext *
>> TWUopenSignal( char const * LOCALCONST URL,
>>                char const * LOCALCONST query_str,
>>                int          LOCALCONST options)
>> {
>>     return TWUopenSignal2( URL, query_str, query_str,
>>                            (enum TWUClib_Open_Options)options);
>> }
>>
>>
>> /* ------------------------------------------------------------------------ 
>> */
>> /* End of: $Id: TWUopenSignal.c,v 2.12 2008/11/14 13:20:45 jgk Exp $ */
>> /* ------------------------------------------------------------------------ 
>> */
>>
>
>
> --- Michael Goffioul <address@hidden> wrote:
>
>> Octave does not support loadlibrary and related.
>> To call functions from a DLL, you need to wrap the function
>> into an oct-file. This is rather easy to do and there exist
>> some examples in octave source tree (this has been
>> mentioned before on this mailing list, you might want
>> to search through previous posts).
>>
>> To build an oct-file, you obviously need a compiler.
>> As you're probably using the precompiled version
>> from octave-forge, you'll need the Visual C++ 2008
>> compiler (available free of charge from MS web site).
>> Tatsuro has made a nice page will all information needed
>> to compile oct-file under Windows (Tatsuro, can you post
>> the link?).
>>
>> Michael.
>>
>>
>> On Wed, Dec 17, 2008 at 7:45 AM, Allahyari Rahim <address@hidden> wrote:
>> > Hi,
>> > i want to call my dll with octave 3.0.3
>> > but i don't know how can i solve this problem.
>> > i have used dll in Matlab like this
>> >
>> > " myPath = 'C:\TWUClib\Win32\lib';
>> >   hfile =  'C:\TWUClib\Win32\include\TWUClib-base.h';
>> >   loadlibrary([myPath '\TWUClib'],hfile);
>> >   signal=calllib('TWUClib','TWUopenSignal2',url,'','',TWOO_default);
>> > "
>> > i tried to use mkoctfile to build oct file.and ... but can't continue.
>> > can anybody help me.
>> > thanks
>> > Allahyari
>> >
>> > _______________________________________________
>> > Help-octave mailing list
>> > address@hidden
>> > https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
>> >
>> >
>> _______________________________________________
>> Help-octave mailing list
>> address@hidden
>> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
>>
>
>
> --------------------------------------
> Power up the Internet with Yahoo! Toolbar.
> http://pr.mail.yahoo.co.jp/toolbar/
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]