Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

C++ char FAR question

Options
  • 02-03-2006 1:00pm
    #1
    Registered Users 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 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 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