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?
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.
Re: Attempting to convert a C program into C# - is it possible?
Quote:
Originally Posted by
Arjay
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?
Re: Attempting to convert a C program into C# - is it possible?
Quote:
Originally Posted by
CodeBugger
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
Does this mean I will create a separate class for each of the dll's?
Yes.
Quote:
Originally Posted by
CodeBugger
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.