By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,771 Members | 1,709 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,771 IT Pros & Developers. It's quick & easy.

COM Interop Problem

P: n/a
I have a COM Server that I've written based on information from the book
..NET and COM / the complete Interop Guide. I have gotten the project to
compile and I've located the regasm.exe program that I was suppose to run
against my dll in order to generate a TLB file for the purposes of importing
the COM object into other programming lanugages such as Delphi.

However, when I try to import the type library into Delphi which I have done
hundreds of times with other components, I get build errors in the
mscorlib_tlb file that states that the Type Byte is not completely defined
as well as Illegal type in OLE automation section for Byte.

Can anyone tell me what is happening here and how to fix it as the book says
nothing of the issue.

thanks,
glenn
Nov 17 '05 #1
Share this Question
Share on Google+
22 Replies


P: n/a

"glenn" <gh******@softeksoftware.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I have a COM Server that I've written based on information from the book
.NET and COM / the complete Interop Guide. I have gotten the project to
compile and I've located the regasm.exe program that I was suppose to run
against my dll in order to generate a TLB file for the purposes of
importing
the COM object into other programming lanugages such as Delphi.

However, when I try to import the type library into Delphi which I have
done
hundreds of times with other components, I get build errors in the
mscorlib_tlb file that states that the Type Byte is not completely defined
as well as Illegal type in OLE automation section for Byte.

Can anyone tell me what is happening here and how to fix it as the book
says
nothing of the issue.

thanks,
glenn


Could you post your code (or part of), and the regasm.exe command line
arguments used?
Not sure where mscorlib_tlb comes from, is this a Delphi generated typelib?
Did you try to create an instance and call a method from a simple
vb/Jscript?

Willy.
Nov 17 '05 #2

P: n/a
I have not tried Java as I don't know java. Here is the code and its pretty
much straight out of the book.

the book told me to run regasm "Com Server.dll" /tlb where Com Server just
happens to be what I named my test app. The tlb is being generated and
registered in the type library. In Delphi for any other COM object I just
go choose the object from the list and it builds the wrappers and adds it to
my component pallet to use. In this case however, I can not get it to wrap
the object due to these errors.

Thanks,

glenn
using System;

using System.Text.RegularExpressions;

using System.Reflection;

//[assembly:AssemblyKeyFile("KeyFile.snk")]

namespace COM_Server

{

/// <summary>

/// Summary description for validation.

/// </summary>

public class validation

{

public validation()

{

//

// TODO: Add constructor logic here

//

}
public bool IsPhoneNumber( string s )

{

return Regex.IsMatch(s,

@"^(((\(\d{3}\)( )?)|(\d{3}( |\-)))\d{3}\-\d{4})$");

}
public bool IsZipCode( string s )

{

return Regex.IsMatch(s, @"^((\d{5})|(\d{5}\-\d{4}))$");

}
public bool IsSSN( string s )

{

return Regex.IsMatch(s, @"^\d{3}\-\d{2}\-\d{4}$");

}
}

}
Nov 17 '05 #3

P: n/a

"glenn" <gh******@softeksoftware.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
I have not tried Java as I don't know java. Here is the code and its
pretty
much straight out of the book.

the book told me to run regasm "Com Server.dll" /tlb where Com Server
just
happens to be what I named my test app. The tlb is being generated and
registered in the type library. In Delphi for any other COM object I just
go choose the object from the list and it builds the wrappers and adds it
to
my component pallet to use. In this case however, I can not get it to
wrap
the object due to these errors.


I mean Javascript not Java. Anyway here is a VBScript snippet that you can
use to test your code.

Dim obj
set obj = CreateObject("COM_Server.validation")
if (obj.IsPhoneNumber("123-235-4365") = true) then
WScript.Echo "It's valid"
end if

Save it as a test.vbs file and run it from the command line.
run:
cscript test.vbs
or simply
test.vbs

Note that still I'm not clear on the mscorlib_tlb file, wonder where does
this comes from?

Willy.

Nov 17 '05 #4

P: n/a
Not really sure but I"m starting to think its something Delphi is doing
because of the fact that the COM object has to use the mscorlib stuff in
order to interface properly and delphi therefore is attempting to import it
as well. I'm looking into it from that perspective anyway...

Thanks,

glenn
"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:uO**************@TK2MSFTNGP14.phx.gbl...

"glenn" <gh******@softeksoftware.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
I have not tried Java as I don't know java. Here is the code and its
pretty
much straight out of the book.

the book told me to run regasm "Com Server.dll" /tlb where Com Server
just
happens to be what I named my test app. The tlb is being generated and
registered in the type library. In Delphi for any other COM object I just go choose the object from the list and it builds the wrappers and adds it to
my component pallet to use. In this case however, I can not get it to
wrap
the object due to these errors.


I mean Javascript not Java. Anyway here is a VBScript snippet that you can
use to test your code.

Dim obj
set obj = CreateObject("COM_Server.validation")
if (obj.IsPhoneNumber("123-235-4365") = true) then
WScript.Echo "It's valid"
end if

Save it as a test.vbs file and run it from the command line.
run:
cscript test.vbs
or simply
test.vbs

Note that still I'm not clear on the mscorlib_tlb file, wonder where does
this comes from?

Willy.

Nov 17 '05 #5

P: n/a
Willy,

I have a question for you since you seem to be the only COM guy here. I
have a COM server that passes back a variant that is actually a string.
This obviously works in all other programming languages that I call it from
but it is not working in C# because it does not support variant types. The
book told me that it maps to type object, however, I have a problem with it.

1) it raises exception when trying to do object ob =
myCOM.executemyfunc();

any ideas?

glenn

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:uO**************@TK2MSFTNGP14.phx.gbl...

"glenn" <gh******@softeksoftware.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
I have not tried Java as I don't know java. Here is the code and its
pretty
much straight out of the book.

the book told me to run regasm "Com Server.dll" /tlb where Com Server
just
happens to be what I named my test app. The tlb is being generated and
registered in the type library. In Delphi for any other COM object I just go choose the object from the list and it builds the wrappers and adds it to
my component pallet to use. In this case however, I can not get it to
wrap
the object due to these errors.


I mean Javascript not Java. Anyway here is a VBScript snippet that you can
use to test your code.

Dim obj
set obj = CreateObject("COM_Server.validation")
if (obj.IsPhoneNumber("123-235-4365") = true) then
WScript.Echo "It's valid"
end if

Save it as a test.vbs file and run it from the command line.
run:
cscript test.vbs
or simply
test.vbs

Note that still I'm not clear on the mscorlib_tlb file, wonder where does
this comes from?

Willy.

Nov 17 '05 #6

P: n/a

"glenn" <gh******@softeksoftware.com> wrote in message
news:OI**************@TK2MSFTNGP14.phx.gbl...
Willy,

I have a question for you since you seem to be the only COM guy here. I
have a COM server that passes back a variant that is actually a string.
This obviously works in all other programming languages that I call it
from
but it is not working in C# because it does not support variant types.
The
book told me that it maps to type object, however, I have a problem with
it.

1) it raises exception when trying to do object ob =
myCOM.executemyfunc();

any ideas?

glenn


I've extended the class you posted in another thread like this:

public class validation
{
public validation()
{
...
public string GiveMeAString()
{
return "Here I am";
}
public object GiveMeAVariantString()
{
return "Here I am hidden in a VARIANT";
}
....
Compile this stuff and register it with - regasm /codebase your.dll /tlb

See I just return a string, and the CLR will marshal the string to a VARIANT
of type BSTR.
the second method returns an object of type String, again the marshaler will
convert it to a VARIANT of type BSTR on return.

You can call it from vbscript ( a COM client) using this:

Dim obj
set obj = CreateObject("COM_Server.validation")
WScript.Echo obj.GiveMeAString()
WScript.Echo obj.GiveMeAVariantString()

Note that all variables in VBS are VARIANT types.

Not sure why or what problem you have exactly, anyway it should work.

Willy.

Nov 17 '05 #7

P: n/a
>
Note that all variables in VBS are VARIANT types.


yes, but this is my point. #1, I'm not calling a C# COM Object. I'm
calling an already existing COM object that I imported that was writting in
unmanaged code in another language.

C# Does not support variant types and therefore you can not execute the code
you listed for VB. They guy in the book says you must cast as object, but
that does not work either. At the moment I'm totally stuck...

thanks,

glenn
Nov 17 '05 #8

P: n/a

"glenn" <gh******@softeksoftware.com> wrote in message
news:uG**************@TK2MSFTNGP09.phx.gbl...

Note that all variables in VBS are VARIANT types.


yes, but this is my point. #1, I'm not calling a C# COM Object. I'm
calling an already existing COM object that I imported that was writting
in
unmanaged code in another language.

C# Does not support variant types and therefore you can not execute the
code
you listed for VB. They guy in the book says you must cast as object, but
that does not work either. At the moment I'm totally stuck...


Sure it does, otherwise it would be useless and could not be used to interop
with Office and other COM server types, VARIANT types are marshaled as
System.Object.
But a VARIANT is a container for another type, like a BSTR or some other
oleautomation compatible type.
What type does your VARIANT return contain, what error do you get?
Can you post a code snip (just a method or part of) of you COM server code?

Willy.

Nov 17 '05 #9

P: n/a
Here is the line of code from C#...

object user = secure.m_getloggedinuser();

When that executes I get :

Loaded 'c:\source\temp\c#-com tests\com tests\com
client\bin\debug\interop.ssisecure.dll', No symbols loaded.

The program '[3700] COM Client.exe' has exited with code 0 (0x0).

The COM server is responding with a variant type that is cast to a string in
all my other clients. Here it appears I'm missing a step but I've followed
the instructions in the book...

Thanks,

glenn

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:O0*************@TK2MSFTNGP12.phx.gbl...

"glenn" <gh******@softeksoftware.com> wrote in message
news:uG**************@TK2MSFTNGP09.phx.gbl...

Note that all variables in VBS are VARIANT types.
yes, but this is my point. #1, I'm not calling a C# COM Object. I'm
calling an already existing COM object that I imported that was writting
in
unmanaged code in another language.

C# Does not support variant types and therefore you can not execute the
code
you listed for VB. They guy in the book says you must cast as object, but that does not work either. At the moment I'm totally stuck...


Sure it does, otherwise it would be useless and could not be used to

interop with Office and other COM server types, VARIANT types are marshaled as
System.Object.
But a VARIANT is a container for another type, like a BSTR or some other
oleautomation compatible type.
What type does your VARIANT return contain, what error do you get?
Can you post a code snip (just a method or part of) of you COM server code?
Willy.


Nov 17 '05 #10

P: n/a
There also seems to be something missing from the assembly altogether as I
also can not use regsvr32 to register the assembly as a COM object. It says
its missing its entry points and can't be loaded. This normally happens to
me in Delphi if I do not provide a proper exports section for the dll
related to the COM objects.

Did I perhaps miss something in my COM Server in C# that is making it not
export correctly?

Thanks,

glenn
"glenn" <gh******@softeksoftware.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I have a COM Server that I've written based on information from the book
.NET and COM / the complete Interop Guide. I have gotten the project to
compile and I've located the regasm.exe program that I was suppose to run
against my dll in order to generate a TLB file for the purposes of importing the COM object into other programming lanugages such as Delphi.

However, when I try to import the type library into Delphi which I have done hundreds of times with other components, I get build errors in the
mscorlib_tlb file that states that the Type Byte is not completely defined
as well as Illegal type in OLE automation section for Byte.

Can anyone tell me what is happening here and how to fix it as the book says nothing of the issue.

thanks,
glenn

Nov 17 '05 #11

P: n/a

"glenn" <gh******@softeksoftware.com> wrote in message
news:uZ**************@TK2MSFTNGP10.phx.gbl...
There also seems to be something missing from the assembly altogether as I
also can not use regsvr32 to register the assembly as a COM object. It
says
its missing its entry points and can't be loaded. This normally happens
to
me in Delphi if I do not provide a proper exports section for the dll
related to the COM objects.

Did I perhaps miss something in my COM Server in C# that is making it not
export correctly?

Thanks,

glenn


C# assemblies exposing COM interfaces do not get registered using regsvr32.
You have to run regasm.exe.

regasm /codebase /tlb yourcsharp.dll

Check the commandline syntax by typing regasm /?

Willy.
Nov 17 '05 #12

P: n/a

"glenn" <gh******@softeksoftware.com> wrote in message
news:ub**************@tk2msftngp13.phx.gbl...
Here is the line of code from C#...

object user = secure.m_getloggedinuser();

When that executes I get :

Loaded 'c:\source\temp\c#-com tests\com tests\com
client\bin\debug\interop.ssisecure.dll', No symbols loaded.

The program '[3700] COM Client.exe' has exited with code 0 (0x0).

The COM server is responding with a variant type that is cast to a string
in
all my other clients. Here it appears I'm missing a step but I've
followed
the instructions in the book...

Thanks,

glenn


I was talking about the COM server code, not the client part.
Did you try to run ildasm on the interop library to check the method
signature?

Willy.

Nov 17 '05 #13

P: n/a

"glenn" <gh******@softeksoftware.com> wrote in message
news:ub**************@tk2msftngp13.phx.gbl...
Here is the line of code from C#...

object user = secure.m_getloggedinuser();

When that executes I get :

Loaded 'c:\source\temp\c#-com tests\com tests\com
client\bin\debug\interop.ssisecure.dll', No symbols loaded.

The program '[3700] COM Client.exe' has exited with code 0 (0x0).

The COM server is responding with a variant type that is cast to a string
in
all my other clients. Here it appears I'm missing a step but I've
followed
the instructions in the book...

Thanks,

glenn


The "No symbols loaded" message indicates there are no symbols available for
the interop assembly, not to worry about this is normal.
The exit message indicates a normal exit....
you will have to post some more code as I'm not clear on what follows.

Willy.
Nov 17 '05 #14

P: n/a
I tried but don't know file to open in order to do this.
I have never used that program before so not really sure what its doing
yet...

Also here is the total source for the server:
using System;

using System.Text.RegularExpressions;

using System.Reflection;

//[assembly:AssemblyKeyFile("KeyFile.snk")] this is actually provided for
in the assemblyInfo.cs file so its been done but over there

namespace COM_Server

{

/// <summary>

/// Summary description for validation.

/// </summary>

public class validation

{

public validation()

{

//

// TODO: Add constructor logic here

//

}
public bool IsPhoneNumber( string s )

{

return Regex.IsMatch(s,

@"^(((\(\d{3}\)( )?)|(\d{3}( |\-)))\d{3}\-\d{4})$");

}
public bool IsZipCode( string s )

{

return Regex.IsMatch(s, @"^((\d{5})|(\d{5}\-\d{4}))$");

}
public bool IsSSN( string s )

{

return Regex.IsMatch(s, @"^\d{3}\-\d{2}\-\d{4}$");

}
}

}
I then compiled and ran regasm mycom.dll /tlb and it did add it to the type
library list for COM objects because I can pick it to load into Delphi...
But I can't compile due to the other things I had listed earlier...
I also tried to import into delphi via the type library itself (tlb file)
but received the errors about it not being valid...

Thanks,

glenn

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:OA**************@tk2msftngp13.phx.gbl...

"glenn" <gh******@softeksoftware.com> wrote in message
news:ub**************@tk2msftngp13.phx.gbl...
Here is the line of code from C#...

object user = secure.m_getloggedinuser();

When that executes I get :

Loaded 'c:\source\temp\c#-com tests\com tests\com
client\bin\debug\interop.ssisecure.dll', No symbols loaded.

The program '[3700] COM Client.exe' has exited with code 0 (0x0).

The COM server is responding with a variant type that is cast to a string in
all my other clients. Here it appears I'm missing a step but I've
followed
the instructions in the book...

Thanks,

glenn


I was talking about the COM server code, not the client part.
Did you try to run ildasm on the interop library to check the method
signature?

Willy.

Nov 17 '05 #15

P: n/a
one note: In the book he tells me to run:
csc /t:library Mycode.cs /r:System.dll and I did not do this step because I
do not have a csc.exe program anywhere on my hard drive that I can find. He
says its the c# command line compiler. Has it been renamed, is this step
what might be causing my problem?

Thanks,

glenn
"glenn" <gh******@softeksoftware.com> wrote in message
news:Oq**************@TK2MSFTNGP14.phx.gbl...
I tried but don't know file to open in order to do this.
I have never used that program before so not really sure what its doing
yet...

Also here is the total source for the server:
using System;

using System.Text.RegularExpressions;

using System.Reflection;

//[assembly:AssemblyKeyFile("KeyFile.snk")] this is actually provided for in the assemblyInfo.cs file so its been done but over there

namespace COM_Server

{

/// <summary>

/// Summary description for validation.

/// </summary>

public class validation

{

public validation()

{

//

// TODO: Add constructor logic here

//

}
public bool IsPhoneNumber( string s )

{

return Regex.IsMatch(s,

@"^(((\(\d{3}\)( )?)|(\d{3}( |\-)))\d{3}\-\d{4})$");

}
public bool IsZipCode( string s )

{

return Regex.IsMatch(s, @"^((\d{5})|(\d{5}\-\d{4}))$");

}
public bool IsSSN( string s )

{

return Regex.IsMatch(s, @"^\d{3}\-\d{2}\-\d{4}$");

}
}

}
I then compiled and ran regasm mycom.dll /tlb and it did add it to the type library list for COM objects because I can pick it to load into Delphi...
But I can't compile due to the other things I had listed earlier...
I also tried to import into delphi via the type library itself (tlb file)
but received the errors about it not being valid...

Thanks,

glenn

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:OA**************@tk2msftngp13.phx.gbl...

"glenn" <gh******@softeksoftware.com> wrote in message
news:ub**************@tk2msftngp13.phx.gbl...
Here is the line of code from C#...

object user = secure.m_getloggedinuser();

When that executes I get :

Loaded 'c:\source\temp\c#-com tests\com tests\com
client\bin\debug\interop.ssisecure.dll', No symbols loaded.

The program '[3700] COM Client.exe' has exited with code 0 (0x0).

The COM server is responding with a variant type that is cast to a string in
all my other clients. Here it appears I'm missing a step but I've
followed
the instructions in the book...

Thanks,

glenn


I was talking about the COM server code, not the client part.
Did you try to run ildasm on the interop library to check the method
signature?

Willy.


Nov 17 '05 #16

P: n/a

"glenn" <gh******@softeksoftware.com> wrote in message
news:Oq**************@TK2MSFTNGP14.phx.gbl...
I tried but don't know file to open in order to do this.
I have never used that program before so not really sure what its doing
yet...

Also here is the total source for the server:
using System;

using System.Text.RegularExpressions;

using System.Reflection;

//[assembly:AssemblyKeyFile("KeyFile.snk")] this is actually provided
for
in the assemblyInfo.cs file so its been done but over there

namespace COM_Server

{

/// <summary>

/// Summary description for validation.

/// </summary>

public class validation

{

public validation()

{

//

// TODO: Add constructor logic here

//

}
public bool IsPhoneNumber( string s )

{

return Regex.IsMatch(s,

@"^(((\(\d{3}\)( )?)|(\d{3}( |\-)))\d{3}\-\d{4})$");

}
public bool IsZipCode( string s )

{

return Regex.IsMatch(s, @"^((\d{5})|(\d{5}\-\d{4}))$");

}
public bool IsSSN( string s )

{

return Regex.IsMatch(s, @"^\d{3}\-\d{2}\-\d{4}$");

}
}

}
I then compiled and ran regasm mycom.dll /tlb and it did add it to the
type
library list for COM objects because I can pick it to load into Delphi...
But I can't compile due to the other things I had listed earlier...
I also tried to import into delphi via the type library itself (tlb file)
but received the errors about it not being valid...

Thanks,

glenn


Seems like we are running in circles, this is the same code you posted
before, and it's the sample in Nathan's book ch8.

I showed you how you could call it from a simple COM client (VBScript is a
COM client), just to prove nothing is wrong with the sample in the book.
So please do yourself a favor, save this in a file say test.vbs and run it
from the command line using:
cscript test.vbs
or simply
test

Dim obj
set obj = CreateObject("COM_Server.validation")
if (obj.IsPhoneNumber("123-235-4365") = true) then
WScript.Echo "It's valid"
end if

Make sure your C# assembly is registered with regasm /codebase yourdll /tlb

This should work with any COM oleautomation compliant client (including
Delphi), using VBScript is just for convenience.

Willy.


Nov 17 '05 #17

P: n/a
Actually I take that back. I finally found it and here is what I get when i
run the command he gave me.

error CS5001: Program 'c:\Source\Temp\C#-COM TESTS\COM Tests\COM
Server\validation.exe' does not have an entry point defined

Now, I have a project called "COM Server" and a unit called validation.cs
that is part of that program that actually contains all the code I sent you
earlier.

The above error is the result of running: csc validation.cs /r:System.dll

and I ran from the main source folder not the location where the dll exists
in debug.

Should VS 2003 already be doing these steps for me or is it required for me
to run this at the command line each time I want to compile a COM server
written in C#?

I still can not get this COM Server installed into Delphi...

P.S. Thanks for all your assistance and patience with me...

Thanks,

glenn
"glenn" <gh******@softeksoftware.com> wrote in message
news:Oq**************@TK2MSFTNGP14.phx.gbl...
I tried but don't know file to open in order to do this.
I have never used that program before so not really sure what its doing
yet...

Also here is the total source for the server:
using System;

using System.Text.RegularExpressions;

using System.Reflection;

//[assembly:AssemblyKeyFile("KeyFile.snk")] this is actually provided for in the assemblyInfo.cs file so its been done but over there

namespace COM_Server

{

/// <summary>

/// Summary description for validation.

/// </summary>

public class validation

{

public validation()

{

//

// TODO: Add constructor logic here

//

}
public bool IsPhoneNumber( string s )

{

return Regex.IsMatch(s,

@"^(((\(\d{3}\)( )?)|(\d{3}( |\-)))\d{3}\-\d{4})$");

}
public bool IsZipCode( string s )

{

return Regex.IsMatch(s, @"^((\d{5})|(\d{5}\-\d{4}))$");

}
public bool IsSSN( string s )

{

return Regex.IsMatch(s, @"^\d{3}\-\d{2}\-\d{4}$");

}
}

}
I then compiled and ran regasm mycom.dll /tlb and it did add it to the type library list for COM objects because I can pick it to load into Delphi...
But I can't compile due to the other things I had listed earlier...
I also tried to import into delphi via the type library itself (tlb file)
but received the errors about it not being valid...

Thanks,

glenn

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:OA**************@tk2msftngp13.phx.gbl...

"glenn" <gh******@softeksoftware.com> wrote in message
news:ub**************@tk2msftngp13.phx.gbl...
Here is the line of code from C#...

object user = secure.m_getloggedinuser();

When that executes I get :

Loaded 'c:\source\temp\c#-com tests\com tests\com
client\bin\debug\interop.ssisecure.dll', No symbols loaded.

The program '[3700] COM Client.exe' has exited with code 0 (0x0).

The COM server is responding with a variant type that is cast to a string in
all my other clients. Here it appears I'm missing a step but I've
followed
the instructions in the book...

Thanks,

glenn


I was talking about the COM server code, not the client part.
Did you try to run ildasm on the interop library to check the method
signature?

Willy.


Nov 17 '05 #18

P: n/a

"glenn" <gh******@softeksoftware.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Actually I take that back. I finally found it and here is what I get when
i
run the command he gave me.

error CS5001: Program 'c:\Source\Temp\C#-COM TESTS\COM Tests\COM
Server\validation.exe' does not have an entry point defined

Now, I have a project called "COM Server" and a unit called validation.cs
that is part of that program that actually contains all the code I sent
you
earlier.

The above error is the result of running: csc validation.cs /r:System.dll

and I ran from the main source folder not the location where the dll
exists
in debug.

Should VS 2003 already be doing these steps for me or is it required for
me
to run this at the command line each time I want to compile a COM server
written in C#?

I still can not get this COM Server installed into Delphi...

P.S. Thanks for all your assistance and patience with me...

Thanks,

glenn


csc/t:library ....
this builds a library ( DLL).
What you are trying is to build an exe, the default when running csc without
/t:xxxxx

Your VS project should be set to build library and have the settings to
export it as a COM server.
Note that for small tests like this you better use the command line tools
like csc, regasm etc.
You'll be suprised how much you'll learn, things that are hidden by the
IDE....

Willy.


Nov 17 '05 #19

P: n/a
Ok, I'll stop bothering you with it then. The problem is, that it does not
work in Delphi and I do not know why. I"ve been programming for 12 years,
10 of them in Delphi and have worked with literally hundreds of COM servers
in my life and have never one time had a problem importing the type library
into Delphi. This happens to be the first C# COM server I've tried to
import and it will not import.

I'm only trying to figure out why.

Thanks for all the help and trouble,

glenn
"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...

"glenn" <gh******@softeksoftware.com> wrote in message
news:Oq**************@TK2MSFTNGP14.phx.gbl...
I tried but don't know file to open in order to do this.
I have never used that program before so not really sure what its doing
yet...

Also here is the total source for the server:
using System;

using System.Text.RegularExpressions;

using System.Reflection;

//[assembly:AssemblyKeyFile("KeyFile.snk")] this is actually provided
for
in the assemblyInfo.cs file so its been done but over there

namespace COM_Server

{

/// <summary>

/// Summary description for validation.

/// </summary>

public class validation

{

public validation()

{

//

// TODO: Add constructor logic here

//

}
public bool IsPhoneNumber( string s )

{

return Regex.IsMatch(s,

@"^(((\(\d{3}\)( )?)|(\d{3}( |\-)))\d{3}\-\d{4})$");

}
public bool IsZipCode( string s )

{

return Regex.IsMatch(s, @"^((\d{5})|(\d{5}\-\d{4}))$");

}
public bool IsSSN( string s )

{

return Regex.IsMatch(s, @"^\d{3}\-\d{2}\-\d{4}$");

}
}

}
I then compiled and ran regasm mycom.dll /tlb and it did add it to the
type
library list for COM objects because I can pick it to load into Delphi... But I can't compile due to the other things I had listed earlier...
I also tried to import into delphi via the type library itself (tlb file) but received the errors about it not being valid...

Thanks,

glenn

Seems like we are running in circles, this is the same code you posted
before, and it's the sample in Nathan's book ch8.

I showed you how you could call it from a simple COM client (VBScript is a
COM client), just to prove nothing is wrong with the sample in the book.
So please do yourself a favor, save this in a file say test.vbs and run it
from the command line using:
cscript test.vbs
or simply
test

Dim obj
set obj = CreateObject("COM_Server.validation")
if (obj.IsPhoneNumber("123-235-4365") = true) then
WScript.Echo "It's valid"
end if

Make sure your C# assembly is registered with regasm /codebase yourdll

/tlb
This should work with any COM oleautomation compliant client (including
Delphi), using VBScript is just for convenience.

Willy.

Nov 17 '05 #20

P: n/a
But what do you mean about the proper settings made for the COM server? I
have done nothing here but write a C# dll library. I have done nothing to
tell this I'm working on a COM server except for running the regasm program
against it. Is there anything else in the program itself that must be told
that this is a COM server?

Thanks,

glenn
"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:eK**************@TK2MSFTNGP12.phx.gbl...

"glenn" <gh******@softeksoftware.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Actually I take that back. I finally found it and here is what I get when i
run the command he gave me.

error CS5001: Program 'c:\Source\Temp\C#-COM TESTS\COM Tests\COM
Server\validation.exe' does not have an entry point defined

Now, I have a project called "COM Server" and a unit called validation.cs that is part of that program that actually contains all the code I sent
you
earlier.

The above error is the result of running: csc validation.cs /r:System.dll
and I ran from the main source folder not the location where the dll
exists
in debug.

Should VS 2003 already be doing these steps for me or is it required for
me
to run this at the command line each time I want to compile a COM server
written in C#?

I still can not get this COM Server installed into Delphi...

P.S. Thanks for all your assistance and patience with me...

Thanks,

glenn

csc/t:library ....
this builds a library ( DLL).
What you are trying is to build an exe, the default when running csc

without /t:xxxxx

Your VS project should be set to build library and have the settings to
export it as a COM server.
Note that for small tests like this you better use the command line tools
like csc, regasm etc.
You'll be suprised how much you'll learn, things that are hidden by the
IDE....

Willy.

Nov 17 '05 #21

P: n/a

"glenn" <gh******@softeksoftware.com> wrote in message
news:uH***************@TK2MSFTNGP12.phx.gbl...
Ok, I'll stop bothering you with it then. The problem is, that it does
not
work in Delphi and I do not know why. I"ve been programming for 12 years,
10 of them in Delphi and have worked with literally hundreds of COM
servers
in my life and have never one time had a problem importing the type
library
into Delphi. This happens to be the first C# COM server I've tried to
import and it will not import.

I'm only trying to figure out why.

Thanks for all the help and trouble,

glenn


Not a problem, I'm just trying to help you out, therefore please try it with
the script first, if this works you can repost with "Subject: COM interop
fails with Delphi client", I'm sure of lot of posters are using Delphi and
C# in interop scenarios.
If it doesn't work with the script there must be something wrong elsewere.
Anyway it must work with the script as client else it won't work with Delphi
as client either.

Willy.
Nov 17 '05 #22

P: n/a

"glenn" <gh******@softeksoftware.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
But what do you mean about the proper settings made for the COM server? I
have done nothing here but write a C# dll library. I have done nothing to
tell this I'm working on a COM server except for running the regasm
program
against it. Is there anything else in the program itself that must be
told
that this is a COM server?

Thanks,

glenn


When working from the commandline you compile using csc and register the
library as a COM server using Regasm.exe.

When building from a VS project, you have to set your project properties
such that the assembly gets registered as as COM server, else you only call
it from managed code and not from a native COM client.

Note that there are attributes you can set (and you better do) to make your
classes COM friendly (
must read : Exposing .NET Framework Components to COM in MSDN)
Willy.

Nov 17 '05 #23

This discussion thread is closed

Replies have been disabled for this discussion.