You should have started a new thread for this question as it doesn't appear to have anything to do with the subject of this thread and the code is virtually unreadable in any case.
The only obvious problem I can see is that 'List' is used without a type parameter if this is the same List as the framework class, System.Collections.Generic.List.
No worries, it's not something you'd be likely to know unless (like me) you've spent years inter-operating with unmanaged code.
@ sridevi pc
If the console is closing before you've time to read the output, I'd try inserting the highlighted lines towards the end of the main() function in test.c:
printf("\n");
system("pause");
return 0;
It's also struck me that if you're using a version of the C# compiler prior to 2.0 then you'll also be using a version of ilasm.exe prior to 2.0.
If that's the case then you'll need to do more to the IL than just adding an .export directive (ilasm 2.0 does most of this for you). I've highlighted all the lines that need inserting:
// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.1
// Copyright (c) Microsoft Corporation. All rights reserved.
Hi Vulpes,
Thanks for the reply
when i try to do step to am getting errorr message "
multiply.cs(3,21): error CS0106: The modifier 'static' is not valid for this
item "
csc /t:library multiply.cs
should i make Multiply function as non static
Hi , Thanks for the reply when i try to do step to am getting errorr message " multiply.cs(3,21): error CS0106: The modifier 'static' is not valid for this item "
Despite what Vithal said, it is possible to do this using a little known technique called reverse P/Invoke.
However, as the C# compiler doesn't support DLL exports directly, you have to create the C# dll, edit the IL to insert an .export directive for each method you want to export and then recompile the dll using a tool called ilasm.exe.
Also, as C knows nothing about objects, this will only work with static methods whose parameters and return types are simple types.
Although none of this is particularly difficult, it is rather messy so I'll try to describe each step in turn.
First, go into the Visual Studio command prompt, type: notepad multiply.cs, enter the following code and save it:
using System;
public static class Arithmetic
{
public static int Multiply(int num1, int num2)
{
return num1 * num2;
}
}
Now type the following at the command prompt to compile this into a .dll
csc /t:library multiply.cs
Next type this at the command prompt to extract the IL from the dll using ildasm.exe and put it into a file called multiply2.il:
ildasm multiply.dll /out=multiply2.il
Next open multiply2.il in notepad and insert the line I've highlighted (which will cause the Multiply method to be available as a DLL export) and save it:
// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.1
// Copyright (c) Microsoft Corporation. All rights reserved.
not possible madam, the compilers and envirment are different for both the languages and most important thing is that C# is a object oriented language...
VulpesPosted Jan 10, 2013, 5:20 AM
The only obvious problem I can see is that 'List' is used without a type parameter if this is the same List as the framework class, System.Collections.Generic.List
I'd have thought it needed to be List
VulpesPosted Nov 30, 2012, 8:44 AM
No worries, it's not something you'd be likely to know unless (like me) you've spent years inter-operating with unmanaged code.
@ sridevi pc
If the console is closing before you've time to read the output, I'd try inserting the highlighted lines towards the end of the main() function in test.c:
If that's the case then you'll need to do more to the IL than just adding an .export directive (ilasm 2.0 does most of this for you). I've highlighted all the lines that need inserting:
sridevi pcPosted Nov 30, 2012, 8:32 AM
VulpesPosted Nov 30, 2012, 7:48 AM
If that's the case, then it's OK to remove 'static' before 'class' but you must leave it in for the Multiply method itself.
Vithal WadjePosted Nov 30, 2012, 7:46 AM
sridevi pcPosted Nov 30, 2012, 7:43 AM
sridevi pcPosted Nov 30, 2012, 7:41 AM
sridevi pcPosted Nov 30, 2012, 7:40 AM
Thanks for the reply
when i try to do step to am getting errorr message "
multiply.cs(3,21): error CS0106: The modifier 'static' is not valid for this
item "
csc /t:library multiply.cs
should i make Multiply function as non staticVulpesPosted Nov 30, 2012, 7:25 AM
Vithal WadjePosted Nov 30, 2012, 6:58 AM