Jon,
Thanks for your reply. Here is a code snippet. It is not complete but it is
small.
IJDPosition, iLogicalDistPor t are COM interfaces defined in VC++ idl files.
DPosoition is COM class ( an ATL object ).
AutoMath.IJDPos ition pos = null;
pos = new AutoMath.DPosit ionClass();
iLogicalDistPor t.SetCenterLoca tion((NozzleEnt ities.IJDPositi on)pos); //This
throws Specified cast in not valid exception.
Why cast is needed :
The iLogicalDistPor t is in defined in the idl file of
NozzleEntities VC++ project. Following is the idl file:
import "AutoMath.i dl";
interface IJLogicalDistPo rt : IDispatch
{
[id(2), helpstring("met hod GetCenterLocati on")] HRESULT
GetCenterLocati on([out,retval] IJDPosition ** ppPosition);
[id(4), helpstring("met hod SetCenterLocati on")] HRESULT
SetCenterLocati on([in] IJDPosition * pPostion);
};
library NozzleEntities
{
coclass DistribPorts
{
[default] interface IDispatch;
interface IJLogicalDistPo rt;
};
}
Since the object is in the type library of NozzleEntities, the method is
expecting NozzleEntities. IJDPosition as argument.
I can only create AutoMath.DPosit ionClass(), 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*@discussion s.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.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too