C# Dll Question

  • Thread starter Thread starter glenn
  • Start date Start date
G

glenn

I understand that C# does not generate dll's that can be called from other
application development platforms. So now I have to find another way to
write a client app that can be utilized within another environment and am
thinking about COM. Can anyone point me to a tutorial or advise me on where
to get started. I have a security component that use to be a dll that I
want to try rewriting in C# as a test to prove whether or not we can start
to utilize C# for some of our solutions.

Can anyone help me?

Thanks,

glenn
 
glenn said:
I understand that C# does not generate dll's that can be called from other
application development platforms.

Huh? What exactly do you mean by "application development platforms"? If you
mean other languages, well all the .NET languages can interoperate with C#
seamlessly. If you mean things like COM applications, then C# can expose COM
interfaces (look up ComVisible). If you mean other operating systems then C#
can expose Web Services.
 
Well, we have been using Borland Delphi for the last 10 years. We are now
looking at the possibility of converting our application to C# and its my
job to see if this is something that can be done. In order to try to prove
my case, I wanted to rewrite a few of the dll's we have in delphi into C#
because they could be rewritten and replaced tomorrow and no one would be
the wiser. However, when I try to develop a dll in c# and then call that
dll from a delphi app, I get access violations when Delphi tries loading the
dll. Long before any functions are actually called.

I can find absolutely nothing so far to help me with this as all examples
have been between c# and c# with not even a mention that there might be
other program languages that exist.

Thanks,

glenn
 
You are jumping the gun here. I have never programmed in Borland Delphi
but I would certainly think unless they are going to support .net
framework, its unmanaged code.

That means if you write the same functionality in C#, you will need to
expose the components thru COM. However, I have no idea if Borland
Delphi can deal with a COM server. If it can, then on your existing
codebase, you will need to use COM to communicate with your newly
written C# component.
 
Ok,

Which leads to the original question. Delphi does support COM 100% as well
as DLL's but since c# does not support the old DLL processes which you seem
to have just confirmed, then COM is my only choice. So back to my original
question. How can I learn how to write a COM server in C#? I know how to
do this and have done it many times in Delphi but out of the 3000 pages of
text I have in 4 different c# books, not one single one even mentions COM.
Did Microsoft Rename the technology again? Is there somewhere I can go to
learn how to write a COM Server? I've been googling all morning and so far
have gotten no where.

Thanks,

glenn
 
Before you jump into this, you should make certain that if Delphi is
going to support .Net. If it is or is going to, it will be all mute
point as you can develop in C# or whatever to produce managed code and
consue it in Delphi.

If Delphi is not going to support managed code, then you will need to
write a COM server in managed code. The link I provided in my first
reply shows how to do it(ComVisible attribute).
since c# does not support the old DLL processes which you seem
to have just confirmed,

I am not what you mean here. You can call unmanaged DLLs using
interop/PInvoke in managed code(C#). That means your Delphi code
(whatever is exported by it) can be used in a managed code. If you have
a COM server in Delphi, you can use it in C#.
 
I understand but you are backwards. I am trying to write a dll in C#
(managed code) and call that dll from Delphi 6 which is unmanaged. Delphi
2005 supports all the .NET stuff but our project is currently being managed
in Delphi 6 which does not.

So to recap. I want to write a dll in C# that performs a function that just
pops up a message box and says hello world. I then want to call that
function from inside my delphi application so that the message box pops up.

I'm also behind the times a little with all this managed code stuff so I'm
not sure what the differences are from what managed and unmanaged code
exactly means.

Thanks,

glenn
 
I am trying to write a dll in C# (managed code) and call that dll from
Delphi 6 which is unmanaged.

What I said earlier about exposing functionality in C# thru COM still
applies. Thats because Delphi 6 is unmanaged and you need some sort of
common layer (COM in this case) between two components.
I'm also behind the times a little with all this managed code stuff so I'm
not sure what the differences are from what managed and unmanaged code
exactly means.

There is a lot of difference between the two. If you have familiarity
with Java, it will be easy to migrate over.

I still believe your best bet is to use Delphi 2005 if it supports .Net
and unmangaged code in the same component. You need to find this out
before deciding about how to proceed.
 
In your C# DLL do the following:

AssemblyInfo.cs
----------------
[assembly: ComVisible(true)]

Then, right-click on the project in the Solution Explorer, select
Properties, choose Configuration Properties\Build, and set "Register for COM
Interop" to "True".

Now when you build your project it will make it COM-compatible and register
it on your machine. You should now be able to reference the C# library in
your Delphi code.

glenn said:
I understand but you are backwards. I am trying to write a dll in C#
(managed code) and call that dll from Delphi 6 which is unmanaged. Delphi
2005 supports all the .NET stuff but our project is currently being
managed
in Delphi 6 which does not.

So to recap. I want to write a dll in C# that performs a function that
just
pops up a message box and says hello world. I then want to call that
function from inside my delphi application so that the message box pops
up.

I'm also behind the times a little with all this managed code stuff so I'm
not sure what the differences are from what managed and unmanaged code
exactly means.

Thanks,

glenn
 
Thank you very much. That was what I was after....

glenn
Sean Hederman said:
In your C# DLL do the following:

AssemblyInfo.cs
----------------
[assembly: ComVisible(true)]

Then, right-click on the project in the Solution Explorer, select
Properties, choose Configuration Properties\Build, and set "Register for COM
Interop" to "True".

Now when you build your project it will make it COM-compatible and register
it on your machine. You should now be able to reference the C# library in
your Delphi code.
 
Well what do I need to add to be able to do this. When adding the change to
the assemblyinfo unit I get The type or name "ComVisible" could not be
found.

Tried from windows solution and dll solution. both same results
Thanks,

glenn


Sean Hederman said:
In your C# DLL do the following:

AssemblyInfo.cs
----------------
[assembly: ComVisible(true)]

Then, right-click on the project in the Solution Explorer, select
Properties, choose Configuration Properties\Build, and set "Register for COM
Interop" to "True".

Now when you build your project it will make it COM-compatible and register
it on your machine. You should now be able to reference the C# library in
your Delphi code.
 
add a reference to System.Runtime.InteropServices in your AssemblyInfo.cs.
-sb

glenn said:
Well what do I need to add to be able to do this. When adding the change
to
the assemblyinfo unit I get The type or name "ComVisible" could not be
found.

Tried from windows solution and dll solution. both same results
Thanks,

glenn


Sean Hederman said:
In your C# DLL do the following:

AssemblyInfo.cs
----------------
[assembly: ComVisible(true)]

Then, right-click on the project in the Solution Explorer, select
Properties, choose Configuration Properties\Build, and set "Register for COM
Interop" to "True".

Now when you build your project it will make it COM-compatible and register
it on your machine. You should now be able to reference the C# library in
your Delphi code.

glenn said:
I understand but you are backwards. I am trying to write a dll in C#
(managed code) and call that dll from Delphi 6 which is unmanaged. Delphi
2005 supports all the .NET stuff but our project is currently being
managed
in Delphi 6 which does not.

So to recap. I want to write a dll in C# that performs a function that
just
pops up a message box and says hello world. I then want to call that
function from inside my delphi application so that the message box pops
up.

I'm also behind the times a little with all this managed code stuff so I'm
not sure what the differences are from what managed and unmanaged code
exactly means.

Thanks,

glenn

Before you jump into this, you should make certain that if Delphi is
going to support .Net. If it is or is going to, it will be all mute
point as you can develop in C# or whatever to produce managed code and
consue it in Delphi.

If Delphi is not going to support managed code, then you will need to
write a COM server in managed code. The link I provided in my first
reply shows how to do it(ComVisible attribute).

since c# does not support the old DLL processes which you seem
to have just confirmed,

I am not what you mean here. You can call unmanaged DLLs using
interop/PInvoke in managed code(C#). That means your Delphi code
(whatever is exported by it) can be used in a managed code. If you
have
a COM server in Delphi, you can use it in C#.
 
Thanks that did it...

glenn
SB said:
add a reference to System.Runtime.InteropServices in your AssemblyInfo.cs.
-sb

glenn said:
Well what do I need to add to be able to do this. When adding the change
to
the assemblyinfo unit I get The type or name "ComVisible" could not be
found.

Tried from windows solution and dll solution. both same results
Thanks,

glenn


Sean Hederman said:
In your C# DLL do the following:

AssemblyInfo.cs
----------------
[assembly: ComVisible(true)]

Then, right-click on the project in the Solution Explorer, select
Properties, choose Configuration Properties\Build, and set "Register
for
COM
Interop" to "True".

Now when you build your project it will make it COM-compatible and register
it on your machine. You should now be able to reference the C# library in
your Delphi code.

I understand but you are backwards. I am trying to write a dll in C#
(managed code) and call that dll from Delphi 6 which is unmanaged. Delphi
2005 supports all the .NET stuff but our project is currently being
managed
in Delphi 6 which does not.

So to recap. I want to write a dll in C# that performs a function that
just
pops up a message box and says hello world. I then want to call that
function from inside my delphi application so that the message box pops
up.

I'm also behind the times a little with all this managed code stuff
so
I'm
not sure what the differences are from what managed and unmanaged code
exactly means.

Thanks,

glenn

Before you jump into this, you should make certain that if Delphi is
going to support .Net. If it is or is going to, it will be all mute
point as you can develop in C# or whatever to produce managed code and
consue it in Delphi.

If Delphi is not going to support managed code, then you will need to
write a COM server in managed code. The link I provided in my first
reply shows how to do it(ComVisible attribute).

since c# does not support the old DLL processes which you seem
to have just confirmed,

I am not what you mean here. You can call unmanaged DLLs using
interop/PInvoke in managed code(C#). That means your Delphi code
(whatever is exported by it) can be used in a managed code. If you
have
a COM server in Delphi, you can use it in C#.
 
Sorry, while it will compile now, the Register for COM option is greyed out
and set to false. I can't change it to true... Am I missing something?

glenn
Sean Hederman said:
In your C# DLL do the following:

AssemblyInfo.cs
----------------
[assembly: ComVisible(true)]

Then, right-click on the project in the Solution Explorer, select
Properties, choose Configuration Properties\Build, and set "Register for COM
Interop" to "True".

Now when you build your project it will make it COM-compatible and register
it on your machine. You should now be able to reference the C# library in
your Delphi code.
 
glenn said:
Sorry, while it will compile now, the Register for COM option is greyed
out
and set to false. I can't change it to true... Am I missing something?

Weird, mine doesn't go off even when I change my project type to Console. Do
you have any public classes in your code. If you do I'm not sure what the
problem is, probably some obscure setting somewhere. Doesn't really matter
anyway, since all that option does is automatically run regasm on your
assembly for you, so you can just do that manually.
glenn
Sean Hederman said:
In your C# DLL do the following:

AssemblyInfo.cs
----------------
[assembly: ComVisible(true)]

Then, right-click on the project in the Solution Explorer, select
Properties, choose Configuration Properties\Build, and set "Register for COM
Interop" to "True".

Now when you build your project it will make it COM-compatible and register
it on your machine. You should now be able to reference the C# library in
your Delphi code.

glenn said:
I understand but you are backwards. I am trying to write a dll in C#
(managed code) and call that dll from Delphi 6 which is unmanaged. Delphi
2005 supports all the .NET stuff but our project is currently being
managed
in Delphi 6 which does not.

So to recap. I want to write a dll in C# that performs a function that
just
pops up a message box and says hello world. I then want to call that
function from inside my delphi application so that the message box pops
up.

I'm also behind the times a little with all this managed code stuff so I'm
not sure what the differences are from what managed and unmanaged code
exactly means.

Thanks,

glenn

Before you jump into this, you should make certain that if Delphi is
going to support .Net. If it is or is going to, it will be all mute
point as you can develop in C# or whatever to produce managed code and
consue it in Delphi.

If Delphi is not going to support managed code, then you will need to
write a COM server in managed code. The link I provided in my first
reply shows how to do it(ComVisible attribute).

since c# does not support the old DLL processes which you seem
to have just confirmed,

I am not what you mean here. You can call unmanaged DLLs using
interop/PInvoke in managed code(C#). That means your Delphi code
(whatever is exported by it) can be used in a managed code. If you
have
a COM server in Delphi, you can use it in C#.
 
Actually, I just created a brand new project and did what was said to do. I
haven't added or changed anything at this point...

thanks,

glenn

Sean Hederman said:
glenn said:
Sorry, while it will compile now, the Register for COM option is greyed
out
and set to false. I can't change it to true... Am I missing something?

Weird, mine doesn't go off even when I change my project type to Console. Do
you have any public classes in your code. If you do I'm not sure what the
problem is, probably some obscure setting somewhere. Doesn't really matter
anyway, since all that option does is automatically run regasm on your
assembly for you, so you can just do that manually.
glenn
Sean Hederman said:
In your C# DLL do the following:

AssemblyInfo.cs
----------------
[assembly: ComVisible(true)]

Then, right-click on the project in the Solution Explorer, select
Properties, choose Configuration Properties\Build, and set "Register
for
COM
Interop" to "True".

Now when you build your project it will make it COM-compatible and register
it on your machine. You should now be able to reference the C# library in
your Delphi code.

I understand but you are backwards. I am trying to write a dll in C#
(managed code) and call that dll from Delphi 6 which is unmanaged. Delphi
2005 supports all the .NET stuff but our project is currently being
managed
in Delphi 6 which does not.

So to recap. I want to write a dll in C# that performs a function that
just
pops up a message box and says hello world. I then want to call that
function from inside my delphi application so that the message box pops
up.

I'm also behind the times a little with all this managed code stuff
so
I'm
not sure what the differences are from what managed and unmanaged code
exactly means.

Thanks,

glenn

Before you jump into this, you should make certain that if Delphi is
going to support .Net. If it is or is going to, it will be all mute
point as you can develop in C# or whatever to produce managed code and
consue it in Delphi.

If Delphi is not going to support managed code, then you will need to
write a COM server in managed code. The link I provided in my first
reply shows how to do it(ComVisible attribute).

since c# does not support the old DLL processes which you seem
to have just confirmed,

I am not what you mean here. You can call unmanaged DLLs using
interop/PInvoke in managed code(C#). That means your Delphi code
(whatever is exported by it) can be used in a managed code. If you
have
a COM server in Delphi, you can use it in C#.
 
You need at least one public class, with a public default constructor, and
public methods.

glenn said:
Actually, I just created a brand new project and did what was said to do.
I
haven't added or changed anything at this point...

thanks,

glenn

Sean Hederman said:
glenn said:
Sorry, while it will compile now, the Register for COM option is greyed
out
and set to false. I can't change it to true... Am I missing
something?

Weird, mine doesn't go off even when I change my project type to Console. Do
you have any public classes in your code. If you do I'm not sure what the
problem is, probably some obscure setting somewhere. Doesn't really
matter
anyway, since all that option does is automatically run regasm on your
assembly for you, so you can just do that manually.
glenn
In your C# DLL do the following:

AssemblyInfo.cs
----------------
[assembly: ComVisible(true)]

Then, right-click on the project in the Solution Explorer, select
Properties, choose Configuration Properties\Build, and set "Register for
COM
Interop" to "True".

Now when you build your project it will make it COM-compatible and
register
it on your machine. You should now be able to reference the C# library in
your Delphi code.

I understand but you are backwards. I am trying to write a dll in C#
(managed code) and call that dll from Delphi 6 which is unmanaged.
Delphi
2005 supports all the .NET stuff but our project is currently being
managed
in Delphi 6 which does not.

So to recap. I want to write a dll in C# that performs a function that
just
pops up a message box and says hello world. I then want to call
that
function from inside my delphi application so that the message box pops
up.

I'm also behind the times a little with all this managed code stuff so
I'm
not sure what the differences are from what managed and unmanaged code
exactly means.

Thanks,

glenn

Before you jump into this, you should make certain that if Delphi
is
going to support .Net. If it is or is going to, it will be all mute
point as you can develop in C# or whatever to produce managed code and
consue it in Delphi.

If Delphi is not going to support managed code, then you will need to
write a COM server in managed code. The link I provided in my first
reply shows how to do it(ComVisible attribute).

since c# does not support the old DLL processes which you seem
to have just confirmed,

I am not what you mean here. You can call unmanaged DLLs using
interop/PInvoke in managed code(C#). That means your Delphi code
(whatever is exported by it) can be used in a managed code. If you
have
a COM server in Delphi, you can use it in C#.
 
Where? When I created my default app it automatically adds a form that has
public events and things in it. But it still does not allow me to select
the COM stuff. Where exactly would I add these events?

Thanks,

glenn
Sean Hederman said:
You need at least one public class, with a public default constructor, and
public methods.

glenn said:
Actually, I just created a brand new project and did what was said to do.
I
haven't added or changed anything at this point...

thanks,

glenn

Sean Hederman said:
Sorry, while it will compile now, the Register for COM option is greyed
out
and set to false. I can't change it to true... Am I missing
something?

Weird, mine doesn't go off even when I change my project type to
Console.
Do
you have any public classes in your code. If you do I'm not sure what the
problem is, probably some obscure setting somewhere. Doesn't really
matter
anyway, since all that option does is automatically run regasm on your
assembly for you, so you can just do that manually.


glenn
In your C# DLL do the following:

AssemblyInfo.cs
----------------
[assembly: ComVisible(true)]

Then, right-click on the project in the Solution Explorer, select
Properties, choose Configuration Properties\Build, and set "Register for
COM
Interop" to "True".

Now when you build your project it will make it COM-compatible and
register
it on your machine. You should now be able to reference the C#
library
in
your Delphi code.

I understand but you are backwards. I am trying to write a dll in C#
(managed code) and call that dll from Delphi 6 which is unmanaged.
Delphi
2005 supports all the .NET stuff but our project is currently being
managed
in Delphi 6 which does not.

So to recap. I want to write a dll in C# that performs a function that
just
pops up a message box and says hello world. I then want to call
that
function from inside my delphi application so that the message box pops
up.

I'm also behind the times a little with all this managed code
stuff
so
I'm
not sure what the differences are from what managed and unmanaged code
exactly means.

Thanks,

glenn

Before you jump into this, you should make certain that if Delphi
is
going to support .Net. If it is or is going to, it will be all mute
point as you can develop in C# or whatever to produce managed
code
and
consue it in Delphi.

If Delphi is not going to support managed code, then you will
need
to
write a COM server in managed code. The link I provided in my first
reply shows how to do it(ComVisible attribute).

since c# does not support the old DLL processes which you seem
to have just confirmed,

I am not what you mean here. You can call unmanaged DLLs using
interop/PInvoke in managed code(C#). That means your Delphi code
(whatever is exported by it) can be used in a managed code. If you
have
a COM server in Delphi, you can use it in C#.
 
I still believe your best bet is to use Delphi 2005 if it supports .Net
and unmangaged code in the same component. You need to find this out
before deciding about how to proceed.

There is absolutely no need to use D2005 as D6 is well able to cope with
using COM objects. Delphi has always been a very flexible development tool;
and has supported both COM and CORBA since either v3 or v4.

As the OP has discovered, all that is required is to create a COM interop
assembly which can then be used to create a type library using Delphi's COM
wizard.

Joanna
 
Back
Top