CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Nov 2013
    Posts
    5

    Add a USB Plug and Play feature inside a vc++ dll

    I have designed a vc++ dll for a controller. I want to add usb plug and play feature inside the dll. I searched on line and came to know:

    "If the project is an unmanaged C++ DLL project, then I can only create windows in an unmanaged way, i.e. the usual Win32 API way, such as adding a new dialog box as a resource, or simply using RegisterClassEx() and CreateWindowEx() to create the window yourself, then pump messages for those windows using GetMessage(), TranslateMessage() and DispatchMessage()."

    I have no idea how to use this concept.

    I have created a separate application (in delphi 2007) that load this Dll. But I want to add this Plug and Play feature inside me dll.

    Kindly help me in this regard.

    Thanks

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Add a USB Plug and Play feature inside a vc++ dll

    The "concept you came to know" is a trivial statement of a couple of obvious things from Win32 API world. No revelation at all, as well as no connection neither with USB nor plug-and-play. You have to come up with better explanation of USB part of your question.
    Best regards,
    Igor

  3. #3
    Join Date
    Nov 2013
    Posts
    5

    Re: Add a USB Plug and Play feature inside a vc++ dll

    Quote Originally Posted by Igor Vartanov View Post
    The "concept you came to know" is a trivial statement of a couple of obvious things from Win32 API world. No revelation at all, as well as no connection neither with USB nor plug-and-play. You have to come up with better explanation of USB part of your question.
    Alright mate,


    "Question": How to add a form inside a VC++ dll.
    I searched online for this issue and I came to know that if the project is an unmanaged C++ DLL project, then I can only create windows in an unmanaged way, i. e. the usual Win32 API way, such as adding a new dialog box as a resource, or simply using RegisterClassEx() and CreateWindowEx() to create the window myself, then pump messages for those windows using GetMessage(), TranslateMessage() and DispatchMessage(). But I have no clue how to do that. Kindly explain me how to write and add functions "RegisterClassEx()", "CreateWindowEx()", "GetMessage()", "TranslateMessage()" and "DispatchMessage()" inside my vc++ dll.


    Kindly help me in this regard!!!
    Thanks

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Add a USB Plug and Play feature inside a vc++ dll

    Quote Originally Posted by Ahsin View Post
    Alright mate,


    "Question": How to add a form inside a VC++ dll.
    I searched online for this issue and I came to know that if the project is an unmanaged C++ DLL project, then I can only create windows in an unmanaged way, i. e. the usual Win32 API way, such as adding a new dialog box as a resource, or simply using RegisterClassEx() and CreateWindowEx() to create the window myself, then pump messages for those windows using GetMessage(), TranslateMessage() and DispatchMessage(). But I have no clue how to do that. Kindly explain me how to write and add functions "RegisterClassEx()", "CreateWindowEx()", "GetMessage()", "TranslateMessage()" and "DispatchMessage()" inside my vc++ dll.
    Or use MFC for the windows.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  5. #5
    Join Date
    Nov 2013
    Posts
    5

    Re: Add a USB Plug and Play feature inside a vc++ dll

    Quote Originally Posted by 2kaud View Post
    Or use MFC for the windows.
    Kindly explain how can I use MFC to create windows inside VC++ dll.

    I want to use .net functions inside VC++ dll. So I want to create a windows form/Dialog to use them

    Kindly help me in this regard.

    Thanks!!!

  6. #6
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Add a USB Plug and Play feature inside a vc++ dll

    MFC is a set of unmanaged classes that wrap the standard API windows functions making it easier to create windows/dialogs etc.
    http://msdn.microsoft.com/en-us/libr...vs.100%29.aspx

    If you want to use .net functions inside the vc++ dll then you will be using managed c++ and you might get better answers posting this question to the Managed c++ forum.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  7. #7
    Join Date
    Nov 2013
    Posts
    5

    Re: Add a USB Plug and Play feature inside a vc++ dll

    Quote Originally Posted by 2kaud View Post
    MFC is a set of unmanaged classes that wrap the standard API windows functions making it easier to create windows/dialogs etc.
    http://msdn.microsoft.com/en-us/libr...vs.100%29.aspx

    If you want to use .net functions inside the vc++ dll then you will be using managed c++ and you might get better answers posting this question to the Managed c++ forum.

    Alright. But I want to create a windows form inside my vc++ dll and then add .net functions. As far as I'm concerned, It is only possible to add a windows form to a project of type Windows Forms or a .net managed class library. If the project is an unmanaged C++ DLL project, then you can only create windows in an unmanaged way, i. e. the usual Win32 API way, such as adding a new dialog box as a resource, or simply using RegisterClassEx() and CreateWindowEx() to create the window myself, then pump messages for those windows using GetMessage(), TranslateMessage() and DispatchMessage().

    But I have no clue how to do that. Kindly explain me how to write and add functions "RegisterClassEx()", "CreateWindowEx()", "GetMessage()", "TranslateMessage()" and "DispatchMessage()" inside my vc++ dll.

    Kindly help me in this regard.

    Thanks

  8. #8
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Add a USB Plug and Play feature inside a vc++ dll

    To answer your question you should make a choice: dialog or plain window?

    In case of dialog, you add a dialog resource to your dll and implement dialog procedure. Then you add a function to your dll that would make use of the dialog. The function has to be exported from your dll to be usable from dll host process.

    In case of window, you create a window procedure. Then you register new window class with the window procedure. After that you create a window of the class you just registered. Ultimately you spin up thread's message pump. Or re-use already existent one, in case your function is intended to be called from a GUI thread. (MSDN: Using Messages and Message Queues)

    Depending on your knowledge you may do that in pure Win32 API, or some GUI framework, like MFC or WTL. And any option above will require some skills specific to the technology you chose.

    However, from what you wrote I can conclude you have none of those. So, pick up any, and start from the very beginning. Acquiring a good book on Windows GUI programming would help you a lot and spare you from asking tons of questions on forums.
    Best regards,
    Igor

  9. #9
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Add a USB Plug and Play feature inside a vc++ dll

    To understand windows programming using the WIN32 api functions I would suggest
    Programming Windows 5th edition by Charles Petzold
    http://www.amazon.co.uk/Programming-...harles+petzold

    and for programming with MFC
    Programming Windows with MFC by Jeff Prosise
    http://www.amazon.co.uk/Programming-...ef=pd_sim_b_22

    depending upon your knowledge of c++ you might also find this of interest
    Beginning Visual c++ 2012
    http://www.amazon.co.uk/Ivor-Hortons...ds=ivor+horton

    These will give you the basics of how to program simple windows based programs. Note that for MFC you will need a detailed understanding of c++ classes.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  10. #10
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Add a USB Plug and Play feature inside a vc++ dll

    Quote Originally Posted by Ahsin View Post
    Alright. But I want to create a windows form inside my vc++ dll and then add .net functions. As far as I'm concerned, It is only possible to add a windows form to a project of type Windows Forms or a .net managed class library. If the project is an unmanaged C++ DLL project, then you can only create windows in an unmanaged way, i. e. the usual Win32 API way, such as adding a new dialog box as a resource, or simply using RegisterClassEx() and CreateWindowEx() to create the window myself, then pump messages for those windows using GetMessage(), TranslateMessage() and DispatchMessage().

    But I have no clue how to do that. Kindly explain me how to write and add functions "RegisterClassEx()", "CreateWindowEx()", "GetMessage()", "TranslateMessage()" and "DispatchMessage()" inside my vc++ dll.

    Kindly help me in this regard.

    Thanks
    What you may want to do is give a general overview of what you are trying to accomplish. This way we can assist with an approach that might be more in line with a best practice approach.

    To be honest, it isn't clear what you are trying to do. A dll that hosts native dialogs, yet adds .net functions? Is this a managed dll or not? Is the dll hosted from a native process or a managed process? Does the dll access manage or native resources?

    Describing what you are trying to achieve exactly will help us help you because there might be a more straightforward approach rather than the mix of technologies you are currently looking for.

  11. #11
    Join Date
    Nov 2013
    Posts
    5

    Re: Add a USB Plug and Play feature inside a vc++ dll

    Quote Originally Posted by Arjay View Post
    What you may want to do is give a general overview of what you are trying to accomplish. This way we can assist with an approach that might be more in line with a best practice approach.

    To be honest, it isn't clear what you are trying to do. A dll that hosts native dialogs, yet adds .net functions? Is this a managed dll or not? Is the dll hosted from a native process or a managed process? Does the dll access manage or native resources?

    Describing what you are trying to achieve exactly will help us help you because there might be a more straightforward approach rather than the mix of technologies you are currently looking for.

    I want to do RegisterDeviceNotification inside my vc++ dll. But I have no idea how to implement inside the dll.

    I want my software to detect the connect/disconnect events of the USB.

    Kindly help me in this regard.

    Thanks

  12. #12
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Add a USB Plug and Play feature inside a vc++ dll

    Quote Originally Posted by Ahsin View Post
    I want to do RegisterDeviceNotification inside my vc++ dll. But I have no idea how to implement inside the dll.
    RegisterDeviceNotification requires either window handle or service handle:
    hRecipient [in]

    A handle to the window or service that will receive device events for the devices specified in the NotificationFilter parameter. The same window handle can be used in multiple calls to RegisterDeviceNotification.

    Services can specify either a window handle or service status handle.
    I don't think you go with creating service, so it should be a window. To create window please see my post #8. Or feel free to google.
    Best regards,
    Igor

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