API structure & function conversion [ vb6 -> c# ]

  • Thread starter Thread starter harry
  • Start date Start date
H

harry

hi everybody!

maybe there is somebody out there, who can give me a
little bit of help with this piece of vb6 code, I want
to 'translate' into c# - but I cannot handle it.


Type uddtData
aLongVariable1 as Long
aFixedLenghtNullTermString1 as String * 60
aFixedLenghtNullTermString2 as String * 34
aLongVariable2 as Long
End Type

Declare Function DoSomething Lib "Any.dll" (ByRef
hAnyHandle as Long, ByRef Data as uddtData, ByVal anyLong
as Long) as Long


I try to not despair too much of all the structure
attributes, marshalling attributes and
System.Runtime.InteropServices - but I'm about to give up.
any pretty good ideas?
many thanx in advance! and a happy new year, of course!

bye - h.
 
Harry,

The declaration you want is as follows:

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public struct uddtData
{
public int aLongVariable1;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=60)]
public string aFixedLengthNullTermString1;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=34)]
public string aFixedLengthNullTermString2;
public int aLongVariable2;
}

The key is in specifying the fixed width strings.

Hope this helps.
 
Back
Top