cannot convert from 'System.IntPtr' to 'int'

  • Thread starter Thread starter mp
  • Start date Start date
M

mp

I get the error in the subject line from the following line of code:
SubentityId subEnt =

new SubentityId(SubentityType.Null, System.IntPtr.Zero);

the second argument of that method is defined as Int.



this code comes from a website offereing autocad info in dotnet

the url to the project is:

http://through-the-interface.typepa...olor-of-a-nested-entity-using-net-take-2.html



I'm presuming the code as shown compiles fine for the author so I dont' know
why it won't for me...maybe because i'm on express version?

thanks for any ideas

mark
 
I get the error in the subject line from the following line of code:
SubentityId subEnt =

new SubentityId(SubentityType.Null, System.IntPtr.Zero);

the second argument of that method is defined as Int.

Well, IntPtr.Zero ultimately returns a pointer initialized to the zero
address, that is, the pointer value itself is 0. The cheap and cheesy way
would be to simply use 0 in the function call. However, a slightly more
elegant way would be use IntPtr's ToInt32() method:

= new SubentityId(SubentityType.Null, System.IntPtr.Zero.ToInt32());

None of this explains why the code was expected to work as-is. Perhaps the
method signature was changed and the text on the Web page is newer or older
than the change. Or it could be a typo.
 
I get the error in the subject line from the following line of code:
SubentityId subEnt =

new SubentityId(SubentityType.Null, System.IntPtr.Zero);

the second argument of that method is defined as Int.

this code comes from a website offereing autocad info in dotnet

the url to the project is:

http://through-the-interface.typepa...olor-of-a-nested-entity-using-net-take-2.html

I'm presuming the code as shown compiles fine for the author so I dont' know
why it won't for me...maybe because i'm on express version?

Either that method did take an IntPtr when it was compiled
or did never did compile.

Note that there are no quality control on blog posts.

Arne
 
Arne Vajhøj said:
Either that method did take an IntPtr when it was compiled
or did never did compile.

Note that there are no quality control on blog posts.

Arne
true enough but as far as I can tell that guy is well thought of in the
autocad community, so I assume it's me doing something wrong.
Thanks
mark
 
Jeff Johnson said:
Well, IntPtr.Zero ultimately returns a pointer initialized to the zero
address, that is, the pointer value itself is 0. The cheap and cheesy way
would be to simply use 0 in the function call.

i thought of that and said....naahhh no one would do it that way....:-)

However, a slightly more
elegant way would be use IntPtr's ToInt32() method:

= new SubentityId(SubentityType.Null, System.IntPtr.Zero.ToInt32());
sheesh, why didnt I think to try putting a dot after the zero
object?....still not used to these cascading series of objects
i tried casting it to an int but not sure how that should look in c#

None of this explains why the code was expected to work as-is. Perhaps the
method signature was changed and the text on the Web page is newer or
older than the change. Or it could be a typo.

Thanks for the solution
Mark
 
Back
Top