Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Passing around params VC++6.0 VC#

Passing around params VC++6.0 VC#

Scheduled Pinned Locked Moved C / C++ / MFC
questioncsharpc++com
8 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    NHM
    wrote on last edited by
    #1

    :confused:Greetings. I'm using a VC++ 6.0 MDI to call a VC# form .dll. I exposed the VC# dll as a COM interface... n now I need to tell the VC# dll who's the daddy... but the VC# forms daddy should be a System.Windows.Forms.Form()... So i want to pass the handle of the VC++ 6.0 MDI app to a method from the VC#... it asks for an IUnknown... Please tell me how do i take the this->m_hWnd pass it through an IUnknow* and finally put it in a System.Windows.Forms.Form object... can this b done? is there a more friendly way? Thanks:confused: NHM

    S 1 Reply Last reply
    0
    • N NHM

      :confused:Greetings. I'm using a VC++ 6.0 MDI to call a VC# form .dll. I exposed the VC# dll as a COM interface... n now I need to tell the VC# dll who's the daddy... but the VC# forms daddy should be a System.Windows.Forms.Form()... So i want to pass the handle of the VC++ 6.0 MDI app to a method from the VC#... it asks for an IUnknown... Please tell me how do i take the this->m_hWnd pass it through an IUnknow* and finally put it in a System.Windows.Forms.Form object... can this b done? is there a more friendly way? Thanks:confused: NHM

      S Offline
      S Offline
      Stephane Rodriguez
      wrote on last edited by
      #2

      If the only thing you need to pass is a window handle, then ::SendMessage(...) is probably the fastest way to achieve it. It does not require the COM interop you have mentioned.

      N 1 Reply Last reply
      0
      • S Stephane Rodriguez

        If the only thing you need to pass is a window handle, then ::SendMessage(...) is probably the fastest way to achieve it. It does not require the COM interop you have mentioned.

        N Offline
        N Offline
        NHM
        wrote on last edited by
        #3

        how can the VC# dll receive messages... in vc++6.0 PreTranslateMessage is the answer... n in VC#?:confused:

        S 1 Reply Last reply
        0
        • N NHM

          how can the VC# dll receive messages... in vc++6.0 PreTranslateMessage is the answer... n in VC#?:confused:

          S Offline
          S Offline
          Stephane Rodriguez
          wrote on last edited by
          #4

          NHM wrote: how can the VC# dll receive messages... in vc++6.0 PreTranslateMessage is the answer... n in VC#? A Windows Forms app has a UI thread which processes windows messages just like any WIN32 app with a message loop. Any Windows Form control has a virtual WndProc method that can be overridden to respond accordingly. The other way, a C# app can send a WIN32 message to any window (for instance a window from a VC++6 app) by using the [DllImport] P/Invoke technique : [DllImport("user32.dll", CharSet=CharSet.Auto)] public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);

          N 1 Reply Last reply
          0
          • S Stephane Rodriguez

            NHM wrote: how can the VC# dll receive messages... in vc++6.0 PreTranslateMessage is the answer... n in VC#? A Windows Forms app has a UI thread which processes windows messages just like any WIN32 app with a message loop. Any Windows Form control has a virtual WndProc method that can be overridden to respond accordingly. The other way, a C# app can send a WIN32 message to any window (for instance a window from a VC++6 app) by using the [DllImport] P/Invoke technique : [DllImport("user32.dll", CharSet=CharSet.Auto)] public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);

            N Offline
            N Offline
            NHM
            wrote on last edited by
            #5

            if i override WndProc in the windows form (C# dll) then when i try to open it through the VC++ 6.0 App it stops execution... just gives a runtime error... ideas? thanks 4 your suport .S.Rod!

            S 1 Reply Last reply
            0
            • N NHM

              if i override WndProc in the windows form (C# dll) then when i try to open it through the VC++ 6.0 App it stops execution... just gives a runtime error... ideas? thanks 4 your suport .S.Rod!

              S Offline
              S Offline
              Stephane Rodriguez
              wrote on last edited by
              #6

              NHM wrote: when i try to open it through the VC++ 6.0 App What do you mean ? Has it anything to do with the debug session ? Do you mean you are trying to access the C# WndProc implementation from your VC++ debug session ? No need to go further, you simply can't. Or do you mean you are processing the message in the C# wndproc implementation and then it fails? If the code fails at this point, then it might be helpful for those listening if you post the code.

              N 1 Reply Last reply
              0
              • S Stephane Rodriguez

                NHM wrote: when i try to open it through the VC++ 6.0 App What do you mean ? Has it anything to do with the debug session ? Do you mean you are trying to access the C# WndProc implementation from your VC++ debug session ? No need to go further, you simply can't. Or do you mean you are processing the message in the C# wndproc implementation and then it fails? If the code fails at this point, then it might be helpful for those listening if you post the code.

                N Offline
                N Offline
                NHM
                wrote on last edited by
                #7

                i've just overriden the WndProc... no code added to the base override... this is what i have... a) a vc++ 6.0 Mdi app (.exe) b) a vc# dll with: - class A (interface) (cominterop) (i have to call some methods and access some properties) - class B (windows form) in the vc++ 6.0 mdi app i create an instance of classA then i call a method from class A wich does this: public void SomeThing() { Form1 f = new Form1(); f.Show(); } and this is what i intended to do: public void SomeThing( Form parent) { Form1 f = new Form1( Form parent); f.MdiParent = parent; f.Show(); } i just want to say to the VC# winForm that his container is the VC++ 6.0 APP what can i do?

                S 1 Reply Last reply
                0
                • N NHM

                  i've just overriden the WndProc... no code added to the base override... this is what i have... a) a vc++ 6.0 Mdi app (.exe) b) a vc# dll with: - class A (interface) (cominterop) (i have to call some methods and access some properties) - class B (windows form) in the vc++ 6.0 mdi app i create an instance of classA then i call a method from class A wich does this: public void SomeThing() { Form1 f = new Form1(); f.Show(); } and this is what i intended to do: public void SomeThing( Form parent) { Form1 f = new Form1( Form parent); f.MdiParent = parent; f.Show(); } i just want to say to the VC# winForm that his container is the VC++ 6.0 APP what can i do?

                  S Offline
                  S Offline
                  Stephane Rodriguez
                  wrote on last edited by
                  #8

                  The simplest thing that comes to my mind is to reparent the C# form window. This can be done with simple things : - the window handle of the C# form is obtained using this.Handle if you use managed code. Otherwise, from C++ code you can enum windows or use FindWindow(...) with a particular caption to get that window handle. - then, use WIN32 ::SetParent(hwndForm, hwndNewParent /*MDIapp frame window hande*/) to reparent the form. Good luck!

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups