How to convert IntPtr to UInt16

  • Thread starter Thread starter Sakharam Phapale
  • Start date Start date
S

Sakharam Phapale

Hi All,

I am using Microsoft Speech DLL "sapi.dll".
I want to use following method of "SpeechLib.SpStream" object
(following is a signature which I copied from Quick Info feature of .NET
code editor)

Public Overridable Overloads Sub BindToFile (Byref pszFileName as
System.UInt16 ,eMode as SpeechLib.SPFILEMODE ,ByRef pFormatId as System.Guid
,ByRef pWaveFormatEx as SpeechLib.WaveFormatEx, ullEventInterest as
System.UInt64)

Here, I think first parameter is pointer to array which contains the file
name.
But I don't understand why is it UInt16 then, it should be IntPtr. And to
that IntPtr can not be convert into UInt16.
So I am not able to pass first parameter.

How to call this procedure?

Any kind of help will be appreciated.

Thanks and Regards,
Sakharam Phapale
 
Hi,

Dim ptr As IntPtr = New IntPtr(100)

Dim myUint As UInt16 = UInt16.Parse(ptr.ToInt32.ToString)

Debug.WriteLine(myUint)



Ken

--------------------

Hi All,

I am using Microsoft Speech DLL "sapi.dll".
I want to use following method of "SpeechLib.SpStream" object
(following is a signature which I copied from Quick Info feature of .NET
code editor)

Public Overridable Overloads Sub BindToFile (Byref pszFileName as
System.UInt16 ,eMode as SpeechLib.SPFILEMODE ,ByRef pFormatId as System.Guid
,ByRef pWaveFormatEx as SpeechLib.WaveFormatEx, ullEventInterest as
System.UInt64)

Here, I think first parameter is pointer to array which contains the file
name.
But I don't understand why is it UInt16 then, it should be IntPtr. And to
that IntPtr can not be convert into UInt16.
So I am not able to pass first parameter.

How to call this procedure?

Any kind of help will be appreciated.

Thanks and Regards,
Sakharam Phapale
 
Hi,

It cant you would have to use a uint32

Ken
Hi Ken,

What if Dim ptr As IntPtr = New IntPtr(82345)
Since ptr contains 32 bit memory address, How it can be converted into
UInt16, which is 16 bit?

Error:
An unhandled exception of type 'System.OverflowException' occurred in
mscorlib.dll
Additional information: Value was either too large or too small for a
UInt16.

Thanks and Regards
Sakharam Phapale
 
Hi Ken,

What if Dim ptr As IntPtr = New IntPtr(82345)
Since ptr contains 32 bit memory address, How it can be converted into
UInt16, which is 16 bit?

Error:
An unhandled exception of type 'System.OverflowException' occurred in
mscorlib.dll
Additional information: Value was either too large or too small for a
UInt16.

Thanks and Regards
Sakharam Phapale
 
Hi Ken,

Thanks for your reply.
But it doesn't solve my problem.
If IntPtr cannot be convert into UInt16 then, how can I use the following
COM procedure?
Is there any other way to do this?
Is there anyone who worked on "sapi.dll" COM object in .NET?

Public Overridable Overloads Sub BindToFile (Byref pszFileName as
System.UInt16 ,eMode as SpeechLib.SPFILEMODE ,ByRef pFormatId as System.Guid
,ByRef pWaveFormatEx as SpeechLib.WaveFormatEx, ullEventInterest as
System.UInt64)

Thanks and Regards
Sakharam Phapale
 
Back
Top