473,657 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1749
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.
ComVisibleAttri bute), 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.
ComVisibleAttri bute), 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.Reflecti on;
using System.Runtime. InteropServices ;
using System.Windows. Forms;
using System.Componen tModel;
using System.Text;

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

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

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

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

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



"Radhakrish na Banavalikar"
<Ra************ *********@discu ssions.microsof t.comwrote in message
news:66******** *************** ***********@mic rosoft.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.
ComVisibleAttri bute), 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 RemoteDataModul e on the Delphi side).

Conversely, we also have some new C# business objects that we surface
to COM+ by descending from ServicedCompone nt. 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_bar th.dkwrote in message
news:eh******** ******@TK2MSFTN GP04.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.Reflecti on;
using System.Runtime. InteropServices ;
using System.Windows. Forms;
using System.Componen tModel;
using System.Text;

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

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

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

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

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



"Radhakrish na Banavalikar"
<Ra************ *********@discu ssions.microsof t.comwrote in message
news:66******** *************** ***********@mic rosoft.com...
>Hi Mathieu,

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

Objectname.Sho w();

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.
ComVisibleAttri bute), 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*****@hotmai l.comwrote in message
news:e7******** ******@TK2MSFTN GP02.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_bar th.dkwrote in message
news:eh******** ******@TK2MSFTN GP04.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.Reflecti on;
using System.Runtime. InteropServices ;
using System.Windows. Forms;
using System.Componen tModel;
using System.Text;

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

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

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

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

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



"Radhakrish na Banavalikar"
<Ra************ *********@discu ssions.microsof t.comwrote in message
news:66******** *************** ***********@mic rosoft.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.
ComVisibleAttri bute), 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*********@ya hoo.comwrote in message
news:11******** *************@m 7g2000cwm.googl egroups.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 RemoteDataModul e on the Delphi side).

Conversely, we also have some new C# business objects that we surface
to COM+ by descending from ServicedCompone nt. 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 "significan t"
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
4984
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. forkme.pl calls the process creation script (createme.pl) 5. createme.pl creates my notepad.exe process, but no window shows up on my PC. The result on my web browser is:
8
2577
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") I want to know in my appl what message to expect from "Task Manager", when user will try to close my appl from the "Windows Task Manager". what message should I get in my appl thank you Pola
15
3309
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
1624
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 would give me message that it can't show me codes because only assembly codes are available. Is there any good article on how to debug something like this? Also, I've only being working with C#.net for 3 months and am still not very familiar...
5
6765
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 cause. If I could create a large file that could be encrypted, and maybe add files to it by appending them and putting in some kind of delimiter between files, maybe a homemade version of truecrypt could be constructed. Any idea what it...
1
2869
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 error. For doing so it needs Administrator privileges to create that section, so far everythings is working ok. The issue raises because the guys from security do not accept this situation. Is there any way to manually create that section in the...
1
1656
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 it's a simple question of file copy/mail/web-publish/etc. The problem is when the application is run by someone who doesn't have .Net installed, it exits without any visible error (except for an obsecure entry in the event log). Needless to say,...
0
2634
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! Is't bug or "feature"? Is that documented? Because SQL0301N
15
3261
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 need to talk to the LPT port directly in Win98/SE, or at least need to get current status of the port(printer). - Paper out, power off, etc. Any information will be appreciated.
0
8413
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8740
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8513
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7352
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1733
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.