Converting program with C and asm code to a DLL

619 Views Asked by At

My algorithm contains C and asm code. I need to call this algorithm in a C# application. I was wondering if I could convert the C and asm code to a DLL and then call it in the C# console application. But I'm very unclear about how to convert the coupled C and asm code algorithm into a DLL. Any help is appreciated.

I know how to use PInvoke to call the DLL in C#. My issue is converting the combined C and asm code to a DLL. VS 2010 keeps vomitting errors when I try to use extern "C" and dllexport. There are over 90 errors!! Most of the errors are those complaining that C++ doesn't support the stuff I've used(though they are valid in C). Like for example, this line of code:

const u8 *error_string_base="ERROR: "; 

gives an

error C4430: missing type specifier -int assumed. Note C++ does not support default-int

2

There are 2 best solutions below

6
Eric J. On

Yes, you can call unmanaged code that is in a DLL from C#.

Platform Invocation Services (PInvoke) allows managed code to call unmanaged functions that are implemented in a DLL.

http://msdn.microsoft.com/en-us/library/aa288468(v=vs.71).aspx

You'll probably want to have a look at the topic Calling a DLL Export Directly from C#

http://msdn.microsoft.com/en-us/library/aa288468(v=vs.71).aspx#pinvoke_callingdllexport

UPDATE (Based on your edit)

Compile your application in C mode rather than C++ mode

Go to properties -> c/c++ ->advanced -> compile as and select 'c'

1
Alok On

Better way is to Create a Dll Application(COM dll or Others) and Write your code in VC++ ,which is very similar to C and you can also merge your asm code like this

 __asm {
         mov al, 2
         mov dx, 0xD007
         out dx, al
       } 

,i mean using __asm keyword.Creating dll application is not a big deal ..There is a lot of resources on net for this.Importing and Exporting Dll's have many constraint ,that's why your code keeps vomitting errors .