473,320 Members | 1,976 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

szPname As String * MAXPNAMELEN (How to declare)

Hi All,
How to declare the following statement in following structure.

szPname As String * MAXPNAMELEN
Public Structure MIXERCAPS
public wMid As Integer
public wPid As Integer
public vDriverVersion As Long
public szPname As String * MAXPNAMELEN
public fdwSupport As Long
public cDestinations As Long
End Structure

Thanks and Regards.
Sakharam Phapale.
Nov 21 '05 #1
5 4577
On 2004-10-07, Sakharam Phapale <sp******@annetsite.com> wrote:
Hi All,
How to declare the following statement in following structure.

szPname As String * MAXPNAMELEN
Public Structure MIXERCAPS
public wMid As Integer
public wPid As Integer
public vDriverVersion As Long
public szPname As String * MAXPNAMELEN
public fdwSupport As Long
public cDestinations As Long
End Structure

Thanks and Regards.
Sakharam Phapale.


Looking at the MSDN docs now...... Ok:

' Replace XX with correct value...
Public Const MAXPNAMELEN As Integer = XX

<StructLayout (LayoutKind.Sequential, CharSet := CharSet.Auto)> _
Public Structure MIXERCAPS
Public wMid As Short
Public wPid As Short

' You'll have to see what type MMVERSION really is,
' but from the description it sounds like a 2-byte integer
' also known as a WORD in API speak and a Short in VB.NET
Public vDriverVersion As Short

<MarshalAs (UnmanagedType.ByValTStr, SizeConst := MAXPNAMELEN)>
Public szPname As String

Public fdwSupport As Integer
Public cDestinations As Integer
End Structure

Be aware that VB6 declarations are not going to be valid for most API
calls. Data types have changed size. Here is a small table to sum up
the differences:

Data Type VB6 Size VB.NET Size
___________________________________
Byte 8-bit 8-bit
Short N/A 16-bit (same size as VB6 Integer)
Integer 16-bit 32-bit
Long 32-bit 64-bit

So, basically when calling api calls from VB.NET - use Short where you
used integer in VB6 and Integer where you used Long. You can use Long
where you would have used Currency in VB6.

Also, notice the CharSet attribute on the structure. This is done so
that it will be converted to the proper charset for the current
platform. This eliminates a lot of the problems with calling API calls
in VB6 - you couldn't call Unicode functions, at least not with out some
hacks :) To use this structure in the function, the CharSet attribute
will have to be set there as well - but VB.NET Declare has a way of
handling that (I'm going to assume your using mixerGetDevCaps)...

Public Declare Auto Function mixerGetDevCaps Lib "winmm.dll" _
(ByVal uMxId As System.IntPtr, _
ByRef pmxcaps As MIXERCAPS, _
ByVal cbmxcaps As Integer) As Integer
By using the Auto clause of the declare statement we avoid having to
alias this function to the A version, because the runtime will call the
function most appropriate to the current platform - which is the W
version on NT based OS's.

--
Tom Shelton [MVP]
Nov 21 '05 #2
Hi Tom,

I am using the structure "MIXERLINE" which includes structure "TARGET".
I have used following statement
mxl.cbStruct = Len(mxl)

This should gives me 168 as length of structure mxl which is "MixerLine"
type, but it gives me 68. It doesn't include the string variables.

What is the reason?

I am also using following API function which fills detail of mixer control
in mxl structure which includs short and full name.

ret = mixerGetLineInfo(hMixer, mxl, MIXER_GETLINEINFOF_COMPONENTTYPE)

ret comes as 11. Above function doesn't work.

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _

Public Structure Target

Public dwType As Integer

Public dwDeviceID As Integer

Public wMid As Integer

Public wPid As Int16

Public vDriverVersion As Int16

<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MAXPNAMELEN)> _

Public szPname As String

End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _

Public Structure MIXERLINE

Public cbStruct As Integer

Public dwDestination As Integer

Public dwSource As Integer

Public dwLineID As Integer

Public fdwLine As Integer

Public dwUser As Integer

Public dwComponentType As Integer

Public cChannels As Integer

Public cConnections As Integer

Public cControls As Integer

<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MIXER_SHORT_NAME_CHARS)> _

Public szShortName As String

<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MIXER_LONG_NAME_CHARS)> _

Public szName As String

Public tTarget As Target

End Structure
Waiting for your respose.

Thanks

Sakharam Phapale
"Tom Shelton" <to*@YOUKNOWTHEDRILLmtogden.com> wrote in message
news:u5**************@TK2MSFTNGP12.phx.gbl...
On 2004-10-07, Sakharam Phapale <sp******@annetsite.com> wrote:
Hi All,
How to declare the following statement in following structure.

szPname As String * MAXPNAMELEN
Public Structure MIXERCAPS
public wMid As Integer
public wPid As Integer
public vDriverVersion As Long
public szPname As String * MAXPNAMELEN
public fdwSupport As Long
public cDestinations As Long
End Structure

Thanks and Regards.
Sakharam Phapale.


Looking at the MSDN docs now...... Ok:

' Replace XX with correct value...
Public Const MAXPNAMELEN As Integer = XX

<StructLayout (LayoutKind.Sequential, CharSet := CharSet.Auto)> _
Public Structure MIXERCAPS
Public wMid As Short
Public wPid As Short

' You'll have to see what type MMVERSION really is,
' but from the description it sounds like a 2-byte integer
' also known as a WORD in API speak and a Short in VB.NET
Public vDriverVersion As Short

<MarshalAs (UnmanagedType.ByValTStr, SizeConst := MAXPNAMELEN)>
Public szPname As String

Public fdwSupport As Integer
Public cDestinations As Integer
End Structure

Be aware that VB6 declarations are not going to be valid for most API
calls. Data types have changed size. Here is a small table to sum up
the differences:

Data Type VB6 Size VB.NET Size
___________________________________
Byte 8-bit 8-bit
Short N/A 16-bit (same size as VB6 Integer)
Integer 16-bit 32-bit
Long 32-bit 64-bit

So, basically when calling api calls from VB.NET - use Short where you
used integer in VB6 and Integer where you used Long. You can use Long
where you would have used Currency in VB6.

Also, notice the CharSet attribute on the structure. This is done so
that it will be converted to the proper charset for the current
platform. This eliminates a lot of the problems with calling API calls
in VB6 - you couldn't call Unicode functions, at least not with out some
hacks :) To use this structure in the function, the CharSet attribute
will have to be set there as well - but VB.NET Declare has a way of
handling that (I'm going to assume your using mixerGetDevCaps)...

Public Declare Auto Function mixerGetDevCaps Lib "winmm.dll" _
(ByVal uMxId As System.IntPtr, _
ByRef pmxcaps As MIXERCAPS, _
ByVal cbmxcaps As Integer) As Integer
By using the Auto clause of the declare statement we avoid having to
alias this function to the A version, because the runtime will call the
function most appropriate to the current platform - which is the W
version on NT based OS's.

--
Tom Shelton [MVP]

Nov 21 '05 #3
On 2004-10-07, Sakharam Phapale <sp******@annetsite.com> wrote:
Hi Tom,

I am using the structure "MIXERLINE" which includes structure "TARGET".
I have used following statement
mxl.cbStruct = Len(mxl)

This should gives me 168 as length of structure mxl which is "MixerLine"
type, but it gives me 68. It doesn't include the string variables.

What is the reason?

User Marshal.SizeOf... This will give you the marshaled length, instead
of the .NET length. (Does that makes sense?)
I am also using following API function which fills detail of mixer control
in mxl structure which includs short and full name.

ret = mixerGetLineInfo(hMixer, mxl, MIXER_GETLINEINFOF_COMPONENTTYPE)

ret comes as 11. Above function doesn't work.

Are you declaring mixerGetLineInfo correctly? Should probably be:

Public Declare Auto Function mixerGetLineInfo Lib "winmm.dll" _
(ByVal hmxobj As System.IntPtr, _
ByRef pmxl As MIXERLINE, _
ByVal fdwInfo As Integer) As Integer
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _

Public Structure Target

Public dwType As Integer

Public dwDeviceID As Integer

Public wMid As Integer

Public wPid As Int16

Public vDriverVersion As Int16

<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MAXPNAMELEN)> _

Public szPname As String

End Structure

According to MSDN, your wMid should also be Short or Int16. I would
also verify the MMVERSION type - I'm assuming Int16 from the docs, but
you never know...


<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _

Public Structure MIXERLINE

Public cbStruct As Integer

Public dwDestination As Integer

Public dwSource As Integer

Public dwLineID As Integer

Public fdwLine As Integer

Public dwUser As Integer

Public dwComponentType As Integer

Public cChannels As Integer

Public cConnections As Integer

Public cControls As Integer

<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MIXER_SHORT_NAME_CHARS)> _

Public szShortName As String

<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MIXER_LONG_NAME_CHARS)> _

Public szName As String

Public tTarget As Target

End Structure
Waiting for your respose.

Thanks

Sakharam Phapale


The rest looks ok at first glance...

--
Tom Shelton [MVP]
Nov 21 '05 #4
Hi Tom,

Thanks for your reply. I have another query related to this.
I am using GlobalAlloc API to allocate memeory for structure "MIXERCONTROL"
And then I used following API function to get the mixer control iformation.
mixerGetLineControls(hMixer, mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE)

Everyhing goes right upto above statement.

Now I want to fill the allocated strucure by the pointer which returned by
above API function.

For that, I used API function CopyStructFromPtr(........)
Calling this function resulted application to crash without giving any
error.
I tried lot but I don't understand why?
Since the same code runs in VB6.0. well I am not been able to convert it to
..NET

Any Help will be really appriciated.

Thanks & Regards
Sakharam Phapale

"Tom Shelton" <to*@YOUKNOWTHEDRILLmtogden.com> wrote in message
news:uf*************@TK2MSFTNGP09.phx.gbl...
On 2004-10-07, Sakharam Phapale <sp******@annetsite.com> wrote:
Hi Tom,

I am using the structure "MIXERLINE" which includes structure "TARGET".
I have used following statement
mxl.cbStruct = Len(mxl)

This should gives me 168 as length of structure mxl which is "MixerLine"
type, but it gives me 68. It doesn't include the string variables.

What is the reason?


User Marshal.SizeOf... This will give you the marshaled length, instead
of the .NET length. (Does that makes sense?)
I am also using following API function which fills detail of mixer control in mxl structure which includs short and full name.

ret = mixerGetLineInfo(hMixer, mxl, MIXER_GETLINEINFOF_COMPONENTTYPE)

ret comes as 11. Above function doesn't work.


Are you declaring mixerGetLineInfo correctly? Should probably be:

Public Declare Auto Function mixerGetLineInfo Lib "winmm.dll" _
(ByVal hmxobj As System.IntPtr, _
ByRef pmxl As MIXERLINE, _
ByVal fdwInfo As Integer) As Integer

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _

Public Structure Target

Public dwType As Integer

Public dwDeviceID As Integer

Public wMid As Integer

Public wPid As Int16

Public vDriverVersion As Int16

<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MAXPNAMELEN)> _

Public szPname As String

End Structure


According to MSDN, your wMid should also be Short or Int16. I would
also verify the MMVERSION type - I'm assuming Int16 from the docs, but
you never know...


<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _

Public Structure MIXERLINE

Public cbStruct As Integer

Public dwDestination As Integer

Public dwSource As Integer

Public dwLineID As Integer

Public fdwLine As Integer

Public dwUser As Integer

Public dwComponentType As Integer

Public cChannels As Integer

Public cConnections As Integer

Public cControls As Integer

<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MIXER_SHORT_NAME_CHARS)> _

Public szShortName As String

<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MIXER_LONG_NAME_CHARS)> _

Public szName As String

Public tTarget As Target

End Structure
Waiting for your respose.

Thanks

Sakharam Phapale


The rest looks ok at first glance...

--
Tom Shelton [MVP]

Nov 21 '05 #5
In article <ei**************@TK2MSFTNGP09.phx.gbl>, Sakharam Phapale wrote:
Hi Tom,

Thanks for your reply. I have another query related to this.
I am using GlobalAlloc API to allocate memeory for structure "MIXERCONTROL"
And then I used following API function to get the mixer control iformation.
mixerGetLineControls(hMixer, mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE)

Everyhing goes right upto above statement.

Now I want to fill the allocated strucure by the pointer which returned by
above API function.

For that, I used API function CopyStructFromPtr(........)
Calling this function resulted application to crash without giving any
error.
I tried lot but I don't understand why?
Since the same code runs in VB6.0. well I am not been able to convert it to
.NET

Any Help will be really appriciated.

Thanks & Regards
Sakharam Phapale


1. You don't need to use GlobalAlloc and GlobalFree. You can use the
equivalent Marshal methods - Marshal.AllocHGlobal and
Marshal.FreeHGlobal.

2. Don't use RtlMoveMemory (or it's various alliases). Your going to
get your self in trouble if you don't jump through the necessary hoops -
like pinning the object references, etc... In your case, if I
understand what your trying to accomplish (though, looking at the VB6
code you're trying to convert would be helpful) - I would say that
Marshal again comes to your rescue, with it's PtrToStructure method...

--
Tom Shelton [MVP]
Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Derek Hart | last post by:
I wish to execute code from a string. The string will have a function name, which will return a string: Dim a as string a = "MyFunctionName(param1, param2)" I have seen a ton of people...
11
by: jcrouse | last post by:
I’m using VB .Net 2003. I am reading a file into memory. Here is a sniplet of the file ” section. I have the code returning what character the string “” starts at but don’t know the...
8
by: **Developer** | last post by:
Been reading some of the Marshal doc and am a little confused. Anyway, I've been using the following and it works OK. Public Declare Auto Function SHGetFolderPath Lib "shell32.dll" (ByVal hWnd...
15
by: angellian | last post by:
Sorry to raise a stupid question but I tried many methods which did work. how can I conserve the initial zero when I try to convert STR(06) into string in SQL statment? It always gives me 6...
1
by: Gilberto | last post by:
pks00 Expert 280 Posts April 16th, 2007 01:08 PM Re: How to print MS Access 2000 report to PDF995 printer by VBA Code Sweet, your using pdf995, makes answering this question that much...
3
Frinavale
by: Frinavale | last post by:
Background An Event is a message sent out by an object to notify other objects that an action/trigger/state-change (ie. an event) has taken place. Therefore, you should use an event when an object's...
1
by: keerthikarani | last post by:
hi, I m using the following code in vb.net, but it shows me some error, can u explain why this error occurs and how to rectify it, but the following code works fine in vb Private Declare...
2
by: =?Utf-8?B?Z29sZGVuX2F1?= | last post by:
Hi, I need to have 2 processes, one is monitorring the parallel port status in every 30 sec at the background and then send the status to the listbox of another window, I am new to vb.net, many...
2
by: Flying Kite | last post by:
Hi All, I want to know how to print chinese characters on Zebra Printer, following code working fine with English string, but it's not working for Chinese string. It shows ASCII characters instead...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.