For Programmers: Free Programming Magazines  


Home > Archive > C# > August 2004 > LOST in HELL: pointers unsafe/fixed, TCHAR, and win32api...please help?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author LOST in HELL: pointers unsafe/fixed, TCHAR, and win32api...please help?
live your lives

2004-08-18, 8:56 am

hi all,

i'm trying to get the contents of a program's listbox (AOL instant
messenger which i'm sure many of you use: specifically, the BUDDY
LIST). my problem in code is the Return Value (called getIt) because
i am having the hardest time grasping the concepts of TCHARs AND
unsafe/fixed pointer coding.

what's strange is that the gettext string (which holds the screen name
values i need) is a bunch of blank characters!!! BUT (always a but
right?), it's DEFINITELY the correct length of each screen name in the
buddy list i'm trying to retrieve! this means that the gettext values
for each item returned is (" "), where if the screen name is
"helloworld" it would be 10 blank characters. sooo, i'm guessing i
have to decode it somehow??? i dunno...

any-whooz, this project started so that i could strive to be great c#
programmers like some of you out there so, if anyone wouldn't mind
taking a look at my code, it would be most appreciated.


here's my mediocre (eh, sigh) code:
//
// EVERYTHING WORKS UP TO POINT "????"
//
// SendMessage function in Win32API
[DllImport("user32.dll")]
public static extern int SendMessage(
IntPtr hWnd, // handle to destination window
int Msg, // message
int wParam, // first message parameter
int lParam // second message parameter
);

// alias for SendMessage function in Win32API
[DllImport("user32.dll", EntryPoint="SendMessage")]
public static extern int SendMessageByString(
IntPtr hWnd, // handle to destination window
int Msg, // message
int wParam, // first message parameter
string lParam // second message parameter
);

/*
// i tried using all of these variables but
// they didn't work so i commented it out.
// it's just to show you what else i've tried...
const int LB_FINDSTRINGEXACT = 0x1A2;
const int CB_GETCOUNT = 0x146;
const int LB_GETITEMDATA = 0x199;
const int LB_SETCARETINDEX = 0x19E;
const int LF_FACESIZE = 32;
const int LB_SELECTSTRING = 0x18C;
const int LB_FINDSTRING = 0x18F;
*/

// these worked up until i used LB_GETTEXT
const int LB_GETCOUNT = 0x18B;
const int LB_SETCURSEL = 0x186;
const int LB_GETTEXTLEN = 0x18A;
const int LB_GETTEXT = 0x189;

// gets the listbox count (of all visible screen names) with
LB_GETCOUNT
int listCount = Win32.SendMessage(subWin3.Handle,LB_GETCOUNT, 0, 0);
// checks listbox count
Console.WriteLine ("listCount="+listCount);

// loop through the listbox
int i;
for (i = 0; i < listCount; i++) {

// set cursor to every visible buddy title
// (or screen name) in the buddy list with LB_SETCURSEL
int setCursor = Win32.SendMessage(subWin3.Handle, LB_SETCURSEL, i, 0);

// get the length of each list or buddy name with LB_GETTEXTLEN
int textLength = Win32.SendMessage(subWin3.Handle, LB_GETTEXTLEN, i,
0);

// set a blank string to use as a buffer
string gettext = new string(' ', textLength);

// ??????????????????????????????????????
// from what the msdn manual says -- Return Value: The
// return value is the length of the string (which gettext holds)
// in TCHARs, excluding the terminating null character.
// basically, i got lost here: filling in the lParam (or gettext)
param...
int getIt = Win32.SendMessageByString(subWin3.Handle, LB_GETTEXT, i,
gettext);

}

i've tried using unsafe/fixed pointers but they don't help...so if you
can i'd love to hear your suggestions, comments, and/or solutions.

thanks in advance and happy coding to you for taking time out to read
this.
live your lives

2004-08-18, 8:57 pm

nevermind, i've figured it out. :)

and in case any of you are lost souls are having the same propblem you
may want to do the following:

1) add to the dllimport: CharSet=CharSet.Auto, SetLastError=true

description:
http://msdn.microsoft.com/library/d...emberstopic.asp

happy coding!

liveyourlives@hotmail.com (live your lives) wrote in message news:<e6bdd1f.0408180220.a600ab1@posting.google.com>...
> hi all,
>
> i'm trying to get the contents of a program's listbox (AOL instant
> messenger which i'm sure many of you use: specifically, the BUDDY
> LIST). my problem in code is the Return Value (called getIt) because
> i am having the hardest time grasping the concepts of TCHARs AND
> unsafe/fixed pointer coding.
>
> what's strange is that the gettext string (which holds the screen name
> values i need) is a bunch of blank characters!!! BUT (always a but
> right?), it's DEFINITELY the correct length of each screen name in the
> buddy list i'm trying to retrieve! this means that the gettext values
> for each item returned is (" "), where if the screen name is
> "helloworld" it would be 10 blank characters. sooo, i'm guessing i
> have to decode it somehow??? i dunno...
>
> any-whooz, this project started so that i could strive to be great c#
> programmers like some of you out there so, if anyone wouldn't mind
> taking a look at my code, it would be most appreciated.
>
>
> here's my mediocre (eh, sigh) code:
> //
> // EVERYTHING WORKS UP TO POINT "????"
> //
> // SendMessage function in Win32API
> [DllImport("user32.dll")]
> public static extern int SendMessage(
> IntPtr hWnd, // handle to destination window
> int Msg, // message
> int wParam, // first message parameter
> int lParam // second message parameter
> );
>
> // alias for SendMessage function in Win32API
> [DllImport("user32.dll", EntryPoint="SendMessage")]
> public static extern int SendMessageByString(
> IntPtr hWnd, // handle to destination window
> int Msg, // message
> int wParam, // first message parameter
> string lParam // second message parameter
> );
>
> /*
> // i tried using all of these variables but
> // they didn't work so i commented it out.
> // it's just to show you what else i've tried...
> const int LB_FINDSTRINGEXACT = 0x1A2;
> const int CB_GETCOUNT = 0x146;
> const int LB_GETITEMDATA = 0x199;
> const int LB_SETCARETINDEX = 0x19E;
> const int LF_FACESIZE = 32;
> const int LB_SELECTSTRING = 0x18C;
> const int LB_FINDSTRING = 0x18F;
> */
>
> // these worked up until i used LB_GETTEXT
> const int LB_GETCOUNT = 0x18B;
> const int LB_SETCURSEL = 0x186;
> const int LB_GETTEXTLEN = 0x18A;
> const int LB_GETTEXT = 0x189;
>
> // gets the listbox count (of all visible screen names) with
> LB_GETCOUNT
> int listCount = Win32.SendMessage(subWin3.Handle,LB_GETCOUNT, 0, 0);
> // checks listbox count
> Console.WriteLine ("listCount="+listCount);
>
> // loop through the listbox
> int i;
> for (i = 0; i < listCount; i++) {
>
> // set cursor to every visible buddy title
> // (or screen name) in the buddy list with LB_SETCURSEL
> int setCursor = Win32.SendMessage(subWin3.Handle, LB_SETCURSEL, i, 0);
>
> // get the length of each list or buddy name with LB_GETTEXTLEN
> int textLength = Win32.SendMessage(subWin3.Handle, LB_GETTEXTLEN, i,
> 0);
>
> // set a blank string to use as a buffer
> string gettext = new string(' ', textLength);
>
> // ??????????????????????????????????????
> // from what the msdn manual says -- Return Value: The
> // return value is the length of the string (which gettext holds)
> // in TCHARs, excluding the terminating null character.
> // basically, i got lost here: filling in the lParam (or gettext)
> param...
> int getIt = Win32.SendMessageByString(subWin3.Handle, LB_GETTEXT, i,
> gettext);
>
> }
>
> i've tried using unsafe/fixed pointers but they don't help...so if you
> can i'd love to hear your suggestions, comments, and/or solutions.
>
> thanks in advance and happy coding to you for taking time out to read
> this.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com