C#相当于VB6'Type' [英] C# equivalent to VB6 'Type'

查看:222
本文介绍了C#相当于VB6'Type'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图端口一个相当大的来源从VB6到C#。这是不容易的任务 - 尤其是对我来说是相当新的C#.NET。此源使用大量的Windows API以及众多类型。我知道是没有的相当于的在C#VB6的类型,但我敢肯定有要达到相同的结果的方法。

I am trying to port a rather large source from VB6 to C#. This is no easy task - especially for me being fairly new to C#.net. This source uses numerous Windows APIs as well as numerous Types. I know that there is no equivalent to the VB6 Type in C# but I'm sure there is a way to reach the same outcome. I will post some code below to further explain my request.

VB6:

VB6 $ C>专用类型ICONDIRENTRY
bWidth为字节
bHeight为字节
bColorCount为字节
bReserved为字节
wPlanes作为整数
wBitCount作为整数
dwBytesInRes只要
dwImageOffset只要
端输入

尺寸tICONDIRENTRY()作为ICONDIRENTRY

使用ReDim tICONDIRENTRY(tICONDIR.idCount - 1)

。对于i = 0到tICONDIR.idCount - 1
调用的ReadFile(lFile,tICONDIRENTRY(I),莱恩(tICONDIRENTRY(I)),LRET,BYVAL 0安培)
下一页我

Private Type ICONDIRENTRY bWidth As Byte bHeight As Byte bColorCount As Byte bReserved As Byte wPlanes As Integer wBitCount As Integer dwBytesInRes As Long dwImageOffset As Long End Type Dim tICONDIRENTRY() As ICONDIRENTRY ReDim tICONDIRENTRY(tICONDIR.idCount - 1) For i = 0 To tICONDIR.idCount - 1 Call ReadFile(lFile, tICONDIRENTRY(i), Len(tICONDIRENTRY(i)), lRet, ByVal 0&) Next i

我一直在使用结构和类尝试 - 但至今没有运气

I have tried using structs and classes - but no luck so far.

我想看到这种类型的结构转换,但如果有人有任何线索,如何将整个事情将它转换将是令人难以置信的帮助。我花了无数的时间在这个小项目了。

I would like to see a conversion of this Type structure, but if someone had any clue as to how to convert the entire thing it would be unbelievably helpful. I have spent countless hours on this small project already.

如果这有什么差别,这是只用于教育目的。

If it makes any difference, this is strictly for educational purposes only.

感谢您的帮助提前,
埃文

Thank you for any help in advance, Evan

推荐答案

结构是等价的。你会表达出来是这样的:

struct is the equivalent. You'd express it like this:

struct IconDirEntry {
    public byte Width;
    public byte Height;
    public byte ColorCount;
    public byte Reserved;
    public int Planes;
    public int BitCount;
    public long BytesInRes;
    public long ImageOffset;
}

您声明一个变量是这样的:

You declare a variable like this:

IconDirEntry entry;



一般情况下,在C#中,类型前缀都没有用,也不是全部大写,除了可能为常数。 结构是在C#中的值类型,这样就意味着他们总是按值传递。它看起来像你传递他们对正在填充它们的方法。如果您希望使用,您将不得不使用类。

Generally, in C#, type prefixes are not used, nor are all caps, except possibly for constants. structs are value types in C#, so that means that they are always passed by value. It looks like you're passing them in to a method that's populating them. If you want that usage, you'll have to use classes.

这篇关于C#相当于VB6'Type'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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