I just tried a different approach, using a c++ mex function (Although part of what I am trying to do is in Simulink, I can still do stuff in matlab). Still crashes though. So if there is advice you can give me on using dll files in either method, it would be helpful.
When I make the mex function I use the command
mex -v 'thecodefor.cpp' 'PCI_VME.lib'
to ensure that the library is linked. The library is also in the same folder as a whole bunch of dll files from some software that it originally came with, so if there is a dependency, I would think that it would solve itself.
Update: I have now also tried the loadlibrary function to put the library directly into matlab. I don't have a header though, and with the headers I am writing it doesn't work (segmentation error again).