none
Using two Button classes for single Button control MFC RRS feed

  • Question

  • Hi,

    Here is my problem:

    I have a VC++ MFC dialog based application. There I am adding a Button to my dialog by just drag and drop from the tool box.

    I am also having a MyCustomButton.dll to give new looks to the button.

    Inside MyCustomButton.dll, MyCustomButton.cpp is the button class which is derived from CButton. 

    Now I want the behavior of my application in such a way at execution of my application, like if the  MyCustomButton.dll is present in system then the button of my dialog should look like as per implementation of MyCustomButton.dll, where as if the dll is not present normal MFC button should get displayed.

    Please guide me in achieving this. How can I make my application (*.exe) decide at run time.

    Thanks in Advance,


    Thanks & Regards, Mayank Agarwal

    Friday, January 16, 2015 8:56 AM

All replies

  • You can make it an ActiveX control and can register on the machine . So if someone want they can use your control .Anyway up to the time no one is creating object of your class MyCustomButton. You can't Do anything .In last it's your dll then what's the problem ship your dll with your exe and from your exe load corresponding class to create your button . But if you want any third party to show your button then without some code change at there end this is not going to be happen.

    Thanks


    Rupesh Shukla

    Friday, January 16, 2015 2:58 PM
  • Thanks Rupesh,

    But my requirement is like that only I have to decide at run time.

    Please look the scenario below:

    //  MyDialogDlg.h //

    #include "MyCustomButton.h"

    class MyDialogDlg

    {

    MyCustomButton m_CalcButton;

    };

    In the above piece of code m_CalcButton is object of  MyCustomButton class.

    and my requirement is such that if MyCustomButton .dll is not present then,  m_CalcButton should executed as the object of CButton class of MFC.

    There are cases where I  cant ship the dll.

    In such case how should I write the code? Please guide.

    Thanks in Advance.  


    Thanks & Regards, Mayank Agarwal

    Monday, January 19, 2015 9:20 AM
  • Do you need a dll here for this button creation . Why not put your code at same place so that you always going to have this code embedded in your exe.

    Thanks


    Rupesh Shukla


    Tuesday, January 20, 2015 6:53 PM
  • actually this dll supports many application, and I do not have the code of this dll, I am just using it for my application.

    Thanks & Regards, Mayank Agarwal

    Wednesday, January 21, 2015 3:33 AM
  • What i can think here create one same class MyCustomButton which is derived from CButton as well.Now try LoadLibrary() if it succeeded  then Use GetProcAddress() to corresponding function which will create instance of your foo class and return it to you . Assign it to your class else use your class as it is.

    Thanks


    Rupesh Shukla

    Friday, January 23, 2015 4:08 PM
  • Hi Rupesh,

    Can you please elaborate or show as a sample code. 


    Thanks & Regards, Mayank Agarwal

    Thursday, February 5, 2015 9:23 AM
  • Hi Rupesh,

    Can you please elaborate or show as a sample code. 


    Thanks & Regards, Mayank Agarwal

    Hello MayankAg, You also can try alternative way as well which is quite easy for you . Create two version of your exe . And inside your installshield script check if dll is present on the machine then install the exe which has your button control stufff else install another one . You can do it multiple way.

    Thanks

                               


    Rupesh Shukla

    Friday, February 6, 2015 2:51 PM
  • Hi Rupesh,

    Can you please elaborate or show as a sample code. 


    Thanks & Regards, Mayank Agarwal

    Did you tried anything as mentioned above logic . If yes can you show your code and let us know what is the problem you are getting there.

    Thanks


    Rupesh Shukla

    Friday, February 6, 2015 4:06 PM