# Help with Parsing a CSTRING from API Call

**URL:** <https://clarionhub.com/t/help-with-parsing-a-cstring-from-api-call/7131>\
**Category:** questions\
**Tags:** winapi\
**Created:** [April 26, 2024, 8:54pm UTC](https://clarionhub.com/t/help-with-parsing-a-cstring-from-api-call/7131 "2024-04-26T20:54:36Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![donridley](https://clarionhub.com/user_avatar/clarionhub.com/donridley/32/1459_2.png) [@donridley](https://clarionhub.com/u/donridley)\
**Post date:** [April 26, 2024, 8:54pm UTC](https://clarionhub.com/t/help-with-parsing-a-cstring-from-api-call/7131/1 "2024-04-26T20:54:36Z")

</div>

Hello Everyone,

Enumerating audio devices.

I have a group with a CSTRING as one of its fields.

The API call works fine.

However, upon sending the CSTRING to Debugview++ I don't see the field's value.

But if I loop through the CSTRING like:

```auto
        Loop x = 1 to SIZE(WaveOutCapsGrp.szPname)
            MyWave.Trace(WaveOutCapsGrp.szPname[x])
        END

```

I see the expected values.

This shouldn't have me stumped but it does.

---

<div class="post-metadata">

**Author:** ![anon77170705](https://clarionhub.com/letter_avatar_proxy/v4/letter/a/ecccb3/32.png) [@anon77170705](https://clarionhub.com/u/anon77170705)\
**Post date:** [April 26, 2024, 8:57pm UTC](https://clarionhub.com/t/help-with-parsing-a-cstring-from-api-call/7131/2 "2024-04-26T20:57:49Z")

</div>

> [@donridley](#):
>
> However, upon sending the CSTRING to Debugview++ I don’t see the field’s value.

Unless Carriage Return is forced in DebugView options the program must add it itself to display a CSTRING.

---

<div class="post-metadata">

**Author:** ![jslarve](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@jslarve](https://clarionhub.com/u/jslarve)\
**Post date:** [April 26, 2024, 9:00pm UTC](https://clarionhub.com/t/help-with-parsing-a-cstring-from-api-call/7131/3 "2024-04-26T21:00:12Z")

</div>

If the first character is null, it could represent an empty value.

A CSTRING can contain other stuff after the null, but it is still considered blank.

---

<div class="post-metadata">

**Author:** ![Bruce](https://clarionhub.com/letter_avatar_proxy/v4/letter/b/ccd318/32.png) [@Bruce](https://clarionhub.com/u/Bruce)\
**Post date:** [April 27, 2024, 4:02am UTC](https://clarionhub.com/t/help-with-parsing-a-cstring-from-api-call/7131/4 "2024-04-27T04:02:02Z")

</div>

The api you are calling is likely returning a char\* (or void\*) and a length. Not really a Cstring. In other words “a binary string”.

In clarion a cstring “cannot” hold binary strings because they “terminate” on the first chr(0).

For api calls like this you should use either a string (remembering to kerp track of the length) or a variable length binary string (like stringtheory).

Outputting to debugview is also problematic. Because debugview takes cstrings as input, so terminates after the first chr(0). Plus of course you wont see non-printable binary chars.

I use stringtheory PeekRam method to inspect binary values. (You can just pass in the address and length, no need to assign.)

---

<div class="post-metadata">

**Author:** ![CarlBarnes](https://clarionhub.com/user_avatar/clarionhub.com/carlbarnes/32/1859_2.png) [@CarlBarnes](https://clarionhub.com/u/CarlBarnes)\
**Post date:** [April 27, 2024, 3:35pm UTC](https://clarionhub.com/t/help-with-parsing-a-cstring-from-api-call/7131/5 "2024-04-27T15:35:26Z")

</div>

What exact API function? MSDN will have some details about the values and types.

Paste your calling code, API Prototype and variable declarations.

---

<div class="post-metadata">

**Author:** ![jslarve](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@jslarve](https://clarionhub.com/u/jslarve)\
**Post date:** [April 27, 2024, 5:34pm UTC](https://clarionhub.com/t/help-with-parsing-a-cstring-from-api-call/7131/6 "2024-04-27T17:34:55Z")

</div>

If it’s regarding this structure, can you show your clarion rendition? It could be possible that there’s an alignment problem, putting a zero where it shouldn’t be.

> **[WAVEOUTCAPS (mmeapi.h) - Win32 apps](https://learn.microsoft.com/en-us/windows/win32/api/mmeapi/ns-mmeapi-waveoutcaps)**
>
> The WAVEOUTCAPS structure describes the capabilities of a waveform-audio output device. (WAVEOUTCAPS)

---

<div class="post-metadata">

**Author:** ![CarlBarnes](https://clarionhub.com/user_avatar/clarionhub.com/carlbarnes/32/1859_2.png) [@CarlBarnes](https://clarionhub.com/u/CarlBarnes)\
**Post date:** [April 27, 2024, 6:00pm UTC](https://clarionhub.com/t/help-with-parsing-a-cstring-from-api-call/7131/7 "2024-04-27T18:00:00Z")

</div>

> [@jslarve](#):
>
> The WAVEOUTCAPS structure

If you can find a [http://pinvoke.net/](http://pinvoke.net/) declaration it can often be helpful in Clarion. The types are closer and constants tend to be defined

```auto
typedef struct {
  WORD wMid;
  WORD wPid;
  MMVERSION vDriverVersion;
  TCHAR szPname[MAXPNAMELEN];
  DWORD fdwSupport;
  DWORD cDestinations;
} MIXERCAPS;

[StructLayout(LayoutKind.Sequential)]
struct MixerCaps
{
  public ushort ManufacturerID;        
  public ushort ProductId; 
  public int Version;          
  [MarshalAs(UnmanagedType.ByValTStr, SizeConst=32)] 
  public String ProductName;
  public uint Support;
  public uint Destinations;        
  public override String ToString()
  {
 return String.Format(...);
  }
}

```

> <https://stackoverflow.com/questions/46899057/c-to-c-mixercaps-structure>

---

<div class="post-metadata">

**Author:** ![Julian](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@Julian](https://clarionhub.com/u/Julian)\
**Post date:** [April 28, 2024, 6:50am UTC](https://clarionhub.com/t/help-with-parsing-a-cstring-from-api-call/7131/8 "2024-04-28T06:50:00Z")

</div>

Is this what you’re using ..

```auto
typedef struct tagWAVEOUTCAPSA {
  WORD wMid;
  WORD wPid;
  MMVERSION vDriverVersion;
  CHAR szPname[MAXPNAMELEN];
  DWORD dwFormats;
  WORD wChannels;
  WORD wReserved1;
  DWORD dwSupport;
} WAVEOUTCAPSA, *PWAVEOUTCAPSA, *NPWAVEOUTCAPSA, *LPWAVEOUTCAPSA;

```

where MAXPNAMELEN = 32, so it’s an array of CHAR (Bytes) in which you just need to locate the ‘\<0\>’

Can’t you just declare either a STRING[32] or a CSTRING[32] and then just assign them thus ..

Option 1 :  
string\_ProductName = SUB(szPname,1,INSTRING(‘\<0\>’,szPname,1,1))

Option 2 :  
cstring\_ProductName = szPname

---

<div class="post-metadata">

**Author:** ![vitesse](https://clarionhub.com/user_avatar/clarionhub.com/vitesse/32/837_2.png) [@vitesse](https://clarionhub.com/u/vitesse)\
**Post date:** [April 28, 2024, 7:01am UTC](https://clarionhub.com/t/help-with-parsing-a-cstring-from-api-call/7131/9 "2024-04-28T07:01:33Z")

</div>

> [@Julian](#):
>
> string\_ProductName = SUB(szPname,1,INSTRING(‘\<0\>’,szPname,1,1))

maybe subtract one from the length to not include the null terminator ‘\<0\>’

```auto
string_ProductName = SUB(szPname,1,INSTRING(‘<0>’,szPname,1,1) - 1)

```

and then consider if there is no terminator, perhaps something like:

```auto
x long,auto
  code
  x = instring(‘<0>’,szPname,1,1)
  case x
  of 0
    string_ProductName = szPname ! no null terminator
  of 1 
   string_ProductName = ''
  else
   string_ProductName = szPname[1 : x-1]
  end

```

---

<div class="post-metadata">

**Author:** ![Julian](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@Julian](https://clarionhub.com/u/Julian)\
**Post date:** [April 28, 2024, 7:08am UTC](https://clarionhub.com/t/help-with-parsing-a-cstring-from-api-call/7131/10 "2024-04-28T07:08:37Z")

</div>

Yes (schoolboy error) you are correct Geoff .. subtract 1 to remove the \<0\>

Looks like there will always be a terminator according to the docs at Jeff’s link.

---

<div class="post-metadata">

**Author:** ![Mike\_Duglas](https://clarionhub.com/user_avatar/clarionhub.com/mike_duglas/32/1061_2.png) [@Mike\_Duglas](https://clarionhub.com/u/Mike_Duglas)\
**Post date:** [April 28, 2024, 8:39am UTC](https://clarionhub.com/t/help-with-parsing-a-cstring-from-api-call/7131/11 "2024-04-28T08:39:06Z")

</div>

I have no problem with wave api, particulary with these structs:

```auto
tagWAVEOUTCAPSA GROUP, TYPE
wMid USHORT
wPid USHORT
vDriverVersion MMVERSION
szPname CSTRING(MAXPNAMELEN)
dwFormats ULONG
wChannels USHORT
wReserved1 USHORT
dwSupport ULONG
                              END
tagWAVEOUTCAPS2A GROUP(tagWAVEOUTCAPSA),TYPE
ManufacturerGuid LIKE(_GUID)
ProductGuid LIKE(_GUID)
NameGuid LIKE(_GUID)
                              END

TWaveOut.GetDevCaps PROCEDURE(UNSIGNED pDeviceID, *typWAVEOUTCAPS pwoc)
woc2 LIKE(tagWAVEOUTCAPS2A)
  CODE
  CLEAR(pwoc)
  SELF.nret = winmm::waveOutGetDevCapsA(pDeviceID, ADDRESS(woc2), SIZE(tagWAVEOUTCAPS2A))
  IF SELF.nret = MMSYSERR_NOERROR
    pwoc.vDriverVersion = woc2.vDriverVersion
    pwoc.szPname = woc2.szPname
    pwoc.dwFormats = woc2.dwFormats
    pwoc.wChannels = woc2.wChannels
    pwoc.dwSupport = woc2.dwSupport
    RETURN TRUE
  ELSE
    printd('waveOutGetDevCapsA(%i) error: %s [%i].', pDeviceID, SELF.GetLastError(), SELF.nret)
    RETURN FALSE
  END

```
