Re: szPname As String * MAXPNAMELEN (How to declare)

From: Sakharam Phapale (sphapale_at_annetsite.com)
Date: 10/07/04


Date: Thu, 7 Oct 2004 17:09:48 +0530

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" <tom@YOUKNOWTHEDRILLmtogden.com> wrote in message
news:ufgYzNErEHA.452@TK2MSFTNGP09.phx.gbl...
> On 2004-10-07, Sakharam Phapale <sphapale@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]



Relevant Pages

  • Re: Danger of using FillMem() on a string? Speed of Abs()?
    ... >PChar to a API function that is going to populate it and reset the ... > length to its true value after the API call so that the end of string ... PChar(MAX_PATH) ??? ...
    (comp.lang.pascal.delphi.misc)
  • Re: Structure Marshalling Question
    ... > bones C API. ... > The BYTE array returned by this API function is actually text. ... > I would be perfectly happy to get this as a String, StringBuilder, ...
    (microsoft.public.dotnet.framework.interop)
  • Re: Interview question - filestream
    ... > than some other technique such as a shell api call? ... that I *would* use a file stream to move a file. ... Using the API, you have ... One reason might be that the API function ...
    (borland.public.delphi.language.objectpascal)
  • Re: With API function, VB freezes up
    ... help section on the Microsoft site likes to put everything in VB.net or C ... you may get better help figuring out API stuff in the ... I haven't been able to just look up an API function ... > I've recently purchased a couple of tutorial books on the API (one by ...
    (microsoft.public.vb.general.discussion)
  • Re: Getting extended error information for PlaySound
    ... > I've seen GetLastError work in VB, it only seems to depend on the API ... it probably wasn't an error value for an API function that you called. ...
    (microsoft.public.vb.winapi)