Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Win API / March 2008



Tip: Looking for answers? Try searching our database.

Com interop -> IUnknown from hWnd

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chris Mierzejewski - 25 Mar 2008 13:21 GMT
Here is the deal:

I have got quite old application which was written in VB 6 using some
ActiveX Controls. My task is to perform some automatic test using Quick Test
Pro, which doesn't recognize those ActiveX controls, but it doesn't matter.

What I want to attain is to get control over an another application ActiveX
control using its window's (control's) handle.
http://rotanes.pl/Project1.exe <- here is really simple application
(requires VB 6 runtime) with a data grid (microsoft Data Grid Control 6.0,
MSDATAGRID.OCX) and one button, which changes data grid height. I want to be
able to do the same from, for example, .net application. Just pass the
handle (I can take it from any spy software) and perform the action.

What I discovered:

This ActiveX grid implements some COM interfaces, which are defined in the
same dll (ocx) file, just use OLE/COM Viewer and everything is visible. So I've
spent more then one week trying (using .net and C#) grab this interface
knowing only controls hwnd.

My attempts (I used to be a .net developer so I wrote everything in C#):

-> Implement interface _cGrid (which is the interface I would like to cast a
COM as) by myself:  [ComImport,
Guid("60E9A471-E4DF-4687-B419-15A644E8AD57]public interface _cGrid{.} Or use
the one generated by tlbimp.exe. -> import some extern procedures:
[DllImport("oleacc.dll", PreserveSig = false)]

[return: MarshalAs(UnmanagedType.Interface)]

public static extern object AccessibleObjectFromWindow(IntPtr hwnd, uint
dwId, ref Guid riid); (I tried this import in several different manners, for
example with UnmanagedType.IUnknonw, UnmanagedType.IDispatch, adding "out
IntPtr ppvd"as the last parameter and changing returned value to int.)
[DllImport("user32.dll")]

public static extern int SendMessage(int hWnd, uint Msg, int wParam, int
lParam); -> Dozens of tries to make everything working (unsuccessfully :( ):
_cGrid result = (_cGrid )InteropClass.AccessibleObjectFromWindow(handle, 0,
ref ITypeInfoGuid); <- throws en exception "Invalid Cast"
InteropClass.AccessibleObjectFromWindow(handle, 0, ref ITypeInfoGuid, out
_cGridPtr); <- after every statement execution _cGridPtr has different value
and it is different from Marshal.GetIUnknownForObject(obj) (I had reference
to the control for my learning purposes, but I won't have). It sends single
WM_GETOBJECT message to the control with 0xffffffff and 0x00000000
parameters (the second parameter referes to the second parameter of
AccessibleObjectFromWindow procedure) which always returns different value
(the subtraction of two sibling values equals 32, coincidence?)
Marshal.GetTypedObjectForIUnknown <- always throws "invalid cast exception"
or something like this. I would appreciate any (the simpler the better,
prefereably c# by can be managed/unmanaged c++ or VB as well) example of
code which works and can retrieve valid IUnknown pointer (or even cast
pointer as interface) from ActiveX control knowing only its hwnd. I found
followiong links helpful: [Some
basis]http://www.codeguru.com/csharp/csharp/cs_misc/com/article.php/c9065/http://www.c
larionmag.com/cmag/v1/v1n6callingole_part1.htmlhttp://www.codeproject.com/KB/COM
/COM_from_scratch_1.aspx

[I think the same
problem]http://www.vbforums.com/archive/index.php/t-158336.html [Hopeful
links]http://www.thescripts.com/forum/thread233284.htmlhttp://msdn2.microsoft.com/en-u
s/library/ms696137(VS.85).aspx

Especially -> Clients call this function to retrieve the address of an
object's IAccessible, IDispatch, IEnumVARIANT, IUnknown, or other supported
interface pointer. I originally posted this message on
http://www.codeguru.com/forum/showthread.php?p=1700068 Thanks in advance.
Jim Mack - 25 Mar 2008 13:57 GMT
> Here is the deal:
>
[quoted text clipped - 4 lines]
> Pro, which doesn't recognize those ActiveX controls, but it doesn't
> matter.

It looks like your question is in the wrong group. This newsgroup is
for VB6 and earlier, while it seems you're looking for a .net solution
("interop" is a clue).

But it's hard to tell because most of your message appears as a jumble
of wrapped lines in my newsreader.

If you're looking for a VB6 solution, could you post again in a
clearer format?

If you're not, then try a group with 'dotnet' or 'vsnet' in its name.

> What I want to attain is to get control over an another application
> ActiveX
[quoted text clipped - 72 lines]
> found
> followiong links helpful: [Some

basis]http://www.codeguru.com/csharp/csharp/cs_misc/com/article.php/c9
065/http://www.clarionmag.com/cmag/v1/v1n6callingole_part1.htmlhttp://
www.codeproject.com/KB/COM/COM_from_scratch_1.aspx
> [I think the same
> problem]http://www.vbforums.com/archive/index.php/t-158336.html
> [Hopeful

links]http://www.thescripts.com/forum/thread233284.htmlhttp://msdn2.mi
crosoft.com/en-us/library/ms696137(VS.85).aspx
> Especially -> Clients call this function to retrieve the address of
> an
[quoted text clipped - 3 lines]
> http://www.codeguru.com/forum/showthread.php?p=1700068 Thanks in
> advance.
Chris Mierzejewski - 27 Mar 2008 08:36 GMT
> It looks like your question is in the wrong group. This newsgroup is
> for VB6 and earlier, while it seems you're looking for a .net solution
[quoted text clipped - 7 lines]
>
> If you're not, then try a group with 'dotnet' or 'vsnet' in its name.

Hi.
Thanks for the answer.
What I am looking for is a working solution, no matter what language it is
written in
The point is - I've got an quite old VB applciation with ActiveX controls
(for example DataGrid which implements IGrid interface). And i woulkd like
to take control over that control knowing only its hwnd and interfaces the
control implements (IGrid). That is all for the summary, the problem seems
really simple :). Any ideas?
Mark Yudkin - 30 Mar 2008 09:42 GMT
I agree with Jim that your problems are with your use of .NET and C#, and
that you're therefore asking in the wrong place. If you want to code your
app in VB6, then do as Jum says, and post the VB6 code that's causing
problems.

AFAIK, you cannot control a DataGrid from another process - only from with
the same process. Your first post implied that you trying to run from a
second process. Your second post removed this fact, but it may merely be
becuase your summary is too brief, as controlling a grid from a VB6
application needs neither the hwnd not IGrid, bnut merely use of normal VB6.

>> It looks like your question is in the wrong group. This newsgroup is
>> for VB6 and earlier, while it seems you're looking for a .net solution
[quoted text clipped - 17 lines]
> control implements (IGrid). That is all for the summary, the problem seems
> really simple :). Any ideas?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.