Re: want to resize window in vbs



thanks jw,

it sounds like what i'm doing can't be done without a c++ compiler. however,
from what you said, it seems i should be able to get the address of a vbs
variant using the varptr function. i tried the vba version at it worked
properly for variants. however, when i tried this code:

UserWrap.Register "msvbvm50.dll", "VarPtr", "i=l", "f=s", "r=l"
Dim PID
Dim lpProcessID
lpProcessID = UserWrap.VarPtr(PID)
UserWrap.MessageBoxA Null, CStr(lpProcessID), "From DynaWrap Object", 3

i get "0" for the pointer. i don't know why that is, since i should be
interfacing to the same function that i called from VBA. if this would work,
then as you say all i have to do is add 8 to the value to get the pointer to
the long.

"mr_unreliable" <kindlyReplyToNewsgroup@xxxxxxxxxxx> wrote in message
news:OfPQPMRQFHA.2932@xxxxxxxxxxxxxxxxxxxxxxx
> hi Gary,
>
> For one thing, I'm surprised you get anything to work with DynaWrap,
> becasue you appear to be ignoring my advice about type-casting
> parameters (i.e., CStr(var), CLng(var), etc.).
>
> But as to your question about GetWindowThreadProcessID, you have
> run up against a limitation of DynaWrap that I don't know any way
> around. More specifically, processID is an [out] parameter, and
> as such must be passed "ByRef". DynaWrap does have a provision
> for byref parameters, BUT ONLY STRING parameters. Too Bad.
>
> There are a couple of ways to address this. For one, if you or
> a friend knows c++, you could take the source code provided and
> build in a capability for byref longs. Or alternatively, you
> could get a "pointer" (memory address) to your processID variable,
> and pass the pointer instead of the variable. The problem (or
> really two problems) is getting the pointer. You could get it
> with vb, using the VarPtr function (directly, or by writing an
> actX utility). Then you get to the second problem, i.e., that
> the vbscript variables are VARIANTS. That means that the address
> of the actual "long" value is 8 bytes beyond the address of the
> variant (those other bytes contain an integer which defines
> the type of the variant and three "filler" integers).
>
> Actually, if you are going to re-write DynaWrap, what I would
> really like to see would be for it to accept a VARIANT parameter.
> Then we could call vb's VarPtr directly with DynaWrap itself.
>
> oDW.Register("msvbvm50.dll", "VarPtr", "i=v", "f=s", "r=l")
> lpProcessID = oDW.VarPtr(myProcessID) + 8 ' add 8 bytes
> ThreadID = oDW.GetWindowThreadProcessID(CLng(hWnd), CLng(lpProcessID))
> MsgBox("GWTProcID returned: " & CStr(myProcessID))
>
> But of course that is all "air code".
>
> Sorry, but DynaWrap has some limitations, and I don't believe it
> will work in the situation you describe.
>
> I expect you will need to find some other solution.
>
> cheers, jw
>
> Gary Roach wrote:
>> thanks for the reply. i got dynacall and used some of your code. i'm
>> having a problem finding windows. i'm using a routine that cycles through
>> windows looking for the one i want. it uses a win32 routine called
>> GetWindowThreadProcessId() that takes a reference to a long uint and uses
>> it to pass back the PID given an hwnd. it works in VBA but not in vbs.
>> any idea how to make this work? thanks again for the help. here's the
>> code:
>>
>> UserWrap.Register "USER32.DLL", "GetWindowThreadProcessId", "I=Hl",
>> "f=s", "R=l"
>>
>> hWndJob = UserWrap.FindWindowA(vbNullString, vbNullString)
>> Do Until hWndJob = 0
>> If UserWrap.GetParent(hWndJob) = 0 Then
>> Call UserWrap.GetWindowThreadProcessId(hWndJob, PID)
>> If PID = ProcessID Then Exit Do
>> End If
>> hWndJob = UserWrap.GetWindow(hWndJob, 2)
>> Loop


.



Relevant Pages

  • Re: want to resize window in vbs
    ... For one thing, I'm surprised you get anything to work with DynaWrap, ... for byref parameters, BUT ONLY STRING parameters. ... and pass the pointer instead of the variable. ... really like to see would be for it to accept a VARIANT parameter. ...
    (microsoft.public.scripting.wsh)
  • Re: How to casting to VARIANT*
    ... > The second parameter to be passed is a range 'object'. ... but I wonder why MSWORD is designed this way. ... in there that just take a plain VARIANT. ... optional are also passed by pointer. ...
    (microsoft.public.vc.atl)
  • Re: Pass arguments with IDispatch.Invoke
    ... Marshal.StructureToPtr(v, LibraryVersion, true); ... I'm getting pointer to the structure from C, ... Alexander Nickolov wrote: ... The problem is a VARIANT does ...
    (microsoft.public.vc.atl)
  • Re: How to casting to VARIANT*
    ... Microsoft MVP, MCSD ... but I wonder why MSWORD is designed this way. ... > in there that just take a plain VARIANT. ... > optional are also passed by pointer. ...
    (microsoft.public.vc.atl)
  • Re: Variants
    ... For UDTs, arrays, objects etc, a ... Variant always contains a pointer. ... But strings in Variants are pointers, ...
    (microsoft.public.vb.general.discussion)

Loading