473,406 Members | 2,345 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,406 software developers and data experts.

COM Interop Problem

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
22 4806

"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
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

"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
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
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

"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
>
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

"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
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
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

"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

"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

"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
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
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

"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
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

"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
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
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

"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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Nadav | last post by:
Hi, Introduction *************** I have a system build of a collection of 'Native COM objects' and '.NET COM interop' objects, all of the COM objects are managed through a 'Native COM' layer,...
20
by: Razzie | last post by:
Hey all, I'm really going through a small hell right now - I've completely lost it :) I made a project, using two interop libraries from exchange (created them as in this msdn article:...
1
by: Shiro | last post by:
Hi I have read the various postings relating to Interop strong name signing and cannot find an example similar to mine. I have stringly named my AxInterops/Interops and they all work just...
8
by: Rob Edwards | last post by:
When trying to add the Microsoft CDO for Exchange Management Library (aka CDOEXM.dll) I receive the following message: "A reference to 'Microsoft CDO for Exchange Management Library' could not be...
7
by: R Reyes | last post by:
Can someone please explain to me why I can't get the MS Word Interop assembly to work in my VS2005 project? I'm trying to manipulate MS Word from my Web Form application and I can't get passed...
3
by: Hospital S.Sebastiao | last post by:
Hi, i'm in desperate need of help to fix a problem that i have, the problem is the following: I have an ASP.NET aplication that to open an word template document, this aplication is in C#(using...
2
by: JC | last post by:
Anybody knows what problem has this code? I think, in the Garbage Collector? You know the Solution? The program in the test's case, whit 350 contacts, run OK before number 86. The error is a...
1
by: Don.Leri | last post by:
Hi, I have a logger.dll (unmanaged c++ dll compiled in vs2005). I have a C# interop to use that dll in managed code implemented in Interfaces.dll (used by other C# dlls). I also have a...
1
by: allbelonging | last post by:
C#.Net Outlook 2003 automation (programmatically) with Office.Interop.Outlook Problem: I have my outlook 2003 configured with multiple mailbox on my local machine. I want to specify the mailbox...
0
by: Tina | last post by:
I've gotten this before where it says there is a problem with Interop.MSDASC but I can't remember what causes this. This is a 1.1 app I'm trying to debug in vs2005. It was running yesterday just...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.