Using a windows dll in a C++ S-function?
Afficher commentaires plus anciens
I have a C++ source code that is completely functional.
It uses functions from a windows DLL.
When I try to create a Simulink s-function using the legacy code tool,
these dll functions are not accessible. I get a segmentation fault.
If I take the calls to the functions out of the source code, it will run fine.
I have already changed my system path to where the dll is located. I have also checked for dependencies in the dll.
My C++ compiler is Visual Studio 2010. Matlab 32 bit 2011b
Here is how I use the legacy code tool:
clc
clear
def = legacy_code('initialize')
def.Options.language = 'C++';
def.OutputFcnSpec=['double y1 = positionfunct(void)']
def.IncPaths = {'C:\mtlb11b\bin\sfunctionblock'}
def.SrcPaths = {'C:\mtlb11b\bin\sfunctionblock'}
def.LibPaths = {'C:\mtlb11b\bin\sfunctionblock'}
def.HeaderFiles = {'Sfile.h','windows.h'}
def.SourceFiles = {'CodeForSFile.cpp'}
def.SFunctionName = 'GetPosition'
legacy_code('sfcn_cmex_generate',def)
legacy_code('compile',def)
legacy_code('Slblock_generate',def)
legacy_code('sfcn_tlc_generate',def)
def.SampleTime = 'parameterized'
Here is how I am obtaining the functions in C++:
static HINSTANCE hGetProcIDDLL = LoadLibrary("C:/mtlb11b/bin/sfunctionblock/PCI_VME.dll");
FARPROC lpfnGetProcessID = GetProcAddress(HMODULE (hGetProcIDDLL),"OPT");
typedef int (__stdcall * pICFUNC2)(char*);
pICFUNC2 OPT;
OPT = pICFUNC2(lpfnGetProcessID);
What are some things that I can try to get this to work? Should this work or should I be using a different approach?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Simulink Coder dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!