Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

C++ char FAR question

  • 02-03-2006 01:00PM
    #1
    Registered Users, Registered Users 2 Posts: 250 ✭✭


    I understand (by reading on web) what this is and that it's not quite standard practice to use it these days. But in a project I am doing I need to use it as it's defined in a Windows API structure.

    My question is: (I am a bit new to this) I am having trouble referencing the content of the buffer. (The structure is LPWSABUF).

    Would i not simply be able to show the buffer with something like:
    LPWSABUF tmpbuf;
    
    ...
    ...
    
    printf("Buffer=%s\n", (char *) *tmpbuf.buf);
    

    Any help would be greatly appreciated.
    TIA


Comments

  • Registered Users, Registered Users 2 Posts: 23 RazorEdge


    typedef struct __WSABUF {
      u_long [URL="http://www.boards.ie/vbulletin/"]len[/URL];
      char FAR* [URL="http://www.boards.ie/vbulletin/"]buf[/URL];
    } WSABUF, 
    *LPWSABUF;
    

    You can ignore the FAR attribute as it has no meaning on Win32.

    LPWSABUF is not a buffer. It is a pointer to a structure of type WSABUF which has a member called buf. Therefore to reference buf, you must access it like this.
    printf("Buffer=%s\n",tmpbuf->buf);
    

    printf assumes that buf points to a NULL terminated string.

    As tmpbuf is a pointer, be sure that it points to allocated WSABUF structure. This structures buf pointer should point to good memory that conatins a NULL terminated string also.


  • Registered Users, Registered Users 2 Posts: 250 ✭✭ikoonman


    Ok, but the variable i am working with is declared as a LPWSABUF (as opposed to WSABUF), which is a pointer to said structure.

    Is your printf statement still valid then?


Advertisement