将vb dll转换为c#时出现问题 [英] Problem in converting vb dll to c#
问题描述
vb.code //.BAS文件
类型电台
开始作为 < span class =code-keyword>长
停止 作为 长
MaxVal 作为 Double
end 类型
和以下struct在dll中
typedef struct
{
long x;
byval y;
}电台;
当我用c编写代码时
< pre lang =cs> class calldll
{
[StructLayout(LayoutKind.Sequential)]
struct 收音机
{
long x;
Intptr y;
double MaxVal;
}
// 但是当我尝试使用Mystruct作为类型时,它给出了错误。
类型无线电
{
int z; // 错误 - 期望获取或设置访问者
// 再次在这里我需要一些声明参数
}
}
我试图将struct更改为类,我也试图删除Type数据类型,它仍然给出了这个错误。
如何在C#中再次使用Radio作为数据类型。
通过将Radio及其变量公开,我可以访问其变量
收音机r = 新收音机
rx = 0;
但我如何在Type Raiod中声明变量vb / .bas文件
不,你不是尝试MyStruct类型,甚至没有关闭。短语Type Radio {int z; }
是完全的胡言乱语;我不知道它可能意味着什么,你的想法是什么。
使用类型的东西可能有很多含义。该类型最简单和最重要的用途是创建某种类型的对象,实例化:
struct Radio {
internal long x; // 否则它将是私有的,无权访问anuwhere
// Intptr y; //刮刮了,Intptr未定义
// 此外,我太害怕了想象你会做什么
// 如果是System.IntPtr;你会怎么做?
内部 double MaxVal;
}
无线电广播= 新 Radio();
radio.x = 10012 ;
// ...
还有静态成员和静态类,OOP,反射,属性......等等。您需要从头开始学习整个编程领域。请参阅.NET和语言手册,祝你好运。祝你好运。
-SA
vb.code //.BAS file
Type Radio
Start As Long
Stop As Long
MaxVal As Double
end Type
and following struct is in dll
typedef struct
{
long x;
byval y;
}Radio;
when I write code in c#
class calldll
{
[StructLayout(LayoutKind.Sequential)]
struct Radio
{
long x;
Intptr y;
double MaxVal ;
}
// but when i try to use Mystruct as type it gives error.
Type Radio
{
int z; // Error - A get or set accessor expected
// again here I have to some declare parameters
}
}
I tried to change struct into class and also i tried to remove Type datatype ,it still gives that error.
How I can use Radio as datatype again in C#.
By making Radio and its variable public I can access its variable
Radio r=new Radio
r.x=0;
but how can i declare variable in Type Raiod which is done vb/ .bas file
No, you are not "trying MyStruct as type", not even close. The phraseType Radio { int z; }
is complete gibberish; I have no idea what it could possibly mean, what was your idea.
"Using something a type" could have many meanings. The simplest and most important use of the type is creating objects of some type, instantiating it:
struct Radio{ internal long x; // otherwise it would be private, with no access to it anuwhere // Intptr y; // scratch is out, Intptr is not defined // besides, I am too terrified to imagine what would you do // if it was System.IntPtr; what would you do with that internal double MaxVal; } Radio radio = new Radio(); radio.x = 10012; //...
There are also static members and static classes, OOP, reflection, attributes… and a lot more. You need to learn the whole programming field pretty much from scratch. Take some manual on .NET and language and… good luck.
—SA
这篇关于将vb dll转换为c#时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!