Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. IT & Infrastructure
  4. need help in interacting with C and C#

need help in interacting with C and C#

Scheduled Pinned Locked Moved IT & Infrastructure
helpquestioncsharpvisual-studiotutorial
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    ekynox
    wrote on last edited by
    #1

    Hi guys, At the moment I am stuck on a problem pertaining to an issue with a SDK written in C. This SDK is the Paperport sdk, a scanning software solution from ScanSoft. They have provided some sample applications written in C, to illustrate how one can use the sdk. The problem I am facing is that how do I make the C functions of the SDK interact with my C# win form ? There is an example in the sdk which does to a limited extent what I want to achieve. The sample application makes use of the OPENFILENAME control. The "OPENFILENAME" is the Save As Dialog in windows. In this example scannsoft have managed to access OPENFILENAME control by including commdlg.h header file with their sample project C file. The issue I am having difficulty is how do I pass my C# winform into this sample application ? Further, I can compile this sample application with VS. I would appreciate if anyone can give me some hints as to how i can achieve a solution. thanks

    C 1 Reply Last reply
    0
    • E ekynox

      Hi guys, At the moment I am stuck on a problem pertaining to an issue with a SDK written in C. This SDK is the Paperport sdk, a scanning software solution from ScanSoft. They have provided some sample applications written in C, to illustrate how one can use the sdk. The problem I am facing is that how do I make the C functions of the SDK interact with my C# win form ? There is an example in the sdk which does to a limited extent what I want to achieve. The sample application makes use of the OPENFILENAME control. The "OPENFILENAME" is the Save As Dialog in windows. In this example scannsoft have managed to access OPENFILENAME control by including commdlg.h header file with their sample project C file. The issue I am having difficulty is how do I pass my C# winform into this sample application ? Further, I can compile this sample application with VS. I would appreciate if anyone can give me some hints as to how i can achieve a solution. thanks

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      ekynox wrote:

      The problem I am facing is that how do I make the C functions of the SDK interact with my C# win form ?

      Simple - write a C++/CLI ( or managed C++ ) wrapper. I do the exact same thing to gain access to the Canon SDK in C#. You write a managed class which contains an instance of the SDK classes, and expose methods to call methods on the SDK.

      ekynox wrote:

      The issue I am having difficulty is how do I pass my C# winform into this sample application ?

      Are you saying you need to pass the handle to your form through to the SDK ? You can do this, I believe there's a Handle property on a windows form. If it's called something else, it's still the same thing. Christian Graus - Microsoft MVP - C++

      E 1 Reply Last reply
      0
      • C Christian Graus

        ekynox wrote:

        The problem I am facing is that how do I make the C functions of the SDK interact with my C# win form ?

        Simple - write a C++/CLI ( or managed C++ ) wrapper. I do the exact same thing to gain access to the Canon SDK in C#. You write a managed class which contains an instance of the SDK classes, and expose methods to call methods on the SDK.

        ekynox wrote:

        The issue I am having difficulty is how do I pass my C# winform into this sample application ?

        Are you saying you need to pass the handle to your form through to the SDK ? You can do this, I believe there's a Handle property on a windows form. If it's called something else, it's still the same thing. Christian Graus - Microsoft MVP - C++

        E Offline
        E Offline
        ekynox
        wrote on last edited by
        #3

        thanks for the reply Christian . i was wondering if you know of any tutorials online which shows how you can write managed c++ wrapper for unmanaged code. Since this is going to be a first for me to write a managed wrapper for unmanaged code. What I had implied by passing my C# winform was that, I also have a similar dialog to the OPENFILENAME control provided in the commdlg.h header file. So my question was if a windows control can be included in a header file. This header file was one of the include statements in the sample sdk application. Therefore my question was how do I pass my C# win form into the C code just the same way as OPENFILENAME. Now from your response it seems that by writing a managed wrapper i can achieve this.

        C 1 Reply Last reply
        0
        • E ekynox

          thanks for the reply Christian . i was wondering if you know of any tutorials online which shows how you can write managed c++ wrapper for unmanaged code. Since this is going to be a first for me to write a managed wrapper for unmanaged code. What I had implied by passing my C# winform was that, I also have a similar dialog to the OPENFILENAME control provided in the commdlg.h header file. So my question was if a windows control can be included in a header file. This header file was one of the include statements in the sample sdk application. Therefore my question was how do I pass my C# win form into the C code just the same way as OPENFILENAME. Now from your response it seems that by writing a managed wrapper i can achieve this.

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          ekynox wrote:

          i was wondering if you know of any tutorials online which shows how you can write managed c++ wrapper for unmanaged code.

          I'm afraid I don't know of any. I pretty much winged it, creating a MC++ dll, and then adding my non managed code to it, with MSDN on stand by. Which is good news, if I can do that, anyone can :P

          ekynox wrote:

          Therefore my question was how do I pass my C# win form into the C code just the same way as OPENFILENAME.

          Nope - I'd bet a fair amount of money that you can't pass an instance of a C# dialog through for a C program to be calling. For starters, C knows nothing of classes, but I think that's the least of your worries. If you have a dialog that exists in C#, it has a handle that you could pass through, but a class instance to be called is a whole other story. Christian Graus - Microsoft MVP - C++

          E 1 Reply Last reply
          0
          • C Christian Graus

            ekynox wrote:

            i was wondering if you know of any tutorials online which shows how you can write managed c++ wrapper for unmanaged code.

            I'm afraid I don't know of any. I pretty much winged it, creating a MC++ dll, and then adding my non managed code to it, with MSDN on stand by. Which is good news, if I can do that, anyone can :P

            ekynox wrote:

            Therefore my question was how do I pass my C# win form into the C code just the same way as OPENFILENAME.

            Nope - I'd bet a fair amount of money that you can't pass an instance of a C# dialog through for a C program to be calling. For starters, C knows nothing of classes, but I think that's the least of your worries. If you have a dialog that exists in C#, it has a handle that you could pass through, but a class instance to be called is a whole other story. Christian Graus - Microsoft MVP - C++

            E Offline
            E Offline
            ekynox
            wrote on last edited by
            #5

            well i managed to work out a simple solution my problem. I cheated but it saved me the pain of writing managed c++ wrapper. i had to read the sdk manual a bit more carefully, worked out how to extract the information i was after from one of the methods, transfered that to an xml file. Now i have to modify couple of lines in my c# winform and i am done. :-)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups