help-octave
[Top][All Lists]
Advanced

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

External C DLL crashes Octave


From: mishrapiyush
Subject: External C DLL crashes Octave
Date: Fri, 28 Aug 2009 05:42:17 -0700 (PDT)

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.



reply via email to

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