Jon,
Thanks for your reply. Here is a code snippet. It is not complete but it is
small.
IJDPosition, iLogicalDistPort are COM interfaces defined in VC++ idl files.
DPosoition is COM class ( an ATL object ).
AutoMath.IJDPosition pos = null;
pos = new AutoMath.DPositionClass();
iLogicalDistPort.SetCenterLocation((NozzleEntities .IJDPosition)pos); //This
throws Specified cast in not valid exception.
Why cast is needed :
The iLogicalDistPort is in defined in the idl file of
NozzleEntities VC++ project. Following is the idl file:
import "AutoMath.idl";
interface IJLogicalDistPort : IDispatch
{
[id(2), helpstring("method GetCenterLocation")] HRESULT
GetCenterLocation([out,retval] IJDPosition ** ppPosition);
[id(4), helpstring("method SetCenterLocation")] HRESULT
SetCenterLocation([in] IJDPosition * pPostion);
};
library NozzleEntities
{
coclass DistribPorts
{
[default] interface IDispatch;
interface IJLogicalDistPort;
};
}
Since the object is in the type library of NozzleEntities, the method is
expecting NozzleEntities.IJDPosition as argument.
I can only create AutoMath.DPositionClass(), since that is where my
DPosition class is implemented.
I hope the scenario is clear. If not I can provide more details. Basically
I am creating an unmanaged object and calling a method on it in managed code.
My main question is, this used to work in v1.0. I haven't make any changes
except moving to v1.1. Now I get the exception. Is there any known problem
or known solution for this problem.
Thanks,
Raj
"Jon Skeet [C# MVP]" wrote:
Raj <Ra*@discussions.microsoft.com> wrote: I have a c# program in which I used cast. That worked perfectly on .Net
platform 1.0. When I moved to .Net 2003, I am getting the execption
"Specified cast is not valid". I have not made any changes to the code. Is
there any difference in project settings or something else between v1.0 and
v1.1?
Could you post a short but complete program which demonstrates the
problem?
See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too