Get information from pointer? - Printable Version
-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Get information from pointer? (/showthread.php?tid=69606)
Get information from pointer? by deAd on 12-17-2006 at 04:34 PM
Some Windows messages have a pointer to a structure as the lParam. How do I "follow" this pointer and get the data it points to? I need to be able to read the contents of the structure. I have no idea what to do with the pointer (it's a number).
Thanks!
RE: Get information from pointer? by Spunky on 12-17-2006 at 04:37 PM
I think this is an example of the kind of thing you want...
code: //Show color picker common dialog
//Create our CHOOSECOLOR data block
var CHOOSECOLOR = Interop.Allocate(36);
CHOOSECOLOR.WriteDWORD(0, 36); //DWORD lStructSize
CHOOSECOLOR.WriteDWORD(4, 0); //HWND hwndOwner
CHOOSECOLOR.WriteDWORD(8, 0); //HWND hInstance
CHOOSECOLOR.WriteDWORD(12, 0x000000FF); //COLORREF rgbResult (COLORREF = 0x00bbggrr)
var CustColors = Interop.Allocate(64); //Create an array of 16 COLORREFs for CustColors
CHOOSECOLOR.WriteDWORD(16, CustColors.DataPtr); //COLORREF *lpCustColors (pointer to our array)
CHOOSECOLOR.WriteDWORD(20, 3); //DWORD Flags (3 = 2 (CC_FULLOPEN) + 1 (CC_RGBINIT) )
CHOOSECOLOR.WriteDWORD(24, 0); //LPARAM lCustData
CHOOSECOLOR.WriteDWORD(28, 0); //LPCCHOOKPROC lpfnHook
CHOOSECOLOR.WriteDWORD(32, 0); //LPCTSTR lpTemplateName
//Open the dialog box
var result = Interop.Call('comdlg32.dll', 'ChooseColorA', CHOOSECOLOR);
//If the user pressed ok convert it to hex
if(result == 1){
//Get decimal values
var r = CHOOSECOLOR.ReadDWORD(12) & 0xFF;
var g = (CHOOSECOLOR.ReadDWORD(12) / 0x100) & 0xFF;
var b = (CHOOSECOLOR.ReadDWORD(12) / 0x10000) & 0xFF;
Debug.Trace('RGB: ' + r + ',' + g + ',' + b)
//Get hex values
var hexchars="0123456789ABCDEF";
var r = hexchars.charAt((r >> 4) & 0xf) + hexchars.charAt(r & 0xF);
var g = hexchars.charAt((g >> 4) & 0xf) + hexchars.charAt(g & 0xF);
var b = hexchars.charAt((b >> 4) & 0xf) + hexchars.charAt(b & 0xF);
Debug.Trace('HEX: ' + r + g + b);
}
You need to use Interop.Allocate and ReadDWORD and so on
RE: Get information from pointer? by deAd on 12-17-2006 at 04:39 PM
No. That's making a pointer to my own data, I know how to do that
I need to get data from a pointer given to me by Windows.
RE: Get information from pointer? by Spunky on 12-17-2006 at 04:46 PM
Don't you still have to specify the pointer? if you do that then can't you still use code: lpointer.ReadDWORD
AFAIK the structure behaves the same
RE: Get information from pointer? by -dt- on 12-17-2006 at 04:47 PM
heres an example of WM_COPYDATA
code:
/*
typedef struct {
DWORD dwData; 4
DWORD cbData; 4
PVOID lpData; 4
} COPYDATASTRUCT; 12
*/
var struct = Interop.Allocate(12);
Interop.Call('Kernel32','RtlMoveMemory', struct, lParam,12);
var dwData = struct.ReadDWORD(0);
var cbData = struct.ReadDWORD(4);
var lpData = struct.ReadDWORD(8);
RE: Get information from pointer? by deAd on 12-17-2006 at 05:02 PM
Thanks! That worked
|