G
Guest
I am writing a C# class library that exposes a method that return a
structure. I am registering the assembly for COM interop and can reference
the assembly in VB (Actually an Acces 2000 Code Module). I can instantiate
the object in VB but when I declare the variable for the returning structure
I get the following error.
Variable uses and automation type not supported Visual Basic.
Also, if I declare the variable as an Object, the error occurs when I call
the method.
Here is my code below...
C# Cod
---------------------------------------------------------------------------------------------
[GuidAttribute("B7D043BD-1003-4c6e-9050-0D0C4D93E213")]
[ClassInterface(ClassInterfaceType.AutoDual)]
public class VINDecoder
{
[StructLayout(LayoutKind.Sequential)]
[GuidAttribute("C39A4B1A-9186-40d8-BB26-CEE38D92A084")]
public struct VehicleInformation
{
[MarshalAs(UnmanagedType.LPWStr)]
public string Year;
[MarshalAs(UnmanagedType.LPWStr)]
public string Make;
[MarshalAs(UnmanagedType.LPWStr)]
public string Model;
[MarshalAs(UnmanagedType.LPWStr)]
public string MSRP;
}
public VINDecoder()
{
//
// TODO: Add constructor logic here
//
}
public VehicleInformation Decode(string VIN)
{
VehicleInformation vi = new VehicleInformation();
vi.Make = "Honda";
vi.Model = "Accord";
vi.Year = "2005";
vi.MSRP = "23000";
return vi;
}
}
VB Cod
-----------------------------------------------------------------------------------------
Public Function Test()
Dim lVINDecoder As VINDecoder.VINDecoder
Set lVINDecoder = New VINDecoder.VINDecoder
Dim vi As VehicleInformation '<---
Error occurs here
Set vi = lVINDecoder.Decode("Test")
Debug.Print vi.Make
End Function
structure. I am registering the assembly for COM interop and can reference
the assembly in VB (Actually an Acces 2000 Code Module). I can instantiate
the object in VB but when I declare the variable for the returning structure
I get the following error.
Variable uses and automation type not supported Visual Basic.
Also, if I declare the variable as an Object, the error occurs when I call
the method.
Here is my code below...
C# Cod
---------------------------------------------------------------------------------------------
[GuidAttribute("B7D043BD-1003-4c6e-9050-0D0C4D93E213")]
[ClassInterface(ClassInterfaceType.AutoDual)]
public class VINDecoder
{
[StructLayout(LayoutKind.Sequential)]
[GuidAttribute("C39A4B1A-9186-40d8-BB26-CEE38D92A084")]
public struct VehicleInformation
{
[MarshalAs(UnmanagedType.LPWStr)]
public string Year;
[MarshalAs(UnmanagedType.LPWStr)]
public string Make;
[MarshalAs(UnmanagedType.LPWStr)]
public string Model;
[MarshalAs(UnmanagedType.LPWStr)]
public string MSRP;
}
public VINDecoder()
{
//
// TODO: Add constructor logic here
//
}
public VehicleInformation Decode(string VIN)
{
VehicleInformation vi = new VehicleInformation();
vi.Make = "Honda";
vi.Model = "Accord";
vi.Year = "2005";
vi.MSRP = "23000";
return vi;
}
}
VB Cod
-----------------------------------------------------------------------------------------
Public Function Test()
Dim lVINDecoder As VINDecoder.VINDecoder
Set lVINDecoder = New VINDecoder.VINDecoder
Dim vi As VehicleInformation '<---
Error occurs here
Set vi = lVINDecoder.Decode("Test")
Debug.Print vi.Make
End Function