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

November 5th, 2013, 10:50 PM

Igor Vartanov

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.

November 6th, 2013, 03:18 AM

Ahsin

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

Quote:

Originally Posted by Igor Vartanov

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

November 6th, 2013, 05:36 AM

2kaud

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

Quote:

Originally Posted by Ahsin

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.

November 6th, 2013, 05:46 AM

Ahsin

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

Quote:

Originally Posted by 2kaud

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

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

November 6th, 2013, 06:49 AM

Igor Vartanov

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 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.

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.

November 6th, 2013, 11:03 AM

Arjay

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

Quote:

Originally Posted by Ahsin

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.

November 7th, 2013, 02:33 AM

Ahsin

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

Quote:

Originally Posted by Arjay

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

November 7th, 2013, 03:41 AM

Igor Vartanov

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

Quote:

Originally Posted by Ahsin

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

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. :)