www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to I call D code from C# Project?

reply "GoD" <goren.ali yandex.com> writes:
Hi.

I want use my D code in C#

How can I do this?

D, very fast programming language. But I can not WinForm 
applications from D. I'm using C# for WinForm applications. But, 
also i want to use D code for my project.

for example;

I'm see PC information with D lang.

Example Code(Suppose that D):

PCInformation //D LANG CODE
{
   showHDDSerialNumber();
   showCPUsage();
   showMACAdress();
   showFooBar();

}

Example Code(Suppose that C#):

using namespace DCODE; // DCODE Library written it D Lang

WinFormApp
{
     PCInformation pin = new PCInformation(); // D code import
     Label1.Text = pin.ShowHDDSerialNumber(); // D code import
}

How can I do this?

Sorry for my bad english :(

Thank you :)
Jun 18 2014
next sibling parent reply "Jesse Phillips" <Jesse.K.Phillips+D gmail.com> writes:
On Wednesday, 18 June 2014 at 20:55:09 UTC, GoD wrote:
 Hi.

 I want use my D code in C#

 How can I do this?
My plan was to use COM. I've not actually implemented such communication. Juno provides some items: https://github.com/JesseKPhillips/Juno-Windows-Class-Library/ But I haven't done a update for latest compiler and as I said, haven't created a real project with it. (Got annoyed with MS security in an example I was working on)
Jun 18 2014
parent reply "GoD" <goren.ali yandex.com> writes:
 Jesse

How to use in C# projects?
Jun 18 2014
parent reply "Jesse Phillips" <Jesse.K.Phillips+D gmail.com> writes:
On Wednesday, 18 June 2014 at 23:41:43 UTC, GoD wrote:
  Jesse

 How to use in C# projects?
You'll have to access it through a COM interface on the C# side. http://msdn.microsoft.com/en-us/library/aa645736%28v=vs.71%29.aspx If you haven't done work in COM before its a lot of new things to learn. C# should also have interfacing with C, so you can have D expose a C interface. Sorry I can't walk you through working examples. As mentioned, I haven't gotten that far myself.
Jun 18 2014
parent "Binarydepth" <binarydepth gmail.com> writes:
On Thursday, 19 June 2014 at 04:07:30 UTC, Jesse Phillips wrote:
 On Wednesday, 18 June 2014 at 23:41:43 UTC, GoD wrote:
  Jesse

 How to use in C# projects?
You'll have to access it through a COM interface on the C# side. http://msdn.microsoft.com/en-us/library/aa645736%28v=vs.71%29.aspx If you haven't done work in COM before its a lot of new things to learn. C# should also have interfacing with C, so you can have D expose a C interface. Sorry I can't walk you through working examples. As mentioned, I haven't gotten that far myself.
That sounds legit.
Jun 25 2014
prev sibling next sibling parent "Andre Artus" <andre.artus gmail.com> writes:
On Wednesday, 18 June 2014 at 20:55:09 UTC, GoD wrote:
 Hi.

 I want use my D code in C#

 How can I do this?

 D, very fast programming language. But I can not WinForm 
 applications from D. I'm using C# for WinForm applications. 
 But, also i want to use D code for my project.

 for example;

 I'm see PC information with D lang.

 Example Code(Suppose that D):

 PCInformation //D LANG CODE
 {
   showHDDSerialNumber();
   showCPUsage();
   showMACAdress();
   showFooBar();

 }

 Example Code(Suppose that C#):

 using namespace DCODE; // DCODE Library written it D Lang

 WinFormApp
 {
     PCInformation pin = new PCInformation(); // D code import
     Label1.Text = pin.ShowHDDSerialNumber(); // D code import
 }

 How can I do this?

 Sorry for my bad english :(

 Thank you :)
You could write a DLL un D, and call that from C# with PInvoke. http://wiki.dlang.org/Win32_DLLs_in_D http://msdn.microsoft.com/en-us/library/aa288468(v=vs.71).aspx
Jun 19 2014
prev sibling parent reply "Kagamin" <spam here.lot> writes:
On Wednesday, 18 June 2014 at 20:55:09 UTC, GoD wrote:
 D, very fast programming language. But I can not WinForm 
 applications from D. I'm using C# for WinForm applications.
DWT and TkD didn't work for you?
Jun 19 2014
next sibling parent "SomeRiz" <goren.ali yandex.com> writes:
I know it but I can not do without the drag-and-drop. (Design 
etc..)
Jun 19 2014
prev sibling parent "FrankLike" <1150015857 qq.com> writes:
On Thursday, 19 June 2014 at 13:59:25 UTC, Kagamin wrote:
 On Wednesday, 18 June 2014 at 20:55:09 UTC, GoD wrote:
 D, very fast programming language. But I can not WinForm 
 applications from D. I'm using C# for WinForm applications.
DWT and TkD didn't work for you?
Can you give us some Design tools on windows for DWT? Thank you.
Jun 25 2014