How can I detect null pointers in Generic DLL return values?

조회 수: 10 (최근 30일)
I am using the Generic DLL interface with a library that may return null pointers as expected results. I would like to check for null values in my LIBPOINTER results in MATLAB.

채택된 답변

MathWorks Support Team
MathWorks Support Team 2009년 6월 27일
Starting MATLAB 7.6(R2008a), you can use the function 'IsNull' to verify if a LIBPOINTER is pointing to a null reference.
For previous product releases, read below for any possible workarounds:
The ability to check directly whether a LIBPOINTER is null is not available in MATLAB 7.4 (R2007a) and previous releases. To work around this issue, try to retrieve the pointer's target in a TRY-CATCH block.
Attempting to dereference a null pointer will cause a MATLAB error of type "MATLAB:libpointer:ValueNotDefined". This error usually indicates a null pointer. You can use the following code to check for null pointers:
p = libpointer() % Create a null pointer for testing
try
setdatatype(p, 'int8Ptr', 1, 80) % Use actual expected type and size
get(p) % Try to display data
catch
e = lasterror
if strcmp(e.identifier, 'MATLAB:libpointer:ValueNotDefined')
disp('Null pointer.')
% React to null pointer result
end
end
get(p) % Show pointer target

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Call C from MATLAB에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

제품


릴리스

R2007a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by