Wow I am confused. SendMessage API.

This is a discussion on Wow I am confused. SendMessage API. within the Windows Programming forums, part of the Platform Specific Boards category; Okie doke, I am so darn confused as to why this piece of code is causing a segmentation fault. Code: ...

  1. #1
    Registered User BillBoeBaggins's Avatar
    Join Date
    Oct 2003
    Posts
    107

    Wow I am confused. SendMessage API. (Resolved)

    Okie doke, I am so darn confused as to why this piece of code is causing a segmentation fault.
    Code:
    char MyMsg[]="This is a message.\0";
    char * pMyMsg=&MyMsg[0];
    SendMessage(hwnd_MyListBox,LB_ADDSTRING,0,*pMyMsg);
    The MSDN says that the LPARAM is supposed to be a pointer.

    However when I use it without Dereferencing it
    Code:
    SendMessage(hwnd_MyListBox,LB_ADDSTRING,0,pMyMsg);
    It tells me that it is expecting a long int.

    It will compile the first way but then causes the fault.


    Thanks for all help past/present/future.
    Last edited by BillBoeBaggins; 08-19-2004 at 03:42 PM.
    May the compiler be with you.
    Be one with the compiler, and you shall prosper greatly.

  2. #2
    Registered User
    Join Date
    Jun 2004
    Posts
    84
    Quote Originally Posted by BillBoeBaggins
    Okie doke, I am so darn confused as to why this piece of code is causing a segmentation fault.
    Code:
    char MyMsg[]="This is a message.\0";
    char * pMyMsg=&MyMsg[0];
    SendMessage(hwnd_MyListBox,LB_ADDSTRING,0,*pMyMsg);
    It's:
    Code:
    static char MyMsg[]="This is a message.\0";
    char * pMyMsg=&MyMsg[0];
    SendMessage(hwnd_MyListBox,LB_ADDSTRING,0,(LPARAM)pMyMsg);
    and you don't need pMyMsg, you can use MyMsg without any problems
    edit: and I don't see any reason to put '\0' at the end.
    Last edited by iwabee; 08-18-2004 at 04:30 PM.

  3. #3
    Registered User BillBoeBaggins's Avatar
    Join Date
    Oct 2003
    Posts
    107
    Thank you much for your input, but per my first post the program won't compile and tells me it can't convert a "'char*' to a 'long int'". Which is weird as well because if dereferencing the pointer causes the procedure to get a character array why should it compile. I am still a bit boggled.
    May the compiler be with you.
    Be one with the compiler, and you shall prosper greatly.

  4. #4
    Registered User BillBoeBaggins's Avatar
    Join Date
    Oct 2003
    Posts
    107
    Okie doke, I noticed your Edits, and that is what cured the problem "(LPARAM)", I tacked that in and it works fine and dandy.

    Thank you!!!
    May the compiler be with you.
    Be one with the compiler, and you shall prosper greatly.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. a good windows API programming book
    By jpchand in forum Windows Programming
    Replies: 3
    Last Post: 10-10-2003, 07:37 AM
  2. Q about most used prog. language in C++! Confused?
    By actionbasti in forum Game Programming
    Replies: 3
    Last Post: 09-16-2003, 08:42 PM
  3. confused.. in selecting my line of deapth
    By jawwadalam in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 05-04-2003, 02:21 PM
  4. How do you toggle keys like Scroll lock without Windows API?
    By animeaholic in forum C++ Programming
    Replies: 7
    Last Post: 09-15-2002, 08:02 PM
  5. API, LOST... help
    By Unregistered in forum Windows Programming
    Replies: 5
    Last Post: 03-13-2002, 03:19 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21