Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > .NET

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 05-05-2008, 04:24 AM
ZarrinPour ZarrinPour is offline
Senior Member
 
Join Date: Jul 2003
Posts: 232
Default How to Write DLL for C#.NET with Delphi 7

Hi all
Currently i'm familiar with writing dll in delphi(i'm using
delphi 7) But i couldn't import my dll to my C# projects.
So could anyone tell me how to i should write my DLL in a way that is accessible by .Net Languages?

Kind Regards.
Reply With Quote
  #2  
Old 05-05-2008, 04:32 AM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,333
Default RE: How to Write DLL for C#.NET with Delphi 7

Is it a "normal" or an activeX dll??? A normal dll should be importable, the activex I don't think is...

But I would recommend writing your dll's in C# aswell. You can choose to compile it for the win32 platform or the .NET. The other way around I doubt is possible, but perhaps I'm wrong. And even if it's possible I doubt it's possible using D7, because it has no .NET support what so ever...

Objective reality is a delirium caused by lack of alcohol in blood.
There is no place like 127.0.0.1
Reply With Quote
  #3  
Old 05-05-2008, 05:09 AM
mshkolnik mshkolnik is offline
Senior Member
 
Join Date: Jul 2001
Posts: 4,195
Default RE: How to Write DLL for C#.NET with Delphi 7

Why you can't import your dll in C#? Did you get some error message?

I use a few own dll from Delphi 5/7 in C# without any problems.

With best regards, Mike Shkolnik
http://www.scalabium.com
Reply With Quote
  #4  
Old 05-05-2008, 05:10 AM
mshkolnik mshkolnik is offline
Senior Member
 
Join Date: Jul 2001
Posts: 4,195
Default RE: How to Write DLL for C#.NET with Delphi 7

ActiveX which is created in Delphi 7 can be referenced in C# without any problem too and VS IDE will show the list of published interfaces/methods/parameters etc

With best regards, Mike Shkolnik
http://www.scalabium.com
Reply With Quote
  #5  
Old 05-05-2008, 05:12 AM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,333
Default RE: How to Write DLL for C#.NET with Delphi 7

Thank you, learned something new then...
Tonight I'll try to figure out how, because now I'm curious

Objective reality is a delirium caused by lack of alcohol in blood.
There is no place like 127.0.0.1
Reply With Quote
  #6  
Old 05-05-2008, 10:37 AM
ZarrinPour ZarrinPour is offline
Senior Member
 
Join Date: Jul 2003
Posts: 232
Default RE: How to Write DLL for C#.NET with Delphi 7

Hi mshkolnik
Thanks for ur reply
To tell yoy the truth i tried to import a simple Dll
before importing my main dll , a simple dll like follow:

Code:
library Project2;

uses
  SysUtils,
  Classes,
  Dialogs;

{$R *.res}


procedure Test; export;
begin
  ShowMessage('Hello From Delphi Dll');
end;

exports Test;

begin
end.
But when i tried to import it to Visual Studio and [Add Reference] it to my C# project i received an error message
but i couldn't remember the error message right now because at the moment i don't have access to my laptop.

could you please send me a simple DLL with Delphi 7 (source code) that , it is imported successfully.?

Thanks in advance.
Kind Regards.
Reply With Quote
  #7  
Old 05-05-2008, 11:01 PM
mshkolnik mshkolnik is offline
Senior Member
 
Join Date: Jul 2001
Posts: 4,195
Default RE: How to Write DLL for C#.NET with Delphi 7

Your code for dll is absolutely correct.
To use this dll from C# you need declare the exported function:

Imports System.Runtime.InteropServices

Public Class DelphiDll
Declare Auto Function Test Lib "Project2.dll" _
As IntPtr
End Class

Public Class HelloWorld
Public Shared Sub Main()
DelphiDll.Test
End Sub
End Class

See the link:
http://msdn.microsoft.com/en-us/library/42b9ea93.aspx

As alternative (better to use in C#) you need use the [DllImport...] directive. See MSDN for documentation.

PS: to add the dll in references and see the list of functions, you need add the ActiveX in your dll as I wrote in my first reply. This is a different kind of dll - dll with ActiveX control.


With best regards, Mike Shkolnik
http://www.scalabium.com
Reply With Quote
  #8  
Old 05-06-2008, 04:22 AM
BitFarmer BitFarmer is offline
Senior Member
 
Join Date: Feb 2008
Posts: 160
Default RE: How to Write DLL for C#.NET with Delphi 7

May be I am not rigth, but shouldn't it use a stdcall in the dll function in order to assure it will do it as other languajes expect? May be it is already using it by default, just a thought!
Reply With Quote
  #9  
Old 05-07-2008, 09:32 AM
ZarrinPour ZarrinPour is offline
Senior Member
 
Join Date: Jul 2003
Posts: 232
Default RE: How to Write DLL for C#.NET with Delphi 7

Hi mshkolnik
I lack the words with which to express my thanks.
now i've learnt a new thing in programming.
Thanks a million!!!.
Reply With Quote
  #10  
Old 05-07-2008, 09:41 AM
ZarrinPour ZarrinPour is offline
Senior Member
 
Join Date: Jul 2003
Posts: 232
Default RE: How to Write DLL for C#.NET with Delphi 7

Hi again
Just one more question!!!
as you mentioned earlier :

PS: to add the dll in references and see the list of functions, you need add the ActiveX in your dll as I wrote in my first reply. This is a different kind of dll - dll with ActiveX control.

... so what do you mean? i added the Activex Unit in my USES clause in in my delphi Dll unit and then compiled it But still i receive the error at importing:

---------------------------
Microsoft Development Environment
---------------------------
A reference to 'C:\Documents and Settings\....\Project1.dll' could not be added. This is not a valid assembly or COM component. Only assemblies with extension 'dll' and COM components can be referenced. Please make sure that the file is accessible, and that it is a valid assembly or COM component.
---------------------------
OK
---------------------------

Kind Regards.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:42 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.