|
-
Jul 20th, 2007, 06:19 PM
#1
[RESOLVED] Converting code question?
Hi guys, I use VB.Net and I need to convert this VB 6 code to VB.Net.
vb Code:
Type WAVEINCAPS
wMid As Integer
wPid As Integer
vDriverVersion As Long
szPname As String * 32
dwFormats As Long
wChannels As Integer
End Type
The only problem I have is this line
Is this some sort of indication of a size?
Thanks in advance!
-
Jul 20th, 2007, 06:45 PM
#2
Addicted Member
Re: Converting code question?
I think you are in the wrong forum...but my small knowladge of VB. net tells me that you need to see something about Marshal to allocate stuff, see this, translated in to something like this:
vbnet Code:
Dim MyPointer As string = Marshal.AllocHGlobal(4)
Marshal.WriteInt32(MyPointer, 255)
' some more code here (call to
' unmanaged code for example)
' free memory
Marshal.FreeHGlobal(MyPointer)
Note: Code not tested
-
Jul 20th, 2007, 08:38 PM
#3
Re: Converting code question?
Yes that is an indicator of size. It dimensions a string 32 bytes long.
for that one line, here is the equivalent vb.net line:
Code:
<VBFixedString(33),System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray,SizeConst:=32)> Public szPName() As Char
note that i have it set to 33. that is because a string has a terminating null bit, and marshallas doesn't take that into account and you have to manually set it.
-
Jul 20th, 2007, 08:55 PM
#4
Re: Converting code question?
Thank you Lord Orwell. That is what I was thinking. One more question, Is VBFixedString(33) needed? I saw a C# example that didn't have VBFixedString class instance.
Last edited by VBDT; Jul 20th, 2007 at 09:07 PM.
-
Jul 20th, 2007, 09:06 PM
#5
Re: Converting code question?
i am by no means an expert, but that is supposedly how it knows what size to make the fixed string.
I have no idea what you are using the structure for, so i can't say any more than that.
-
Jul 20th, 2007, 09:11 PM
#6
Re: Converting code question?
Well, I am tring to use this structure in "waveInGetDevCaps" Api function. The reason I ask because I saw a C# example that didn't have VBFixedString class instance. Anyways thank you very much.
Last edited by VBDT; Jul 20th, 2007 at 09:27 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|