Main Content

libstruct

MATLAB 구조체를 공유 C 라이브러리에서 사용할 C 형식 구조체로 변환

설명

S = libstruct(structtype)은 MATLAB® libstruct 객체 S에 대한 NULL 포인터를 만듭니다.

예제

S = libstruct(structtype,mlstruct)mlstruct로 초기화되는 포인터를 만듭니다.

예제

모두 축소

c_struct 유형의 변수를 만들어 addStructFields 함수를 호출합니다.

c_struct 유형이 포함된, matlabroot\extern\examples\shrlib 폴더의 shrlibsample 라이브러리를 불러옵니다.

if ~libisloaded('shrlibsample')
   addpath(fullfile(matlabroot,'extern','examples','shrlib'))
   loadlibrary('shrlibsample')
end

shrlibsample에 대한 함수 시그니처를 표시하고 목록에서 addStructFields 항목을 검색합니다.

libfunctionsview shrlibsample
double addStructFields(c_struct)

입력 인수는 c_struct 데이터형에 대한 포인터입니다.

MATLAB 구조체 sm을 만듭니다.

sm.p1 = 476;   sm.p2 = -299;   sm.p3 = 1000;

c_struct 유형에서 libstruct 객체 sc를 생성합니다.

sc = libstruct('c_struct',sm)

sc의 필드에는 MATLAB 구조체 sm의 값이 포함됩니다.

addStructFields 함수를 호출합니다.

calllib('shrlibsample','addStructFields',sc)
ans =
    1177

정리(Clean Up)하려면 먼저 libstruct 객체를 지운 다음 라이브러리를 언로드하십시오.

clear sc
unloadlibrary shrlibsample

입력 인수

모두 축소

공유 라이브러리에 정의된 C 구조체입니다.

S의 필드를 초기화하는 데 사용되는 MATLAB 구조체입니다.

데이터형: struct

출력 인수

모두 축소

포인터로, MATLAB libstruct 객체로 반환됩니다.

제한 사항

  • loadlibrary 함수를 사용하여 불러온 라이브러리와 함께 사용하십시오.

  • libstruct 함수는 스칼라 구조체에서만 사용할 수 있습니다.

  • MATLAB 구조체를 libstruct 객체로 변환할 때 구조체는 Structure Argument Requirements에 나와 있는 요구 사항을 준수해야 합니다.

  • 공유 라이브러리의 함수에 구조체 인수가 있으면 libstruct를 사용하여 인수를 만드십시오. libstruct 함수는 라이브러리의 함수로 전달하는 C 형식 구조체를 만듭니다. 이 구조체는 실제 MATLAB 구조체와 마찬가지로 MATLAB에서 처리합니다.

버전 내역

R2006a 이전에 개발됨