help-octave
[Top][All Lists]
Advanced

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

Re: External C DLL crashes Octave


From: mishrapiyush
Subject: Re: External C DLL crashes Octave
Date: Fri, 28 Aug 2009 12:44:02 -0700 (PDT)

Tatsuro,

  Thanks for replying to promptly.. I am using Octave 3.2.0, which is the
latest Win binary. I believe it is the MinGW version. I am able to compile
and call the sample application (d_gcc) but was having problem with my Cpp
code.

   In the meantime, I have found the reason of crash - it was due to an
error in my DEFUN_DLD function. Basically, I want to pass an array of
Doubles to my C function, say, as follows:
x = [10 100 1000 10000] %array of Doubles
mycodewrapper(x) %containing func1

as stated earlier, func1 is defined as follows:
extern "C" unsigned int func1(double *x);

I have tried:
Matrix B = args(0).matrix_value();
double* A = B.Rep->data;"
  but rep is now protected and hence compilation fails.

Could you recommend a good way to convert args of DEFUN_DLD into a pointer
of doubles. Is there a variation on "double* A = B.data()" which will allow
me to cast const double* to double*?

Thanks again,
Piyush


Tatsuro MATSUOKA-2 wrote:
> 
> Hello
> 
> Please show the version of octave and whether it is MSVC version or MinGW
> Version.
> 
> Regards
> 
> Tatsuro
> --- mishrapiyush wrote:
> 
>> 
>> Hi all,
>> 
>>   I followed the example on wiki
>> (http://wiki.octave.org/wiki.pl?OctaveLinkToWindowsDLLs) to compile my
>> c/c++
>> code into an .oct file but when I try to call this function, octave
>> crashes.
>> A snippet of my codes is attached below for your reference.
>> 
>> I had compiled mycode.cpp as Win DLL using MS Visual Studio 2008 and
>> tested
>> it on Matlab. Next I had copied the mycode.dll and mycode.lib into my
>> Octave
>> project folder and compiled them with mycodewrapper.cc to generate
>> func1.oct, which I call in a matlab function.
>> 
>> I have recetly started using Octave and have spent hours researching the
>> process of integrating external function calls. In my opinion, the manual
>> (Appendix A.1.9) does not do a good job of explaining C/C++ integration
>> and
>> should be supplemented with wiki entry mentioned above, which itself
>> misses
>> to mention that when linking the wrapper with external code, it should be
>> done with .lib file and not the .dll file. I would very much appreciate
>> any
>> help in further resolving this problem. Thanks for your time.
>> 
>> ----------------------------dllmain.cpp------------------------------
>> #include "stdafx.h"
>> 
>> BOOL APIENTRY DllMain( HMODULE hModule, DWORD  ul_reason_for_call, LPVOID
>> lpReserved ) {
>>      switch (ul_reason_for_call)
>>      {
>>      case DLL_PROCESS_ATTACH:
>>      case DLL_THREAD_ATTACH:
>>      case DLL_THREAD_DETACH:
>>      case DLL_PROCESS_DETACH:
>>              break;
>>      }
>>      return TRUE;
>> }
>> ----------------------------mycode.cpp------------------------------
>> #include <stdio.h>
>> #include <stdlib.h>
>> 
>> extern "C" unsigned int func1(double *x);
>> 
>> unsigned int func1(double *x)
>> {
>>     ...
>> }
>> ----------------------------mycodewrapper.cc------------------------------
>>   #include <octave/oct.h>
>>   
>>   extern "C" {
>>              unsigned int func1(double *x);
>>   }
>>   DEFUN_DLD (func1, args, , "usage func1('double')" ) {
>>      octave_value_list retval;
>>      Matrix B = args(0).matrix_value();
>>      double* A;
>>      *A = B.data(0);
>>      retval(0) = (double) func1( A );
>>      return retval;
>>   }
>> 
>> -- 
>> View this message in context:
>> http://www.nabble.com/External-C-DLL-crashes-Octave-tp25189231p25189231.html
>> Sent from the Octave - General mailing list archive at Nabble.com.
>> 
>> _______________________________________________
>> Help-octave mailing list
>> address@hidden
>> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
>> 
> 
> 
> --------------------------------------
> Thanks 10 years!  Yahoo! Shopping and Yahoo! Auctions
> http://pr.mail.yahoo.co.jp/ec10years/
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
> 
> 

-- 
View this message in context: 
http://www.nabble.com/External-C-DLL-crashes-Octave-tp25189231p25195846.html
Sent from the Octave - General mailing list archive at Nabble.com.



reply via email to

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