Reputation: 16622
This is my FoxPro class:
DEFINE CLASS clscem AS custom
Height = 102
Width = 212
publicproperty = "this is my initial value"
pubprop = ""
Name = "clscem"
ENDDEFINE
and this is my form1.scx code:
objSinif = CREATEOBJECT("SinifDeneme.Class")
donenObjSinif = objSinif.f_Metot(thisform.CLSCEM1)
thisform.command1.Caption = donenObjSinif.M_SitringProp
I am calling .NET dll as COM object from FoxPro. This is my .NET class of DLL:
using System;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
namespace ClsLib
{
[ClassInterface(ClassInterfaceType.AutoDual)]
[ProgId("SinifDeneme.Class")]
[ComVisible(true)]
public class Sinif
{
public string SitringField;
public string M_SitringProp { get; set; }
public Sinif f_Metot(object oj)
{
StreamWriter sw = File.CreateText(Path.GetDirectoryName(Assembly.GetAssembly(typeof(Sinif)).Location )+ "\\obje.txt");
Type myObjectType = oj.GetType();
//Get public properties
PropertyInfo[] propertyInfo = myObjectType.GetProperties();
sw.WriteLine("------------- PROPERTY --------------");
foreach (PropertyInfo info in propertyInfo)
{
sw.WriteLine("Name:"+info.Name);
sw.WriteLine("PropertyType:"+info.PropertyType);
sw.WriteLine("GetValue():" + info.GetValue(oj,null));
sw.WriteLine("-------------");
}
FieldInfo[] fieldInfo = myObjectType.GetFields();
sw.WriteLine("------------- FIELDS --------------");
foreach (FieldInfo info in fieldInfo)
{
sw.WriteLine("Name:" + info.Name);
sw.WriteLine("AssemblyQualifiedName:" + info.FieldType.AssemblyQualifiedName);
sw.WriteLine("GetValue():" + info.GetValue(oj));
sw.WriteLine("-------------");
}
sw.Flush();
sw.Close();
sw.Dispose();
return new Sinif()
{
M_SitringProp="SitringProp propertisi",
SitringField="Sitring fieldı"
};
}
}
}
But I couldn't write the properties or fields of FoxPro object. Whereas I can set the property of C# object whicj was returned by f_Metot of DLL. Where is the problem to get object properties which is coming from FoxPro?
I don't know the COM object conversion. Would you please explain?
Thanks in advance....
Upvotes: 0
Views: 2064
Reputation: 73243
Rick Strahl did a three part article set on interop between VFP and .Net - although it's a little old, I would expect you will find your answer in one of them, probably the first.
Upvotes: 1