0

I am trying to find the handle of a VB.Net WPF application. I have tried various hWnd IntPtr commands with no luck

Me.Handle gives the error 'Handle' is not a parameter of MainWindow

Dim itnrp As IntPtr = Process.GetCurrentProcess().MainWindowHandle

gives the error:

error BC30657: 'ToPointer' has a return type that is not supported or parameter types that are not supported.

If I try putting it into a function to try and get the type that the above error appears to refer to like this...:

Public Function GetHandleOfWindow()
    winHandle = Process.GetCurrentProcess().MainWindowHandle.GetType()
    'Return winHandle
End Function

I get the same error BC30657 as previous

If I try:

Public winHandle As IntPtr winHandle = New WindowInteropHelper(Me).Handle

I get the same error BC30657 as previous

Any help would be much appreciated!!

Andy_
  • 19
  • 6
  • 1
    Why are you using `Process`? In VB.Net, to refer to your own windows you typically use `Me`. Also, where is this code being executed? In what context? – Ken White Aug 08 '19 at 16:30
  • I tried Me.Handle also with no luck - seems to give the same error. I have a WPF form, as it is loading I am trying to get the handle. I am then using the handle to dock it into a winform is the plan. I have a solution with C# and VB projects. The VB project is referenced within the C# project. I'm trying to pass the handle of the VB WPF window into C# and dock it into a panel within a C# winform – Andy_ Aug 08 '19 at 16:34
  • You should add the WPF tag instead of the redundant *handle* tag or the non-applicable *visual-studio-2019* tag. It helps if your question is specific to a UI framework if we know it. :-) – Ken White Aug 08 '19 at 16:50
  • How do I do this please? – Andy_ Aug 08 '19 at 16:52
  • 2
    Possible duplicate of [Finding the handle to a WPF window](https://stackoverflow.com/questions/1556182/finding-the-handle-to-a-wpf-window) (and about a dozen more searching here for *window handle in WPF*). – Ken White Aug 08 '19 at 16:52
  • I already corrected the tags for you, as you can see in the lower left corner of your post (across from your user name). – Ken White Aug 08 '19 at 16:54
  • No luck unfortunately, I've tried this: `Public winHandle As IntPtr winHandle = New WindowInteropHelper(Me).Handle` I'm getting the same errors as before – Andy_ Aug 08 '19 at 17:04
  • Searching this site for **window handle in WPF** and **window handle in XAML** both return a list of many results. Have you done any reading of the results of that search other than the one I specifically linked above? – Ken White Aug 08 '19 at 17:22
  • @KenWhite I think it may be a case that Visual Studio is broken - I've seen this link [https://developercommunity.visualstudio.com/content/problem/491378/vb-intptr-error-bc30657-topointer-has-a-return-typ.html] – Andy_ Aug 08 '19 at 18:11

1 Answers1

0

It would appear this is a bug within Visual Studio 2019
[https://developercommunity.visualstudio.com/content/problem/491378/vb-intptr-error-bc30657-topointer-has-a-return-typ.html]]

Andy_
  • 19
  • 6