473,327 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

How to create a DLL that can be called from another Win32 appl.

Hi all,

I am new to C#, .NET and Visual Studio but I have been coding professionally
for more than 10 years, so I am not a complete newbe :-)

At my work we are now in the process of switching from Borland Delphi to
Visual Studio and C#.
We have a lot of applications that we do not have time to recode to .NET, so
we are planning to do all "new" developments in C#.
And this is where my question pop up:

I need to create a new Database Search form for one of our apps. and I would
like to do this in C#, so that later developments in .Net can reuse this.

How can I create a DLL that can open a WinForm and return a string (as soon
as I got this in place, I can start doing real stuff :-))
Another Win32 (un-managed) appl. should use this DLL.

Since this is my first C# project, I need information about all the steps
necessary to do this.

I hope you are able to provide me with guidelines and if possible some
samples.

Thank you very much in advance

/Claus
Oct 9 '06 #1
8 1738
Claus a écrit :
I am new to C#, .NET and Visual Studio but I have been coding professionally
for more than 10 years, so I am not a complete newbe :-)

At my work we are now in the process of switching from Borland Delphi to
Visual Studio and C#.
We have a lot of applications that we do not have time to recode to .NET, so
we are planning to do all "new" developments in C#.
And this is where my question pop up:

I need to create a new Database Search form for one of our apps. and I would
like to do this in C#, so that later developments in .Net can reuse this.

How can I create a DLL that can open a WinForm and return a string (as soon
as I got this in place, I can start doing real stuff :-))
Another Win32 (un-managed) appl. should use this DLL.

Since this is my first C# project, I need information about all the steps
necessary to do this.

I hope you are able to provide me with guidelines and if possible some
samples.
Hi,

Basically, I think you cannot create DLLs in .NET in the usual sense.
What you create are called Assemblies (that are confusely named *.dll).
But you can use the libraries you create via COM (cf.
ComVisibleAttribute), which I hope can solve your problem here.

Mathieu
>
Oct 9 '06 #2
Hi Mathieu,

You can write a function inside the DLL that creates a new Form object and
then calls:

Objectname.Show();

Expose this function as a public function. You can add additional parameters
that you want to pass in the function definition and by returning a
collection type from the return clause you can receive strings et al.

Seek me if you want more help.
--
Radhakrishna Banavalikar
Vasant-Vihar, Thane, INDIA.
"Mathieu Cartoixa" wrote:
Claus a écrit :
I am new to C#, .NET and Visual Studio but I have been coding professionally
for more than 10 years, so I am not a complete newbe :-)

At my work we are now in the process of switching from Borland Delphi to
Visual Studio and C#.
We have a lot of applications that we do not have time to recode to .NET, so
we are planning to do all "new" developments in C#.
And this is where my question pop up:

I need to create a new Database Search form for one of our apps. and I would
like to do this in C#, so that later developments in .Net can reuse this.

How can I create a DLL that can open a WinForm and return a string (as soon
as I got this in place, I can start doing real stuff :-))
Another Win32 (un-managed) appl. should use this DLL.

Since this is my first C# project, I need information about all the steps
necessary to do this.

I hope you are able to provide me with guidelines and if possible some
samples.

Hi,

Basically, I think you cannot create DLLs in .NET in the usual sense.
What you create are called Assemblies (that are confusely named *.dll).
But you can use the libraries you create via COM (cf.
ComVisibleAttribute), which I hope can solve your problem here.

Mathieu
Oct 9 '06 #3
Dear Radhakrishna ,

That is exactly what I am after :-) I got this code working (see buttom):

But I would like to create a new Form1, and design with all necessary
components and code.

What are the tasks to compile multible sourcefiles (class1.cs and form1.cs)
and strongname these, to be able to call from un-managed code?

* For startes: how do I compile Class1.cs AND Form1.cs into TestDLL.dll from
the command line?
Thank you for your help

/Claus
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.ComponentModel;
using System.Text;

namespace TestDLL
{
public interface MyInterface
{
void myMethod1();
void myMethod2(string msg);
void myShowForm();
}

[ClassInterface(ClassInterfaceType.None)]
public class MyClass : MyInterface
{
public MyClass()
{
}

public void myMethod1()
{
MessageBox.Show("Hello World... Calling from C#");
}

public void myMethod2(string msg)
{
MessageBox.Show(msg);
}

public void myShowForm()
{
Form myForm = new Form();
myForm.Show();
}
}
}



"Radhakrishna Banavalikar"
<Ra*********************@discussions.microsoft.com wrote in message
news:66**********************************@microsof t.com...
Hi Mathieu,

You can write a function inside the DLL that creates a new Form object and
then calls:

Objectname.Show();

Expose this function as a public function. You can add additional
parameters
that you want to pass in the function definition and by returning a
collection type from the return clause you can receive strings et al.

Seek me if you want more help.
--
Radhakrishna Banavalikar
Vasant-Vihar, Thane, INDIA.
"Mathieu Cartoixa" wrote:
Claus a écrit :
I am new to C#, .NET and Visual Studio but I have been coding
professionally
for more than 10 years, so I am not a complete newbe :-)
>
At my work we are now in the process of switching from Borland Delphi
to
Visual Studio and C#.
We have a lot of applications that we do not have time to recode to
..NET, so
we are planning to do all "new" developments in C#.
And this is where my question pop up:
>
I need to create a new Database Search form for one of our apps. and I
would
like to do this in C#, so that later developments in .Net can reuse
this.
>
How can I create a DLL that can open a WinForm and return a string (as
soon
as I got this in place, I can start doing real stuff :-))
Another Win32 (un-managed) appl. should use this DLL.
>
Since this is my first C# project, I need information about all the
steps
necessary to do this.
>
>
>
I hope you are able to provide me with guidelines and if possible some
samples.
Hi,

Basically, I think you cannot create DLLs in .NET in the usual sense.
What you create are called Assemblies (that are confusely named *.dll).
But you can use the libraries you create via COM (cf.
ComVisibleAttribute), which I hope can solve your problem here.

Mathieu
>

Oct 9 '06 #4
Claus wrote:
At my work we are now in the process of switching from Borland Delphi to
Visual Studio and C#.
We're also doing this, but I can't imagine any GOOD WAY to call .NET
Windows forms or dialogs from a Delphi Win32 application. This would
require hosting the CLR inside your Win32 process and this can get
nasty quick.

We've separated our visual components by platforms and we don't re-use
them between Delphi and C#. But we have a lot of middle tier Delphi
business components where
we added a COM interface to them so we can call them from C# (we just
use a RemoteDataModule on the Delphi side).

Conversely, we also have some new C# business objects that we surface
to COM+ by descending from ServicedComponent. Then Delphi can easily
call them.

We also make calls across servers and we're using a customized version
of Borland's Socket Server to do this. This lets us marshal the COM
calls over a TCP/IP socket, and it also provides for round-robin load
balancing. We also added some functionality Borland had in their legacy
OleEnterprise product that lets us control which servers are allowed to
"export" which components - this allows dynamic reconfiguration without
bringing anything down.

We also use both Delphi and C# in web applications, both legacy ASP and
ASP.NET. Again, COM is the key to easy interop. You could look into
p-invoke for a faster way to call a Delphi DLL from C#, but it's going
to be a lot more work that way. But this is only for non-visual middle
tier objects.

Eric

Oct 9 '06 #5
Claus,

So you might want to take a look of this as well:
http://support.microsoft.com/kb/815780/

chanmm

"Claus" <ctb@nospam_barth.dkwrote in message
news:eh**************@TK2MSFTNGP04.phx.gbl...
Dear Radhakrishna ,

That is exactly what I am after :-) I got this code working (see
buttom):

But I would like to create a new Form1, and design with all necessary
components and code.

What are the tasks to compile multible sourcefiles (class1.cs and
form1.cs)
and strongname these, to be able to call from un-managed code?

* For startes: how do I compile Class1.cs AND Form1.cs into TestDLL.dll
from
the command line?
Thank you for your help

/Claus
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.ComponentModel;
using System.Text;

namespace TestDLL
{
public interface MyInterface
{
void myMethod1();
void myMethod2(string msg);
void myShowForm();
}

[ClassInterface(ClassInterfaceType.None)]
public class MyClass : MyInterface
{
public MyClass()
{
}

public void myMethod1()
{
MessageBox.Show("Hello World... Calling from C#");
}

public void myMethod2(string msg)
{
MessageBox.Show(msg);
}

public void myShowForm()
{
Form myForm = new Form();
myForm.Show();
}
}
}



"Radhakrishna Banavalikar"
<Ra*********************@discussions.microsoft.com wrote in message
news:66**********************************@microsof t.com...
>Hi Mathieu,

You can write a function inside the DLL that creates a new Form object
and
then calls:

Objectname.Show();

Expose this function as a public function. You can add additional
parameters
>that you want to pass in the function definition and by returning a
collection type from the return clause you can receive strings et al.

Seek me if you want more help.
--
Radhakrishna Banavalikar
Vasant-Vihar, Thane, INDIA.
"Mathieu Cartoixa" wrote:
Claus a écrit :
I am new to C#, .NET and Visual Studio but I have been coding
professionally
for more than 10 years, so I am not a complete newbe :-)

At my work we are now in the process of switching from Borland Delphi
to
Visual Studio and C#.
We have a lot of applications that we do not have time to recode to
.NET, so
we are planning to do all "new" developments in C#.
And this is where my question pop up:

I need to create a new Database Search form for one of our apps. and
I
would
like to do this in C#, so that later developments in .Net can reuse
this.
>
How can I create a DLL that can open a WinForm and return a string
(as
soon
as I got this in place, I can start doing real stuff :-))
Another Win32 (un-managed) appl. should use this DLL.

Since this is my first C# project, I need information about all the
steps
necessary to do this.

I hope you are able to provide me with guidelines and if possible
some
samples.

Hi,

Basically, I think you cannot create DLLs in .NET in the usual sense.
What you create are called Assemblies (that are confusely named *.dll).
But you can use the libraries you create via COM (cf.
ComVisibleAttribute), which I hope can solve your problem here.

Mathieu



Oct 9 '06 #6
Chanmm,

Thank you for the link. I'll give it a look :-)

/Claus

"chanmm" <ch*****@hotmail.comwrote in message
news:e7**************@TK2MSFTNGP02.phx.gbl...
Claus,

So you might want to take a look of this as well:
http://support.microsoft.com/kb/815780/

chanmm

"Claus" <ctb@nospam_barth.dkwrote in message
news:eh**************@TK2MSFTNGP04.phx.gbl...
Dear Radhakrishna ,

That is exactly what I am after :-) I got this code working (see
buttom):

But I would like to create a new Form1, and design with all necessary
components and code.

What are the tasks to compile multible sourcefiles (class1.cs and
form1.cs)
and strongname these, to be able to call from un-managed code?

* For startes: how do I compile Class1.cs AND Form1.cs into TestDLL.dll
from
the command line?
Thank you for your help

/Claus
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.ComponentModel;
using System.Text;

namespace TestDLL
{
public interface MyInterface
{
void myMethod1();
void myMethod2(string msg);
void myShowForm();
}

[ClassInterface(ClassInterfaceType.None)]
public class MyClass : MyInterface
{
public MyClass()
{
}

public void myMethod1()
{
MessageBox.Show("Hello World... Calling from C#");
}

public void myMethod2(string msg)
{
MessageBox.Show(msg);
}

public void myShowForm()
{
Form myForm = new Form();
myForm.Show();
}
}
}



"Radhakrishna Banavalikar"
<Ra*********************@discussions.microsoft.com wrote in message
news:66**********************************@microsof t.com...
Hi Mathieu,

You can write a function inside the DLL that creates a new Form object
and
then calls:

Objectname.Show();

Expose this function as a public function. You can add additional
parameters
that you want to pass in the function definition and by returning a
collection type from the return clause you can receive strings et al.

Seek me if you want more help.
--
Radhakrishna Banavalikar
Vasant-Vihar, Thane, INDIA.
"Mathieu Cartoixa" wrote:

Claus a écrit :
I am new to C#, .NET and Visual Studio but I have been coding
professionally
for more than 10 years, so I am not a complete newbe :-)
>
At my work we are now in the process of switching from Borland
Delphi
to
Visual Studio and C#.
We have a lot of applications that we do not have time to recode to
.NET, so
we are planning to do all "new" developments in C#.
And this is where my question pop up:
>
I need to create a new Database Search form for one of our apps.
and
I
would
like to do this in C#, so that later developments in .Net can reuse
this.
>
How can I create a DLL that can open a WinForm and return a string
(as
soon
as I got this in place, I can start doing real stuff :-))
Another Win32 (un-managed) appl. should use this DLL.
>
Since this is my first C# project, I need information about all the
steps
necessary to do this.
>
>
>
I hope you are able to provide me with guidelines and if possible
some
samples.

Hi,

Basically, I think you cannot create DLLs in .NET in the usual sense.
What you create are called Assemblies (that are confusely named
*.dll).
But you can use the libraries you create via COM (cf.
ComVisibleAttribute), which I hope can solve your problem here.

Mathieu
>


Oct 13 '06 #7
Eric,

The reason I would like to call the WinForms from Delphi is just to prepare
ourselfes for C#.
This way I "believe" (read: I hope) I can avoid coding the same dialog again
when the shift to C# is complete.
Then I can just keep using the same dialog...

Thank you for your thoughts. I will read them through again and investigate
your recommendations
Best

/Claus

"Eric" <en*********@yahoo.comwrote in message
news:11*********************@m7g2000cwm.googlegrou ps.com...
Claus wrote:
At my work we are now in the process of switching from Borland Delphi to
Visual Studio and C#.

We're also doing this, but I can't imagine any GOOD WAY to call .NET
Windows forms or dialogs from a Delphi Win32 application. This would
require hosting the CLR inside your Win32 process and this can get
nasty quick.

We've separated our visual components by platforms and we don't re-use
them between Delphi and C#. But we have a lot of middle tier Delphi
business components where
we added a COM interface to them so we can call them from C# (we just
use a RemoteDataModule on the Delphi side).

Conversely, we also have some new C# business objects that we surface
to COM+ by descending from ServicedComponent. Then Delphi can easily
call them.

We also make calls across servers and we're using a customized version
of Borland's Socket Server to do this. This lets us marshal the COM
calls over a TCP/IP socket, and it also provides for round-robin load
balancing. We also added some functionality Borland had in their legacy
OleEnterprise product that lets us control which servers are allowed to
"export" which components - this allows dynamic reconfiguration without
bringing anything down.

We also use both Delphi and C# in web applications, both legacy ASP and
ASP.NET. Again, COM is the key to easy interop. You could look into
p-invoke for a faster way to call a Delphi DLL from C#, but it's going
to be a lot more work that way. But this is only for non-visual middle
tier objects.

Eric

Oct 13 '06 #8
Claus wrote:
The reason I would like to call the WinForms from Delphi is just to prepare
ourselfes for C#.
This way I "believe" (read: I hope) I can avoid coding the same dialog again
when the shift to C# is complete.
Then I can just keep using the same dialog...
I don't think you can do this easily. The pain would exceed the gain.

C# is a lot like Delphi when it comes to Windows Forms, so it's not
terribly difficult to re-do your GUI apps. After all, it still comes
down to the basic Windows controls that haven't changed much over the
last 5 years (or more). The VCL wrappers are a little different that
the C# wrappers, but Intellisense is a big help in VS.

The biggest difference on the GUI side is the databinding control issue
- Delphi makes it terribly easy to wire up visual controls to a live
datasource. This model is entirely different in C# because ADO.NET only
uses a disconnected model. You have to learn how to do databinding all
over again, and it's more complex than you might think. But it's also
more flexible in the long run. If you are a big user of Delphi
TDBGrids, you should spend a few days (or weeks) with the .NET grids
and ADO.NET to ensure that you understand them well before going too
far. I had to do a certain amount of re-work in the early days of my
conversion to C# becuase I didn't have a clear understanding of the
model going into it.

If you have a budget for it, and you have a lot of Delphi GUI apps to
port to C#, it might be a good idea to hire a consultant who's an
expert on Windows Forms. He can save you a lot of trouble and
heartache, and you may only need him for a couple months for training
purposes. With all the buzz about ASP.NET it can be difficult to find
an expert on Windows Forms, and it can be frustrating for you if you
don't have someone who can SHOW you how it's done in .NET.

Once you get your mind around the OOP classes it's actually very
flexible. And in 2.0 you can bind controls to data classes, and that's
pretty cool (something Delphi could never do).

Another option is to refactor your code so there's not much actual
processing in any of the GUI elements. If you move meaty processing to
middle tier COM DLLs, those can be re-used by C# pretty easily, without
a need to re-code them.

Our strategy is to port apps from Delphi to C# if a "significant"
amount of work is needed on a Delphi app. But if the Delphi app only
needs a minor bug fix, we just leave it in Delphi. Almost all new apps
are being done in C# unless it has to interop with Delphi components in
an advanced way.

Eric

Oct 13 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: RL | last post by:
Hello Perl gurus, 1. I have a web page where I can push a button (dospawn.html). 2. This button calls a CGI script (spawnboss.cgi) 3. spawnboss.cgi calls a forking perl script (forkme.pl) 4....
8
by: Pola | last post by:
Please Help I am using VC++ in win 2000 In my appl (Win32 project) I want to control the close operation of the apl (for example if somebody will try to close appl from the "Windows Task Manager")...
15
by: Viviana Vc | last post by:
How can I programatically do the equivalent of the following: cacls "C:\Program Files\test" /T /G Everyone:f ? Thanks, Viv
6
by: Alpha | last post by:
Hi, I'm fixing a bug in an application and need to step thru the appl to find where it's occuring. The main project includs 33 other projects each having a .resx file in it. When I step through it...
5
by: Michael Sperlle | last post by:
Is it possible? Bestcrypt can supposedly be set up on linux, but it seems to need changes to the kernel before it can be installed, and I have no intention of going through whatever hell that would...
1
by: Jorge Luzarraga Castro | last post by:
Helloo, I´ve got a ASP .Net application which writes to the event viewer whenever it finds a error. This appl needs to create a new section in the event viewer the first time it encounters any...
1
by: stoj | last post by:
I have a smallish C# application that i wish to distribute as a standalone executable (ie. without installer or other support files). Easy enough if everyone has .Net Framework 2.0 installed as...
0
by: bughunter | last post by:
I found code from java - real bug with secondary parameter, should be Integer but called with String, But procedure completed without any errors and parameter correctly transformed to integer! ...
15
by: kid joe | last post by:
Hi, Is it possible to use inline asm to make intrrupt calls in Win32 appl. for reading some hardware information such as reading port's status register, etc? Any restrictions or Impossible? I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.