Attempting to convert a C program into C# - is it possible?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Attempting to convert a C program into C# - is it possible?

  1. #1
    Join Date
    May 2006
    Posts
    6

    Attempting to convert a C program into C# - is it possible?

    I'm a newbie C# programmer, attempting to create an API to talk to a sales tax API which is housed at another location. I have all of the header files, all of the dll's and the connection to the database. However, the program is a C program and only 6 of the dll's are COM dll's. The others are all C and I am unable to reference them to my program. Not to mention the header files are useless. However they are necessary for me to connect and utilize the full gamut of functionality and methods. Is it possible to create this API and figure out a way to utilize the C dll's somehow? As well as the headers? Or am I getting way to ahead of myself?

    I've heard that its possible to write wrapper programs to wrap each of the header files and dll's and that, that way, it may be possible to write a C# API which can use the dll's and header files and actually get the job done. How difficult is it to write these wrapper programs? How can PInvoke come into play, here?
    Last edited by CodeBugger; April 15th, 2014 at 10:47 AM. Reason: new info

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,289

    Re: Attempting to convert a C program into C# - is it possible?

    There are several approaches:
    1) PInvoke to your C dlls
    2) Use the C source code and write managed C++ wrapper assemblies around the code.

    PInvoke to the existing dlls is by far the simplest approach providing the dll function signatures are somewhat standard. See PInvoke.net for more help.

    Note: If you pinvoke to the existing dlls, unlike in C/C++ you don't need to use the header files.

  3. #3
    Join Date
    May 2006
    Posts
    6

    Re: Attempting to convert a C program into C# - is it possible?

    Quote Originally Posted by Arjay View Post
    There are several approaches:
    1) PInvoke to your C dlls
    2) Use the C source code and write managed C++ wrapper assemblies around the code.

    PInvoke to the existing dlls is by far the simplest approach providing the dll function signatures are somewhat standard. See PInvoke.net for more help.

    Note: If you pinvoke to the existing dlls, unlike in C/C++ you don't need to use the header files.
    Thank you Arjay. I had never heard of PInvoke before today. I will refer to PInvoke.net to see what it has to offer. I assume that since I will not need or be able to use the header files, that I will need to use PInvoke somehow for each of my C dll's - All 30 of them? Does this mean I will create a separate class for each of the dll's? Any PInvoke oddities I should be aware of?

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,289

    Re: Attempting to convert a C program into C# - is it possible?

    Quote Originally Posted by CodeBugger View Post
    that I will need to use PInvoke somehow for each of my C dll's - All 30 of them?
    Yes
    Quote Originally Posted by CodeBugger View Post
    Does this mean I will create a separate class for each of the dll's?
    Yes.
    Quote Originally Posted by CodeBugger View Post
    Any PInvoke oddities I should be aware of?
    The hardest part is getting the PInvoke dll signatures correct. Refer to PInvoke in msdn and the PInvoke.Net site.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center