P/Invoke - TAPI - LINEDEVCAPS-structure!?

  • Thread starter Thread starter Danyel Meyer - dialog-it GmbH
  • Start date Start date
D

Danyel Meyer - dialog-it GmbH

Hallo...

I´ve got quite confused while trying to P/Invoke TAPI´s lineGetDeviceCaps. I
find it very difficult to marshal the LINEDEVCAPS-structure, which is
defined as:

--8<--
typedef struct linedevcaps_tag
{
DWORD ... [many many DWORDs]
} LINEDEVCAPS, FAR *LPLINEDEVCAPS;
-->8--

As far as I understand it, I have to use Integers for the DWORD-values. What
I don´t understand is, how can I e.g. get the lineName from this structure,
when there are only integers in it? Furthermore, what does "FAR" in the type
definition mean (I´m not quite familiar with C)?
How do I have to imagine what this structure looks like ans how it´s values
are stored?

Plaes, help before my head explodes ;) ...I just don´t get what happens
there...

--
Danyel Meyer
-------------------------------------------
dialog-it GmbH
Röllinghäuser Strasse 55a
31061 Alfeld/Leine

Tel +49 (0) 5181 900 814
Fax +49 (0) 5181 900 815
E-Mail danyel.meyer <at> dialog-it.de
 
When you call TSPI_lineGetDevCaps and pass it an instance of the structure,
the function may tell you that the block of memory you passed is too small.
That is, the explicit fields declared as being part of the structure are
just the 'header' part of the memory layout of the information. After those
fields, there is an indeterminate amount of extra memory required for
things, like the name, which may vary in length. The dwLineNameOffset field
of the structure tells you how many bytes into the structure the start of
the line name string is (it will begin after the last explicit field shown
in the structure declaration), and the dwLineNameSize field tells you how
many bytes of string data are stored there for the name. To actually
extract that data, you'll need to get the bytes at that offset and for that
length from the structure and convert them to a string.

This is a case where representing the structure in memory as a byte array is
probably the best way to go. That way, when you create it and call
TSPI_lineGetDevCaps and it returns an indication that there is not enough
space, you can internally extend the array and try again. There are
numerous examples of this use-a-byte-array-as-a-structure-for-P/Invoke in
the OpenNetCF framework, as well as in the archives of this newsgroups.

Paul T.
 
Thanks Paul,

That was what I just missed. To imagine the structures defined fields as a
kind of header was what came to my mind, but I wanted to get feedback if
it´s right.
I now was able to use the structure the way you recommended.


--
Danyel Meyer
-------------------------------------------
dialog-it GmbH
Röllinghäuser Strasse 55a
31061 Alfeld/Leine

Tel +49 (0) 5181 900 814
Fax +49 (0) 5181 900 815
E-Mail danyel.meyer <at> dialog-it.de

Paul G. Tobey said:
When you call TSPI_lineGetDevCaps and pass it an instance of the structure,
the function may tell you that the block of memory you passed is too small.
That is, the explicit fields declared as being part of the structure are
just the 'header' part of the memory layout of the information. After those
fields, there is an indeterminate amount of extra memory required for
things, like the name, which may vary in length. The dwLineNameOffset field
of the structure tells you how many bytes into the structure the start of
the line name string is (it will begin after the last explicit field shown
in the structure declaration), and the dwLineNameSize field tells you how
many bytes of string data are stored there for the name. To actually
extract that data, you'll need to get the bytes at that offset and for that
length from the structure and convert them to a string.

This is a case where representing the structure in memory as a byte array is
probably the best way to go. That way, when you create it and call
TSPI_lineGetDevCaps and it returns an indication that there is not enough
space, you can internally extend the array and try again. There are
numerous examples of this use-a-byte-array-as-a-structure-for-P/Invoke in
the OpenNetCF framework, as well as in the archives of this newsgroups.

Paul T.

Danyel Meyer - dialog-it GmbH dialog-it.de> said:
Hallo...

I´ve got quite confused while trying to P/Invoke TAPI´s
lineGetDeviceCaps.
I
find it very difficult to marshal the LINEDEVCAPS-structure, which is
defined as:

--8<--
typedef struct linedevcaps_tag
{
DWORD ... [many many DWORDs]
} LINEDEVCAPS, FAR *LPLINEDEVCAPS;
-->8--

As far as I understand it, I have to use Integers for the DWORD-values. What
I don´t understand is, how can I e.g. get the lineName from this structure,
when there are only integers in it? Furthermore, what does "FAR" in the type
definition mean (I´m not quite familiar with C)?
How do I have to imagine what this structure looks like ans how it´s values
are stored?

Plaes, help before my head explodes ;) ...I just don´t get what happens
there...

--
Danyel Meyer
-------------------------------------------
dialog-it GmbH
Röllinghäuser Strasse 55a
31061 Alfeld/Leine

Tel +49 (0) 5181 900 814
Fax +49 (0) 5181 900 815
E-Mail danyel.meyer <at> dialog-it.de
 
Hallo Alex,

Thanks for the hint to your wrapper. I have taken a look at it, and I indeed
thought about using it. But my requirements untli now are just a small
subset of it, so I decided to code it myself. I just need to monitor the
cell line to recieve data about beginning and ending calls.
I´ve just got it done, and your code was of great help.


--
Danyel Meyer
-------------------------------------------
dialog-it GmbH
Röllinghäuser Strasse 55a
31061 Alfeld/Leine

Tel +49 (0) 5181 900 814
Fax +49 (0) 5181 900 815
E-Mail danyel.meyer <at> dialog-it.de

Alex Feinman said:
I think you might find it easier to use a prebuilt wrapper.
Take a look at http://www.alexfeinman.com/downloads.asp?doc=tapi1.1.zip
If you decide to take a look at it, I would appreciate a feedback - I'm
trying to freeze the feature set so that a beta can be included into
OpenNETCF SDF

Danyel Meyer - dialog-it GmbH dialog-it.de> said:
Hallo...

I´ve got quite confused while trying to P/Invoke TAPI´s
lineGetDeviceCaps.
I
find it very difficult to marshal the LINEDEVCAPS-structure, which is
defined as:

--8<--
typedef struct linedevcaps_tag
{
DWORD ... [many many DWORDs]
} LINEDEVCAPS, FAR *LPLINEDEVCAPS;
-->8--

As far as I understand it, I have to use Integers for the DWORD-values. What
I don´t understand is, how can I e.g. get the lineName from this structure,
when there are only integers in it? Furthermore, what does "FAR" in the type
definition mean (I´m not quite familiar with C)?
How do I have to imagine what this structure looks like ans how it´s values
are stored?

Plaes, help before my head explodes ;) ...I just don´t get what happens
there...

--
Danyel Meyer
-------------------------------------------
dialog-it GmbH
Röllinghäuser Strasse 55a
31061 Alfeld/Leine

Tel +49 (0) 5181 900 814
Fax +49 (0) 5181 900 815
E-Mail danyel.meyer <at> dialog-it.de
 
Back
Top