Click here to Skip to main content
15,918,404 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
vb.code //.BAS file
VB
Type Radio
    Start As Long
    Stop As Long
    MaxVal As Double 
end Type

and following struct is in dll

VB
typedef struct
{
    long x;
    byval y;
}Radio;


when I write code in c#

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
C#
Radio r=new Radio

r.x=0;
but how can i declare variable in Type Raiod which is done vb/ .bas file
Posted
Comments
Sergey Alexandrovich Kryukov 28-May-14 23:53pm    
First of all, what do you mean by "VB"? Why "converting" it? (It's "translating", not "converting").
Why using StructLayoutAttribute? Who cares about the layout, why? It is used for interop, but you are translating.
—SA

1 solution

No, you are not "trying MyStruct as type", not even close. The phrase Type 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:
C#
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
 
Share this answer
 
v2
Comments
krishpraj123 29-May-14 18:27pm    
Sir I was trying to call VB6 dll in c#.
in that dll the struct is defined.
I just wanted to know how to use TYPE defined in VB to C#.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900