473,796 Members | 2,621 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4610
On 2004-10-07, Sakharam Phapale <sp******@annet site.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.Seq uential, 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 = mixerGetLineInf o(hMixer, mxl, MIXER_GETLINEIN FOF_COMPONENTTY PE)

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

<StructLayout(L ayoutKind.Seque ntial, CharSet:=CharSe t.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(Unma nagedType.ByVal TStr, SizeConst:=MAXP NAMELEN)> _

Public szPname As String

End Structure

<StructLayout(L ayoutKind.Seque ntial, CharSet:=CharSe t.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(Unma nagedType.ByVal TStr, SizeConst:=MIXE R_SHORT_NAME_CH ARS)> _

Public szShortName As String

<MarshalAs(Unma nagedType.ByVal TStr, SizeConst:=MIXE R_LONG_NAME_CHA RS)> _

Public szName As String

Public tTarget As Target

End Structure
Waiting for your respose.

Thanks

Sakharam Phapale
"Tom Shelton" <to*@YOUKNOWTHE DRILLmtogden.co m> wrote in message
news:u5******** ******@TK2MSFTN GP12.phx.gbl...
On 2004-10-07, Sakharam Phapale <sp******@annet site.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.Seq uential, 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******@annet site.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 = mixerGetLineInf o(hMixer, mxl, MIXER_GETLINEIN FOF_COMPONENTTY PE)

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

Are you declaring mixerGetLineInf o correctly? Should probably be:

Public Declare Auto Function mixerGetLineInf o Lib "winmm.dll" _
(ByVal hmxobj As System.IntPtr, _
ByRef pmxl As MIXERLINE, _
ByVal fdwInfo As Integer) As Integer
<StructLayout( LayoutKind.Sequ ential, CharSet:=CharSe t.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(Unm anagedType.ByVa lTStr, SizeConst:=MAXP NAMELEN)> _

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.Sequ ential, CharSet:=CharSe t.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(Unm anagedType.ByVa lTStr, SizeConst:=MIXE R_SHORT_NAME_CH ARS)> _

Public szShortName As String

<MarshalAs(Unm anagedType.ByVa lTStr, SizeConst:=MIXE R_LONG_NAME_CHA RS)> _

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 "MIXERCONTR OL"
And then I used following API function to get the mixer control iformation.
mixerGetLineCon trols(hMixer, mxlc, MIXER_GETLINECO NTROLSF_ONEBYTY PE)

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 CopyStructFromP tr(........)
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*@YOUKNOWTHE DRILLmtogden.co m> wrote in message
news:uf******** *****@TK2MSFTNG P09.phx.gbl...
On 2004-10-07, Sakharam Phapale <sp******@annet site.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 = mixerGetLineInf o(hMixer, mxl, MIXER_GETLINEIN FOF_COMPONENTTY PE)

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


Are you declaring mixerGetLineInf o correctly? Should probably be:

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

<StructLayout( LayoutKind.Sequ ential, CharSet:=CharSe t.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(Unm anagedType.ByVa lTStr, SizeConst:=MAXP NAMELEN)> _

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.Sequ ential, CharSet:=CharSe t.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(Unm anagedType.ByVa lTStr, SizeConst:=MIXE R_SHORT_NAME_CH ARS)> _

Public szShortName As String

<MarshalAs(Unm anagedType.ByVa lTStr, SizeConst:=MIXE R_LONG_NAME_CHA RS)> _

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 "MIXERCONTR OL"
And then I used following API function to get the mixer control iformation.
mixerGetLineCon trols(hMixer, mxlc, MIXER_GETLINECO NTROLSF_ONEBYTY PE)

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 CopyStructFromP tr(........)
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.AllocHG lobal and
Marshal.FreeHGl obal.

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
3699
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 discuss how reflection does this, but I cannot find the syntax to do this. I have tried several code example off of gotdotnet and other articles. Can somebody please show me the code to do this?
11
1789
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 command or syntax to start at a certain character number (which I have) and then read until the first blank line then put it into another variable After that I want to do the same thing, kind of, and put the parts after the “=” sign into separate...
8
5774
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 As Integer, _ ByVal nFolder As Integer, ByVal nToken As Integer, _ ByVal dwFlags As Integer, _
15
8072
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 instead of 06. Thanks a lot.
1
2381
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 easier :)
3
9498
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 state change requires other objects to change as well. The object that sends an event is known as the event sender. The object that receives (or listens for) the event is known as the event receiver. Events implement the "Observer Design...
1
1557
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 Function SQLDataSources Lib "odbc32.dll" _ (ByVal hEnv As Long, _ ByVal fDirection As Integer, _ ByVal szDSN As String, _ ByVal cbDSNMax As Integer, _ ByVal pcbDSN As Integer, _
2
4384
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 thanks for any advice.
2
6726
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 of Chinese characters, on my machine I installed language pack and currently set language as Chinese PRC but still it's not working. Option Explicit Private Type DOCINFO pDocName As String pOutputFile As String pDatatype As String
0
9531
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10237
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10018
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6795
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5446
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5578
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4120
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3735
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.