Re: Segmentation fault when accessing function in a DLL



Erik

You are passing a NULL pointer to the function 'USMC_Init' is that what the function expects or does it expect a pointer to a valid
location? To pass a valid pointer initialize at least one field of the structure before passing it to USMC_Init.

Phil

"Erik Benkler" <erik.benkler@xxxxxx> wrote in message news:gs7f7m$8k9$1@xxxxxxxxxxxxxxxxxxxxx
Hi everybody,
I am trying to use functions in a windows DLL for controlling stepper motor hardware. The stepper motor manual says that the DLL
should work with Matlab. So, I read carefully the external interfacing section in Matlab help and related articles in several
newsgroups. I think I am doing everything right, but Matlab always produces a segmentation fault when I make the calllib statement
to the function USMC_Init in the DLL. Before the callib statement, the library seems to be loaded correctly and the correct data
structures seem to be generated and initialized (see line 18 in the m-file). The files necessary to reproduce this behaviour are
available at http://www.mediafire.com/file/juin0zzin2k/USMCDLLtest.zip. Before the USMCDLL.dll can be used, the MicroSMC driver
must be installed on the system and using the DLL requires administrative rights. For more information see the comments in the
USMCDLL_test.m file and in the Matlab error message in segmentation_errormessage.txt. Am I doing something wrong in the m-file or
is there a problem in Matlab or in the DLL? For people who don't want to download the files, I post the contents of the m-file
below.
Thanks for any help in advance,
Erik

% OS is Windows XP SP2, Matlab version is 7.0.4.365 (R14) SP2
% ATTENTION: The user must be logged in with administrative rights,
% otherwise the USMCDLL library does not work
% Before the USMCDLL library can be used, it must be installed with
% setup.exe in the MicroSMC folder.
% Calls to the USMCDLL library first invoke MicroSMC.exe. Access to the
% library functions without MicroSMC properly installed does not work and
% produces an error message box, independet of Matlab).
% The USMCDLL.h header file must be located on the current Matlab path.

clear all
if not(libisloaded('USMCDLL'))
loadlibrary('USMCDLL','USMCDLL.h')
end
%libfunctionsview('USMCDLL')

Devices=libpointer('USMC_Devices_stPtr');
%Devices.Value %this correctly shows %initialized values in the data structure USMC_Devices_st as
%defined in USMCDLL.h header file
calllib('USMCDLL', 'USMC_Init', Devices); % here, a reproducible %segmentation violation occurs


.



Relevant Pages

  • Re: Critical section shared betwen dll and main program
    ... I am discussing the case of dynamic DLL ... loading and passing PCRITICAL_SECTION between old version of DLL ... and an executable which was build in newer environment. ... without passing a pointer to the kernel32.dll? ...
    (microsoft.public.win32.programmer.kernel)
  • pointer to struct to use in a DLL
    ... i'm trying to evaluate the feasibility of this method by creating a few functions based on the structure type i use, but i seem not to be able to pass a pointer to a structure from matlab to the DLL. ...
    (comp.soft-sys.matlab)
  • Re: pointer to struct to use in a DLL
    ... thus i'm considering to create a DLL containing some functions of my programm, and call them from matlab. ... not to be able to pass a pointer to a structure from matlab to the DLL. ...
    (comp.soft-sys.matlab)
  • Re: Critical section shared betwen dll and main program
    ... different components like EXE and DLL. ... old version of CRITICAL_SECTION and passes a pointer to it which is used ... There is no problem with passing its address between exe and DLL. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: COM callbacks
    ... So my first test was to generate a COM .dll called from Matlab ... pointer crash within Matlab. ... I looked at the marshal sample from the MS website. ...
    (comp.soft-sys.matlab)

Loading