Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

LOST in HELL: pointers unsafe/fixed, TCHAR, and win32api...please help?
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.

Report this thread to moderator Post Follow-up to this message
Old Post
live your lives
08-18-04 01:56 PM


Re: LOST in HELL: pointers unsafe/fixed, TCHAR, and win32api...please help?
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.a600a
b1@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.

Report this thread to moderator Post Follow-up to this message
Old Post
live your lives
08-19-04 01:57 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

C# archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 09:21 PM.

 

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.