Reputation: 19117
Here is my class and associated interface:
[Guid("xx")]
[ComVisible(true)]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IStudentItem
{
string Type { get; set; }
DateTime Week { get; set; }
int Study { get; set; }
}
[Guid("yy")]
[ClassInterface(ClassInterfaceType.None)]
[ComVisible(true)]
public class StudentItem : IStudentItem
{
public string Type { get; set; }
public DateTime Week { get; set; }
public int Study { get; set; }
}
As you can see, Study
is defined as a int
.
But in the MFC side, when I am using this property, I end up with a long
:
long lStudyNumber = 0;
if(SUCCEEDED(studentItem->get_Study(&lStudyNumber)))
oEntry.iStudyPoint = static_cast<int>(lStudyNumber);
My DLL is in both 86x and 64x editions. Is there any way to get the get_Study
property to return a integer
instead?
Upvotes: 0
Views: 75
Reputation: 15365
Why do you want this. Use an appropriate type that makes sense for the data in all OS and bitness.
You can use int. COMs know the __int3264 type in the MIDL compiler and inside the TLB (type libraries) and even a VARIANT has the VT_INT type.
So also an IDispatch driven automation will receive the correspondent value.
But be aware that even than there is some marshaling, when you have 64bit external COM Server and a 32bit process asks for data, the marshaller will transform the previous VT_INT into a VT_I8... On the other hand a 32bit external COM server will return an VT_INT as a VT_I4 to a 64bit process...
Upvotes: 1