.NET

.NET

Reply
Active Contributor
Basha Sk
Posts: 43
Registered: ‎11-07-2006
Message 1 of 5 (260 Views)

Passing reference from C# to VB dll

260 Views, 4 Replies
11-28-2006 05:59 AM
Hi All,
I have written a Function in VB6.0 and made it as a dll. I have given this dll as a reference to a C# application. I have to pass an object to this VB dll as a parameter from C#. But i am getting error while passing the object. Here is the Coding

DemoProject.DemoClass DP = new DemoProject.DemoClass(); Autodesk.AutoCAD.Interop.Common.AcadObject Obj = e.DBObject;
DP.GetObjFromParent(ref Obj );

I am getting error at above line. Any help would be greatly appreciated. Thanks in advance.

Regards,
Basha
*Norman Yuan
Message 2 of 5 (260 Views)

Re: Passing reference from C# to VB dll

11-28-2006 06:58 AM in reply to: Basha Sk
What does the VB DLL function look like? What type is the argument of the
function? What is the error? It seems that the VB DLL function does not
recognise the type DBObject in Autodesk.AutoCAD.DatabaseServices namespace
(of course).

Assume the VB DLL function's argument is a AcadObject type, like

Public Function GetObjFromParent(obj As AcadObject) As ....

End Function

Then you should pass an AcadObject, not DBObject. Since DBObject and Entity
object in Autodesk.AutoCAD.Database Services namespace have a property
"AcadObject", which returns Acad COM object "AcadObject", you could try
this:

Autodesk.AutoCAD.Interop.Common.AcadObject Obj = e.DBObject.AcadObject;



wrote in message news:5408074@discussion.autodesk.com...
Hi All,
I have written a Function in VB6.0 and made it as a dll. I have
given this dll as a reference to a C# application. I have to pass an object
to this VB dll as a parameter from C#. But i am getting error while passing
the object. Here is the Coding

DemoProject.DemoClass DP = new DemoProject.DemoClass();
Autodesk.AutoCAD.Interop.Common.AcadObject Obj = e.DBObject;
DP.GetObjFromParent(ref Obj );

I am getting error at above line. Any help would be greatly appreciated.
Thanks in advance.

Regards,
Basha
Active Contributor
Basha Sk
Posts: 43
Registered: ‎11-07-2006
Message 3 of 5 (260 Views)

Re: Passing reference from C# to VB dll

11-28-2006 10:11 PM in reply to: Basha Sk
Hi Norman,

My function in VB look like below
Public Function GetObjFromParent(Fname as String, Obj As AcadObject)
' My Stuff
End Function

My function in C#.Net look like this

public void objAppended(object o, ObjectEventArgs e)
{
DemoProject.DemoClass DP= new DemoProject.DemoClass();
string Fname = "E:\\New Demo\\Demo.xml";
Autodesk.AutoCAD.Interop.Common.AcadObject Obj = e.DBObject.AcadObject;
DP.GetObjFromParent(ref Fname,ref Obj );
}
Error1: Cannot implicitly convert type 'object' to 'Autodesk.AutoCAD.Interop.Common.AcadObject'. An explicit conversion exists (are you missing a cast?).
Error2: No overload for method 'GetObjFromParent' takes '2' arguments

Hope this clearly explains my problem.

Regards,
Basha
*Norman Yuan
Message 4 of 5 (260 Views)

Re: Passing reference from C# to VB dll

11-29-2006 06:08 AM in reply to: Basha Sk
Sorry for the minor mistake in my previous reply:

DBObject's AcadObject property is actually returns an object of "object"
type, not "AcadObject" type, although the property is named AcadObject. So,
you need explicitly cast it as AcadObject before assigning it to an
AcadObject variable:

Autodesk.AutoCAD.Interop.Common.AcadObject Obj =
(Autodesk.AutoCAD.Interop.Common.AcadObject) e.DBObject.AcadObject;

As for Error2, in your original post, the VB function has only one argument,
have you re-written the VB DLL but forgotten to update the reference?


wrote in message news:5409039@discussion.autodesk.com...
Hi Norman,

My function in VB look like below
Public Function GetObjFromParent(Fname as String, Obj As AcadObject)
' My Stuff
End Function

My function in C#.Net look like this

public void objAppended(object o, ObjectEventArgs e)
{
DemoProject.DemoClass DP= new DemoProject.DemoClass();
string Fname = "E:\\New Demo\\Demo.xml";
Autodesk.AutoCAD.Interop.Common.AcadObject Obj = e.DBObject.AcadObject;
DP.GetObjFromParent(ref Fname,ref Obj );
}
Error1: Cannot implicitly convert type 'object' to
'Autodesk.AutoCAD.Interop.Common.AcadObject'. An explicit conversion exists
(are you missing a cast?).
Error2: No overload for method 'GetObjFromParent' takes '2' arguments

Hope this clearly explains my problem.

Regards,
Basha
Active Contributor
Basha Sk
Posts: 43
Registered: ‎11-07-2006
Message 5 of 5 (260 Views)

Re: Passing reference from C# to VB dll

11-29-2006 10:32 PM in reply to: Basha Sk
Hi Norman,
Thank you for your time. Actually i am passing two parameters, one is the string and the other is an object. In my original post i haven't specified the 1st argument. Now the first error was resolved but still i am getting the 2nd error.

Error2: No overload for method 'GetObjFromParent' takes '2' arguments

Thanks in Advance,

Regards,
Basha
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.