CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Jun 2002
    Location
    India,bangalore
    Posts
    295

    Place VC++ child dialog(dll) inside VB form ??

    Hi all,

    I have VC++ regular dll which creates a dialog as child and returns pointer.

    My requirement is i need to invoke this DLL from VB and place the created child dialog inside VB form

    First of all is this possible? is yes how can we achive it?

    //////////////////////////////////////////////////////////
    Background

    I dont have much idea about VB as i am vc++ programmer, My colleague says its impossible to display a vc++ child dialog(dll) in her VB form but can display a vc++ dialog if its of popup style.

    But my requirement is VC++ child dialog has to be displayed inside VB forms and not as popop window.

  2. #2
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: Place VC++ child dialog(dll) inside VB form ??

    Possible it is.
    First you have to declare the function and its origin like
    Code:
    Declare Function myDllFunction Lib "mydll.dll" ([optioanl parameters]) As Long
    In your VB ptogram you invoke it like
    Code:
      Dim retval As Long
      retval = myDllFunction([parameters if any])
    The appearance of the popup, however, would propably be on top of the B windows, but not actually inside them.
    The function should return the actual window handle (hWnd) of the popup, then we could think of methods to make a VB window parent to it, or at least simulate an appearance "within" the VB window.

  3. #3
    Join Date
    Jun 2002
    Location
    India,bangalore
    Posts
    295

    Re: Place VC++ child dialog(dll) inside VB form ??

    Thanks for the reply.

    Quote Originally Posted by WoF View Post
    Possible it is.
    First you have to declare the function and its origin like
    Code:
    Declare Function myDllFunction Lib "mydll.dll" ([optioanl parameters]) As Long
    In your VB ptogram you invoke it like
    Code:
      Dim retval As Long
      retval = myDllFunction([parameters if any])
    She has done these steps and is able to display it as Popup.

    Quote Originally Posted by WoF View Post
    The appearance of the popup, however, would propably be on top of the B windows, but not actually inside them.
    Yes, this is the problem.

    Quote Originally Posted by WoF View Post
    The function should return the actual window handle (hWnd) of the popup,
    The function can be modified to return hWnd, no issues.

    Quote Originally Posted by WoF View Post
    then we could think of methods to make a VB window parent to it, or at least simulate an appearance "within" the VB window.
    What are all the methods to make a VB window parent to it? as i am passing child window m_hwnd to VB.

    Please lets not simulate the appearance "within" the VB window.

  4. #4
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: Place VC++ child dialog(dll) inside VB form ??

    There is an API call SetParent, which should do what you want:
    http://allapi.mentalis.org/apilist/SetParent.shtml

    Although I'm not quite sure about a form "in" another form, except if the parent is an MDI form which has child forms within its area.

  5. #5
    Join Date
    Jun 2002
    Location
    India,bangalore
    Posts
    295

    Re: Place VC++ child dialog(dll) inside VB form ??

    A sample VC++ dll called VCDllChildDlg has been attached.

    Entry function is CallDllChildWindow which returns HWND

    extern "C" __declspec(dllexport) HWND CallDllChildWindow()

    Can you place the vc++ child dialog inside VB Form? If vb is MDI form or just a Form no issues.
    Attached Files Attached Files

  6. #6
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: Place VC++ child dialog(dll) inside VB form ??

    Well, why can't you?
    Did you try the SetParent function according to the instructions?

    It gives us all a bad feeling to run unknown code from a dll on our ccomputers.

  7. #7
    Join Date
    Jun 2002
    Location
    India,bangalore
    Posts
    295

    Re: Place VC++ child dialog(dll) inside VB form ??

    Quote Originally Posted by WoF View Post
    Well, why can't you?
    Beacause i dont know VB

    Quote Originally Posted by WoF View Post
    Did you try the SetParent function according to the instructions?
    I cant tell the VB guys as they say they are expert and they cant achieve above requirement.

    Quote Originally Posted by WoF View Post
    It gives us all a bad feeling to run unknown code from a dll on our ccomputers.
    To be honest, If i were you i would have created the VB app and would have attached VB source here instead of using an unknown code. I guess it hardly a 5 lines of code.

  8. #8
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Place VC++ child dialog(dll) inside VB form ??

    You could post the code:
    Code:
    ' Like THIS
    w/CODE TAGS
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  9. #9
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: Place VC++ child dialog(dll) inside VB form ??

    Ok, I misunderstood.

    So, assumed you have a form named Form1 and you want to open your dll's child and attach it to Form1 then this is the code:
    Code:
    'First the SetParent API function is declared.
    Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    
    'Then the function inside your dll is declared.
    Declare Function CallDllChildWindow Lib "VCDllChildDlg.dll" () As Long
    
    'A variable ChildWindow is declared to hold the hWnd of the child
    Private ChildhWnd As Long
    
    Sub OpenAndAttachChild()
    ' this calls your dll for the child window and calls SetParent to attach it to the Form1.
      Dim res As Long
      ChildhWnd = CallDllChildWindow
      res = SetParent(ChildhWnd, Form1.hWnd)
      If res <> 0 Then 'you have succeeded, otherwise the call failed for some reason.
    End Sub
    Instead of Form1.hWnd you could write Me.hWnd when the code is within the parent form.

  10. #10
    Join Date
    Jun 2002
    Location
    India,bangalore
    Posts
    295

    Re: Place VC++ child dialog(dll) inside VB form ??

    @WoF - Much appreciated for the code.

    When i copied your code to form1.frm it was giving compiler errors.
    I figured out that we have to add Private before 'Declare' keyword with the help of google.

    Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long

    Thats it, it worked for me .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured