开发者

is there something equivalent to 'Address of' or offset operator in .net?

We have nested stuctures as such, used as an interface for some device drivers. On occasion we have to update individual elements. An 'address of' operator would be helpful, but an 'offset' function or operator is what I'm really looking for, but not sure how to go about it. In other words, how far is structureN.elementX away from the start of the structure in bytes?

[StructLayout(LayoutKind.Sequential)]
public struct s1
{
    UInt16 elem1;   
    UInt16 elem2;
    UInt16 elem3;
}

[StructLayout(LayoutKind.Sequential)]
public struct s2
{
    UInt16 elem1;   
    UInt16 elem2;
    UInt16 elem3;
}

[StructLayout(LayoutKind.Sequential)]
public struct driver
{
    public S1 s1;
    public S2 s2;
}

For instance we need to send the device driver some data to update driver.s1.elem3, by way of providing an offset address, data block and length. We开发者_高级运维 would update our local copy, then call the device api with the afore mentioned data. Not sure I have to do this with 'unsafe' method calls. Any help?


Consider working with your device and user interface developers to abstract this implementation into more appropriate components.

A UI that directly interacts in such a low-level manner with device drivers will be difficult to maintain, test, and create (obviously - no AddressOf is an issue already ;-).

Consider restructuring into both a UI project/application (.NET), and then either an unmanaged library you can p/invoke or use COM to talk to that does the device driver work... or see if managed .NET C++ can get you part of the way there.

Sorry for not directly answering the question, but I argue an app architecture change may be more important here for this instance than a technical answer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜