非托管代码 [英] Unmanaged code

查看:105
本文介绍了非托管代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我遇到了以下问题:

我有一个变量

Hello,

I''ved came accross the following problem :

I have a variable

IntPtr pointer

,我知道我已经为其分配了一个点结构(x和y为浮点数).
我需要获取x值.
如果尝试编写x = pointer-> x,我会得到:"*和->运算符必须应用于指针".
我怎么能得到指针-> x的值?

在此先谢谢您!

to which I know that I have assigned a point structure ( x and y as floats ) .
I need to get the x value.
If I try to write x=pointer->x I get : "The * and -> operators must be applied to a pointer".
How could I get the value of pointer->x ?

Thanks in advance !

推荐答案

您首先需要创建一个指向point结构的指针并将其指针对象投射到该结构,然后您可以通过以下方式访问该结构的内容点参考.像这样的东西:
You first need to create a pointer to a point structure and cast your pointer object to it, then you can access the structure contents through the point reference. Something like:
IntPtr pointer = ...// your initialization here
Point* pt = (Point*)pointer;
float fx = pt->x;


我在这里可能会觉得很陌生,但是您的主题行和标记很少提供有关您使用哪种语言(例如C ++,C ++/CLI,C#)的线索.


I may be wide of the mark here but your subject line and tag gives very few clues as to what language you are using (i.e C++, C++/CLI, C#).


它"自从我做过C ++以来已经有一段时间了,但是尝试pointer.x
It''s been a while since I did any C++, but try pointer.x


我相信您可能必须使用这样的语法.和John一样,自从我从事C ++工作以来已经很长时间了,所以我可能只提供了无用的信息,但是在我可能没错的情况下……
I believe you may have to use syntax like this. Like John, it has been a very long time since I''ve done work in C++, so I might just be providing useless info, but on the off chance that I''m right...
*pointer.x


((point)*pointer).x


这篇关于非托管代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆