# How to use own defined struct in .api file

**URL:** <https://forum.legato.io/t/how-to-use-own-defined-struct-in-api-file/3430>\
**Category:** Legato Application Framework\
**Created:** [July 11, 2018, 8:54am UTC](https://forum.legato.io/t/how-to-use-own-defined-struct-in-api-file/3430 "2018-07-11T08:54:24Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![sowvikroy](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@sowvikroy](https://forum.legato.io/u/sowvikroy)\
**Post date:** [July 11, 2018, 8:54am UTC](https://forum.legato.io/t/how-to-use-own-defined-struct-in-api-file/3430/1 "2018-07-11T08:54:25Z")

</div>

Hello,  
I have a requirement to use my own defined structure in the .api file. Somehow I am successfully doing this like below:

**File: abc.api**  
REFERENCE Params;  
FUNCTION Info(Params params OUT);

**File: abcd.h**  
typedef struct {  
//Common parameters  
int32\_t signal\_strength;  
int32\_t temperature;  
uint32\_t level;  
}abc\_Params;

**File: abcde.c**  
void abc\_Info(abc\_ParamsRef\_t\* params) {

//Here I can’t access the struct members  
}

Could anyone please help

---

<div class="post-metadata">

**Author:** ![flu](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/flu/32/813_2.png) [@flu](https://forum.legato.io/u/flu)\
**Post date:** [July 11, 2018, 9:12am UTC](https://forum.legato.io/t/how-to-use-own-defined-struct-in-api-file/3430/2 "2018-07-11T09:12:15Z")

</div>

Hello sowviroy

\*.api files do not support structures

Solution #1:  
Use different functions to pass the difference structure fields

Solution #2:  
abc\_Params myStruc;  
Use le\_event\_Report ( myEvtId, & myStruc, sizeof ( myStruc ) );

KR.

---

<div class="post-metadata">

**Author:** ![Madan](https://avatars.discourse-cdn.com/v4/letter/m/6a8cbe/32.png) [@Madan](https://forum.legato.io/u/Madan)\
**Post date:** [October 25, 2018, 4:16am UTC](https://forum.legato.io/t/how-to-use-own-defined-struct-in-api-file/3430/3 "2018-10-25T04:16:45Z")

</div>

I do need to use a structure in an API call.  
Legato documentation shows there is a provision for STRUCT. But it is not recognised by compiler.  
Wasnt it supposed to work?

---

<div class="post-metadata">

**Author:** ![davidc](https://avatars.discourse-cdn.com/v4/letter/d/a183cd/32.png) [@davidc](https://forum.legato.io/u/davidc)\
**Post date:** [October 25, 2018, 7:06am UTC](https://forum.legato.io/t/how-to-use-own-defined-struct-in-api-file/3430/4 "2018-10-25T07:06:18Z")

</div>

Hiya,

API doesn’t support a struct as a ‘datatype’.

The `struct` you see mentioned in the docs are just how the IPC library deals with `references` - they’re actually an opaque data type that you treat as a void pointer.

This has caused me grief for a couple of years…

ciao, Dave

---

<div class="post-metadata">

**Author:** ![Kalai](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/kalai/32/1135_2.png) [@Kalai](https://forum.legato.io/u/Kalai)\
**Post date:** [September 16, 2021, 6:10am UTC](https://forum.legato.io/t/how-to-use-own-defined-struct-in-api-file/3430/5 "2021-09-16T06:10:59Z")

</div>

hi any samples available how to use struct in user defined api.thanks in advance

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [September 16, 2021, 7:02am UTC](https://forum.legato.io/t/how-to-use-own-defined-struct-in-api-file/3430/6 "2021-09-16T07:02:57Z")

</div>

how about this?

> [@In legato 19.02 api is not supporting more than 2 string](https://forum.legato.io/t/in-legato-19-02-api-is-not-supporting-more-than-2-string/5716/2):
>
> how about making the API file like this? STRUCT ARRAY123 { string Array1[10]; int32 port1; string Array2[10]; int32 port2; string Array3[10]; int32 port3; string Array4[10]; int32 port4; string Array5[10]; int32 port5; }; FUNCTION arraySend ( ARRAY123 asd IN ); It is working on my side with vscode leaf swi-wp76\_4.7.0. You can use my code: [IPC\_step1.rar](https://forum.legato.io/uploads/short-url/dgUwkVXIXDa6sS6CbPxzjqn2x7a.rar) (2.4 KB)

---

<div class="post-metadata">

**Author:** ![Kalai](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/kalai/32/1135_2.png) [@Kalai](https://forum.legato.io/u/Kalai)\
**Post date:** [September 16, 2021, 10:35am UTC](https://forum.legato.io/t/how-to-use-own-defined-struct-in-api-file/3430/7 "2021-09-16T10:35:38Z")

</div>

[StructApi.tar.gz](https://forum.legato.io/uploads/short-url/rSq0yuFxpuIO2boggioLiABPiwP.gz) (3.0 KB)  
am getting the following error, can u guide me how to pass input to the struct and my sample is attached for your refernce

Jan 6 10:27:00 swi-mdm9x28-wp user.info Legato: INFO | ClientCompExe[4274]/ClientComp T=main | ClientComp.c \_ClientComp\_COMPONENT\_INIT() 17 | LOG\_CLIENT\> start  
Jan 6 10:27:00 swi-mdm9x28-wp user.info Legato: INFO | ClientCompExe[4274]/ClientComp T=main | ClientComp.c \_ClientComp\_COMPONENT\_INIT() 24 | LOG\_CLIENT\> make the request no 1 to server  
Jan 6 10:27:00 swi-mdm9x28-wp user.info Legato: INFO | StructApiComponentExe[4273]/StructApiComponent T=main | StructApiComponent.c Sample\_logMessage() 26 | LOG\_SERVER\> received the message “log from client : request no 1” from a client.  
Jan 6 10:27:10 swi-mdm9x28-wp user.emerg Legato: _EMR_ | ClientCompExe[4274]/framework T=main | Sample\_client.c Sample\_arraySend() 667 | Assert Failed: ‘Sample\_PackARRAY123( &\_msgBufPtr, &\_msgBufSize, asdPtr )’  
Jan 6 10:27:10 swi-mdm9x28-wp user.info Legato: INFO | supervisor[4058]/supervisor T=main | proc.c proc\_SigChildHandler() 2051 | Process ‘ClientCompExe’ (PID: 4274) has exited with exit code 1.  
Jan 6 10:27:10 swi-mdm9x28-wp user.warn Legato: -WRN- | supervisor[4058]/supervisor T=main | app.c app\_SigChildHandler() 4031 | Process ‘ClientCompExe’ in app ‘StructApi’ faulted: Ignored.

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [September 16, 2021, 11:02am UTC](https://forum.legato.io/t/how-to-use-own-defined-struct-in-api-file/3430/8 "2021-09-16T11:02:31Z")

</div>

Can yoy use the sample code in the link which is proven to be working fine

---

<div class="post-metadata">

**Author:** ![Kalai](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/kalai/32/1135_2.png) [@Kalai](https://forum.legato.io/u/Kalai)\
**Post date:** [September 16, 2021, 11:04am UTC](https://forum.legato.io/t/how-to-use-own-defined-struct-in-api-file/3430/9 "2021-09-16T11:04:29Z")

</div>

i exactly use the same program but getting error , the only change made is instead of two app i used two component

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [September 16, 2021, 11:06am UTC](https://forum.legato.io/t/how-to-use-own-defined-struct-in-api-file/3430/10 "2021-09-16T11:06:00Z")

</div>

How about just running my app with two app

---

<div class="post-metadata">

**Author:** ![Kalai](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/kalai/32/1135_2.png) [@Kalai](https://forum.legato.io/u/Kalai)\
**Post date:** [September 16, 2021, 11:28am UTC](https://forum.legato.io/t/how-to-use-own-defined-struct-in-api-file/3430/11 "2021-09-16T11:28:24Z")

</div>

getting same error, dont know what am missing

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [September 16, 2021, 11:30am UTC](https://forum.legato.io/t/how-to-use-own-defined-struct-in-api-file/3430/12 "2021-09-16T11:30:19Z")

</div>

Are you using swi-wp76\_4.7.0

---

<div class="post-metadata">

**Author:** ![Kalai](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/kalai/32/1135_2.png) [@Kalai](https://forum.legato.io/u/Kalai)\
**Post date:** [September 16, 2021, 11:32am UTC](https://forum.legato.io/t/how-to-use-own-defined-struct-in-api-file/3430/13 "2021-09-16T11:32:19Z")

</div>

no its swi-wp76\_4.0.1

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [September 16, 2021, 11:41am UTC](https://forum.legato.io/t/how-to-use-own-defined-struct-in-api-file/3430/14 "2021-09-16T11:41:25Z")

</div>

Can you try the same
