James
unread,Jan 30, 2014, 3:53:09 PM1/30/14You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
Hello,
I am creating an S function in simulink using the legacy code generator.
My C++ source code will compile and work by itself without any issues.
This C++ code imports functions from an external dll file.
I do not have a .lib or .h file for this dll library, it is commercial library.
So I import the functions using this method:
static HINSTANCE hGetProcIDDLL = LoadLibrary("\TheFile.dll");
FARPROC lpfnGetProcessID = GetProcAddress(HMODULE (hGetProcIDDLL),"OPT");
typedef int (__stdcall * pICFUNC2)(char*);
pICFUNC2 OPT;
OPT = pICFUNC2(lpfnGetProcessID);
I can compile the s function without errors. However, when I go to run it, I get a segmentation fault (matlab freezes up and closes with no error messages given).
If I take out the calls to the imported functions in the C++ code, everything runs fine.
extra info:
-my matlab C++ compiler is set as Visual Studios 2010
-This is what my s-function legacy code looks like, it may have some unnecessary stuff:
clc
clear
def = legacy_code('initialize')
def.Options.language = 'C++';
def.OutputFcnSpec=['double y1 = positionfunct(void)']
def.IncPaths = {'C:\mtlb11b\bin\s function block'}
def.SrcPaths = {'C:\mtlb11b\bin\s function block'}
def.LibPaths = {'C:\mtlb11b\bin\s function block'}
def.HeaderFiles = {'Sfile.h','windows.h'}
def.SourceFiles = {'CodeForSFile.cpp'}
def.SFunctionName = 'GetPosition'
def.HostLibFiles = {}
def.TargetLibFiles = {'PCI_VME.lib'}
legacy_code('sfcn_cmex_generate',def)
legacy_code('compile',def)
legacy_code('Slblock_generate',def)
legacy_code('sfcn_tlc_generate',def)
def.SampleTime = 'parameterized'
If anyone has any advice regarding this, I would greatly appreciate it.
James