Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

124 views
Skip to first unread message

mp

unread,
Sep 28, 2010, 11:00:40 AM9/28/10
to
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.typepad.com/through_the_interface/2010/08/changing-the-layer-or-color-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


Jeff Johnson

unread,
Sep 28, 2010, 11:46:06 AM9/28/10
to
"mp" <nos...@Thanks.com> wrote in message
news:i7svun$hcn$1...@news.eternal-september.org...

>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.


Arne Vajhøj

unread,
Sep 28, 2010, 2:56:52 PM9/28/10
to

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

mp

unread,
Sep 29, 2010, 1:40:57 AM9/29/10
to

"Arne Vajhøj" <ar...@vajhoej.dk> wrote in message
news:4ca23a63$0$50455$1472...@news.sunsite.dk...
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


mp

unread,
Sep 29, 2010, 1:45:14 AM9/29/10
to

"Jeff Johnson" <i....@enough.spam> wrote in message
news:i7t2k5$hq8$1...@news.eternal-september.org...

> "mp" <nos...@Thanks.com> wrote in message
> news:i7svun$hcn$1...@news.eternal-september.org...
>
>>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.

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


0 new messages