locked
Is it possible to use both a Windows Form Application and Native Code in a Application? RRS feed

  • Question

  • I was wondering if it is possible to create a Windows Form Application, with several buttons. When one button is clicked it goes to the code within a c++ class and performs an operation. Is this possible? Can you show me an example like when button1 is clicked, how to make it perform lines 4 - 8 in a c++ class file? Explain it as simple as possible in your answer.
    Tuesday, July 13, 2010 10:13 PM

Answers

  • Hi Shadowhunter9636,

    >>Is it possible to use both a Windows Form Application and Native Code in a Application?

    Yes, it is possible. If we are working on Windows Form Application, the default compiler option is using Pure CLR (/clr:pure), we can switch this option via project Property pages -> Configuration Properties-> General -> Common Language Runtime support.

    Once we use /clr, the application becomes a mixed managed/unmanaged application and start to accept native C++ code.

    >>Can you show me an example like when button1 is clicked, how to make it perform lines 4 - 8 in a c++ class file?

    Hammadi Dali is correct. If the code locates in lines4-8 is exactly a function, you can call this function directly from the button handler. If these codes can be executed alone and we know the source code, you can copy and paste the native code to the button handler, it should be executed successfully.

    If you have any concern, please let me know.

    Cheers,

    Yi


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, July 15, 2010 6:25 AM
    Moderator

All replies

  • Hi

    The C++ code in others classes will be interpreted as block of code and not as a simple texte, so it will be better to access it as separated functions.

    I was wondering if it is possible to create a Windows Form Application, with several buttons. When one button is clicked it goes to the code within a c++ class and performs an operation. Is this possible? Can you show me an example like when button1 is clicked, how to make it perform lines 4 - 8 in a c++ class file? Explain it as simple as possible in your answer.

    Regards

    Wednesday, July 14, 2010 11:34 AM
  • Hi Shadowhunter9636,

    >>Is it possible to use both a Windows Form Application and Native Code in a Application?

    Yes, it is possible. If we are working on Windows Form Application, the default compiler option is using Pure CLR (/clr:pure), we can switch this option via project Property pages -> Configuration Properties-> General -> Common Language Runtime support.

    Once we use /clr, the application becomes a mixed managed/unmanaged application and start to accept native C++ code.

    >>Can you show me an example like when button1 is clicked, how to make it perform lines 4 - 8 in a c++ class file?

    Hammadi Dali is correct. If the code locates in lines4-8 is exactly a function, you can call this function directly from the button handler. If these codes can be executed alone and we know the source code, you can copy and paste the native code to the button handler, it should be executed successfully.

    If you have any concern, please let me know.

    Cheers,

    Yi


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, July 15, 2010 6:25 AM
    Moderator