If I'm not mistake, structs are exposed to COM as simple idl structs, which
means that none of the methods are exported. Assuming this is true, none of
your methods (and i think this also means properties) are exported. by the
way, you should use the StructLayoutAttribute with the value
LayoutKind.Sequential to fix the members of the struct.
regarding the error you're speaking of, without COM code there's nothing
more I can do about it.

Signature
--
Regards,
Luis Abreu
http://weblogs.pontonetpt.com/luisabreu
http://www.pontonetpt.com
> I'm trying to make my own ValueType in C#, i need to call this from COM so i
> need to expose it.
[quoted text clipped - 51 lines]
>
> The result of exposing is 2 variables _assigned and _vaerdi.
Mads - 06 Oct 2004 11:47 GMT
Thank you for helping :o).
Here is a complete example of the code:
I try to ask another way: Is there any way to expose the type FinVal so it
is posible to use like i do in C#.
Ex i need to call it from Delphi:
var
test1 : Test;
begin
test1 := CoTest.Create;
test1.Val := 100; // this makes error "Incompatible types"
test1.Val._vaerdi := 100; // this makes errer "Left side cannot be
assigned to"
end;
using System;
using System.Runtime.InteropServices;
namespace ClassLibrary1
{
[ClassInterface(ClassInterfaceType.AutoDual)]
public class Test
{
public Test()
{
}
private FinVal _val;
public FinVal Val
{
get
{
return _val;
}
set
{
_val = value;
}
}
}
[StructLayout(LayoutKind.Sequential)]
public struct FinVal
{
private bool _assigned;
private bool Assigned
{
get
{
return _assigned;
}
set
{
_assigned = value;
}
}
private double _vaerdi;
public double Vaerdi
{
get
{
if(Assigned)
return _vaerdi;
else
throw new Exception("Vaerdien er ikke sat!: " +
this.GetType().TypeInitializer.Name);
}
set
{
Assigned = true;
_vaerdi = value;
}
}
public FinVal(double vaerdi)
{
_assigned = true;
_vaerdi = vaerdi;
}
public override string ToString()
{
return Convert.ToString(Vaerdi);
}
public override bool Equals(object obj)
{
return base.Equals(obj);
}
public override int GetHashCode()
{
return base.GetHashCode ();
}
public static explicit operator int(FinVal val)
{
return (int)val.Vaerdi;
}
public static implicit operator FinVal(int val)
{
return new FinVal(val);
}
}
}
> If I'm not mistake, structs are exposed to COM as simple idl structs, which
> means that none of the methods are exported. Assuming this is true, none of
[quoted text clipped - 61 lines]
> >
> > The result of exposing is 2 variables _assigned and _vaerdi.
Luis Abreu - 06 Oct 2004 14:54 GMT
Hello again.
> I try to ask another way: Is there any way to expose the type FinVal so it
> is posible to use like i do in C#.
short answer: I think not...what you must understand is that COM is not
about OO programming...it's about contracts made at binary level (at least
that's my opinion).
Another thing that you must understand is that when your struct is exported
to COM it looses all its members. So, if you use oleview to see what you've
got, you'll notice that there's only 2 members _assigned and _vaerdi. btw,
if you really want to use the struct, then maybe it's better to expose them
without the underscore ( _ ) (because VB doesn't show them due to the fact
that names started with underscore should be private).

Signature
--
Regards,
Luis Abreu
http://weblogs.pontonetpt.com/luisabreu
http://www.pontonetpt.com