By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,052 Members | 1,201 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,052 IT Pros & Developers. It's quick & easy.

Some Marshaling questions

P: n/a
I have SendMessage declared with the last two parameters as ByVal IntPtr

I need to call it with an Integer value and a Byte array pointer.
The Integer is [in] while the Byte array is [out]

I could probably figure how to do the pointer using Marshal.AllocHGlobal ,
Marshal.StructureToPtr, ...
If that's the simplest way to do it. But is it?

Also, if the integer value was zero I'd use IntPtr.Zero, but it's not zero -
is there a way to generate a IntPtr with the value of a given Integer.

Thanks
Nov 21 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
I have SendMessage defined as follows:

<DllImport("User32", SetLastError:=True)> _
Private Shared Function SendMessage( _
ByVal hWnd As IntPtr, _
ByVal Msg As Integer, _
ByVal wParam As Integer, _
ByVal lParam As IntPtr) As Integer

End Function
I could probably figure how to do the pointer using Marshal.AllocHGlobal ,
Marshal.StructureToPtr, ...
If that's the simplest way to do it. But is it?
Yes.
Also, if the integer value was zero I'd use IntPtr.Zero, but it's not
zero - is there a way to generate a IntPtr with the value of a given
Integer.
Dim ip As Intptr = New IntPtr(20

Here is an example, for a balloon tip:

<code>
Dim ti As TOOLINFO = New TOOLINFO
ti.cbSize = Marshal.SizeOf(ti)
ti.uFlags = TTF_TRANSPARENT Or TTF_SUBCLASS
ti.hwnd = parent.Handle
ti.lpszText = m_displayText

' get the display co-ordinates
GetClientRect(parent.Handle, ti.rect)

' add the tool tip
Dim ptrStruct As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(ti))
Marshal.StructureToPtr(ti, ptrStruct, True)

SendMessage(m_tool.Handle, TTM_ADDTOOL, 0, ptrStruct)

ti = CType(Marshal.PtrToStructure(ptrStruct, ti.GetType()),
TOOLINFO)

Marshal.FreeHGlobal(ptrStruct)
</code>

HTH

Charles
" Just Me" <gr****@a-znet.com> wrote in message
news:eY**************@TK2MSFTNGP09.phx.gbl...I have SendMessage declared with the last two parameters as ByVal IntPtr

I need to call it with an Integer value and a Byte array pointer.
The Integer is [in] while the Byte array is [out]

I could probably figure how to do the pointer using Marshal.AllocHGlobal ,
Marshal.StructureToPtr, ...
If that's the simplest way to do it. But is it?

Also, if the integer value was zero I'd use IntPtr.Zero, but it's not
zero - is there a way to generate a IntPtr with the value of a given
Integer.

Thanks

Nov 21 '05 #2

P: n/a
Thanks, this helps a lot, but I still have problems with strings.
For example:
SendMessage (handle, EM_GETLINE, LineNum, Line)

Fills Line with the characters that make up line numbered: LineNum

I'd like to use your SendMessage(...byVal Integer, ByVal IntPtr)

How should I declare Line?

Thanks again


"Charles Law" <bl***@nowhere.com> wrote in message
news:u6**************@TK2MSFTNGP09.phx.gbl...
I have SendMessage defined as follows:

<DllImport("User32", SetLastError:=True)> _
Private Shared Function SendMessage( _
ByVal hWnd As IntPtr, _
ByVal Msg As Integer, _
ByVal wParam As Integer, _
ByVal lParam As IntPtr) As Integer

End Function
I could probably figure how to do the pointer using Marshal.AllocHGlobal
, Marshal.StructureToPtr, ...
If that's the simplest way to do it. But is it?


Yes.
Also, if the integer value was zero I'd use IntPtr.Zero, but it's not
zero - is there a way to generate a IntPtr with the value of a given
Integer.


Dim ip As Intptr = New IntPtr(20

Here is an example, for a balloon tip:

<code>
Dim ti As TOOLINFO = New TOOLINFO
ti.cbSize = Marshal.SizeOf(ti)
ti.uFlags = TTF_TRANSPARENT Or TTF_SUBCLASS
ti.hwnd = parent.Handle
ti.lpszText = m_displayText

' get the display co-ordinates
GetClientRect(parent.Handle, ti.rect)

' add the tool tip
Dim ptrStruct As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(ti))
Marshal.StructureToPtr(ti, ptrStruct, True)

SendMessage(m_tool.Handle, TTM_ADDTOOL, 0, ptrStruct)

ti = CType(Marshal.PtrToStructure(ptrStruct, ti.GetType()),
TOOLINFO)

Marshal.FreeHGlobal(ptrStruct)
</code>

HTH

Charles
" Just Me" <gr****@a-znet.com> wrote in message
news:eY**************@TK2MSFTNGP09.phx.gbl...
I have SendMessage declared with the last two parameters as ByVal IntPtr

I need to call it with an Integer value and a Byte array pointer.
The Integer is [in] while the Byte array is [out]

I could probably figure how to do the pointer using Marshal.AllocHGlobal
, Marshal.StructureToPtr, ...
If that's the simplest way to do it. But is it?

Also, if the integer value was zero I'd use IntPtr.Zero, but it's not
zero - is there a way to generate a IntPtr with the value of a given
Integer.

Thanks


Nov 21 '05 #3

P: n/a
One way would be like this

<code>
Const MAX_LENGTH As Integer = 50

Dim title As System.Text.StringBuilder
Dim ip As IntPtr

Dim retval As Integer
Dim answer As String

title = New System.Text.StringBuilder(MAX_LENGTH)
title.Insert(0, " ", MAX_LENGTH)

ip = Marshal.StringToHGlobalAuto(title.ToString)

retval = SendMessage(TextBox1.Handle, EM_GETLINE, 1, ip)

answer = Marshal.PtrToStringAnsi(ip)

Marshal.FreeHGlobal(ip)
</code>

Answer contains the string you want.

HTH

Charles
" Just Me" <gr****@a-znet.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Thanks, this helps a lot, but I still have problems with strings.
For example:
SendMessage (handle, EM_GETLINE, LineNum, Line)

Fills Line with the characters that make up line numbered: LineNum

I'd like to use your SendMessage(...byVal Integer, ByVal IntPtr)

How should I declare Line?

Thanks again


"Charles Law" <bl***@nowhere.com> wrote in message
news:u6**************@TK2MSFTNGP09.phx.gbl...
I have SendMessage defined as follows:

<DllImport("User32", SetLastError:=True)> _
Private Shared Function SendMessage( _
ByVal hWnd As IntPtr, _
ByVal Msg As Integer, _
ByVal wParam As Integer, _
ByVal lParam As IntPtr) As Integer

End Function
I could probably figure how to do the pointer using Marshal.AllocHGlobal
, Marshal.StructureToPtr, ...
If that's the simplest way to do it. But is it?


Yes.
Also, if the integer value was zero I'd use IntPtr.Zero, but it's not
zero - is there a way to generate a IntPtr with the value of a given
Integer.


Dim ip As Intptr = New IntPtr(20

Here is an example, for a balloon tip:

<code>
Dim ti As TOOLINFO = New TOOLINFO
ti.cbSize = Marshal.SizeOf(ti)
ti.uFlags = TTF_TRANSPARENT Or TTF_SUBCLASS
ti.hwnd = parent.Handle
ti.lpszText = m_displayText

' get the display co-ordinates
GetClientRect(parent.Handle, ti.rect)

' add the tool tip
Dim ptrStruct As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(ti))
Marshal.StructureToPtr(ti, ptrStruct, True)

SendMessage(m_tool.Handle, TTM_ADDTOOL, 0, ptrStruct)

ti = CType(Marshal.PtrToStructure(ptrStruct, ti.GetType()),
TOOLINFO)

Marshal.FreeHGlobal(ptrStruct)
</code>

HTH

Charles
" Just Me" <gr****@a-znet.com> wrote in message
news:eY**************@TK2MSFTNGP09.phx.gbl...
I have SendMessage declared with the last two parameters as ByVal IntPtr

I need to call it with an Integer value and a Byte array pointer.
The Integer is [in] while the Byte array is [out]

I could probably figure how to do the pointer using Marshal.AllocHGlobal
, Marshal.StructureToPtr, ...
If that's the simplest way to do it. But is it?

Also, if the integer value was zero I'd use IntPtr.Zero, but it's not
zero - is there a way to generate a IntPtr with the value of a given
Integer.

Thanks



Nov 21 '05 #4

P: n/a
Thanks, this helped a lot.

PS
I had to change Marshal.PtrToStringAnsi to Marshal.PtrToStringAuto

"Charles Law" <bl***@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
One way would be like this

<code>
Const MAX_LENGTH As Integer = 50

Dim title As System.Text.StringBuilder
Dim ip As IntPtr

Dim retval As Integer
Dim answer As String

title = New System.Text.StringBuilder(MAX_LENGTH)
title.Insert(0, " ", MAX_LENGTH)

ip = Marshal.StringToHGlobalAuto(title.ToString)

retval = SendMessage(TextBox1.Handle, EM_GETLINE, 1, ip)

answer = Marshal.PtrToStringAnsi(ip)

Marshal.FreeHGlobal(ip)
</code>

Answer contains the string you want.

HTH

Charles
" Just Me" <gr****@a-znet.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Thanks, this helps a lot, but I still have problems with strings.
For example:
SendMessage (handle, EM_GETLINE, LineNum, Line)

Fills Line with the characters that make up line numbered: LineNum

I'd like to use your SendMessage(...byVal Integer, ByVal IntPtr)

How should I declare Line?

Thanks again


"Charles Law" <bl***@nowhere.com> wrote in message
news:u6**************@TK2MSFTNGP09.phx.gbl...
I have SendMessage defined as follows:

<DllImport("User32", SetLastError:=True)> _
Private Shared Function SendMessage( _
ByVal hWnd As IntPtr, _
ByVal Msg As Integer, _
ByVal wParam As Integer, _
ByVal lParam As IntPtr) As Integer

End Function

I could probably figure how to do the pointer using
Marshal.AllocHGlobal , Marshal.StructureToPtr, ...
If that's the simplest way to do it. But is it?

Yes.

Also, if the integer value was zero I'd use IntPtr.Zero, but it's not
zero - is there a way to generate a IntPtr with the value of a given
Integer.

Dim ip As Intptr = New IntPtr(20

Here is an example, for a balloon tip:

<code>
Dim ti As TOOLINFO = New TOOLINFO
ti.cbSize = Marshal.SizeOf(ti)
ti.uFlags = TTF_TRANSPARENT Or TTF_SUBCLASS
ti.hwnd = parent.Handle
ti.lpszText = m_displayText

' get the display co-ordinates
GetClientRect(parent.Handle, ti.rect)

' add the tool tip
Dim ptrStruct As IntPtr =
Marshal.AllocHGlobal(Marshal.SizeOf(ti))
Marshal.StructureToPtr(ti, ptrStruct, True)

SendMessage(m_tool.Handle, TTM_ADDTOOL, 0, ptrStruct)

ti = CType(Marshal.PtrToStructure(ptrStruct, ti.GetType()),
TOOLINFO)

Marshal.FreeHGlobal(ptrStruct)
</code>

HTH

Charles
" Just Me" <gr****@a-znet.com> wrote in message
news:eY**************@TK2MSFTNGP09.phx.gbl...
I have SendMessage declared with the last two parameters as ByVal IntPtr

I need to call it with an Integer value and a Byte array pointer.
The Integer is [in] while the Byte array is [out]

I could probably figure how to do the pointer using
Marshal.AllocHGlobal , Marshal.StructureToPtr, ...
If that's the simplest way to do it. But is it?

Also, if the integer value was zero I'd use IntPtr.Zero, but it's not
zero - is there a way to generate a IntPtr with the value of a given
Integer.

Thanks



Nov 21 '05 #5

P: n/a
Perhaps you have a slightly different set-up from me. I tried
Marshal.PtrToStringAnsi on a multi-line text box and it worked fine. It
might be an O/S or locale thing.

Charles
" Just Me" <gr****@a-znet.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Thanks, this helped a lot.

PS
I had to change Marshal.PtrToStringAnsi to Marshal.PtrToStringAuto

"Charles Law" <bl***@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
One way would be like this

<code>
Const MAX_LENGTH As Integer = 50

Dim title As System.Text.StringBuilder
Dim ip As IntPtr

Dim retval As Integer
Dim answer As String

title = New System.Text.StringBuilder(MAX_LENGTH)
title.Insert(0, " ", MAX_LENGTH)

ip = Marshal.StringToHGlobalAuto(title.ToString)

retval = SendMessage(TextBox1.Handle, EM_GETLINE, 1, ip)

answer = Marshal.PtrToStringAnsi(ip)

Marshal.FreeHGlobal(ip)
</code>

Answer contains the string you want.

HTH

Charles
" Just Me" <gr****@a-znet.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Thanks, this helps a lot, but I still have problems with strings.
For example:
SendMessage (handle, EM_GETLINE, LineNum, Line)

Fills Line with the characters that make up line numbered: LineNum

I'd like to use your SendMessage(...byVal Integer, ByVal IntPtr)

How should I declare Line?

Thanks again


"Charles Law" <bl***@nowhere.com> wrote in message
news:u6**************@TK2MSFTNGP09.phx.gbl...
I have SendMessage defined as follows:

<DllImport("User32", SetLastError:=True)> _
Private Shared Function SendMessage( _
ByVal hWnd As IntPtr, _
ByVal Msg As Integer, _
ByVal wParam As Integer, _
ByVal lParam As IntPtr) As Integer

End Function

> I could probably figure how to do the pointer using
> Marshal.AllocHGlobal , Marshal.StructureToPtr, ...
> If that's the simplest way to do it. But is it?

Yes.

> Also, if the integer value was zero I'd use IntPtr.Zero, but it's not
> zero - is there a way to generate a IntPtr with the value of a given
> Integer.

Dim ip As Intptr = New IntPtr(20

Here is an example, for a balloon tip:

<code>
Dim ti As TOOLINFO = New TOOLINFO
ti.cbSize = Marshal.SizeOf(ti)
ti.uFlags = TTF_TRANSPARENT Or TTF_SUBCLASS
ti.hwnd = parent.Handle
ti.lpszText = m_displayText

' get the display co-ordinates
GetClientRect(parent.Handle, ti.rect)

' add the tool tip
Dim ptrStruct As IntPtr =
Marshal.AllocHGlobal(Marshal.SizeOf(ti))
Marshal.StructureToPtr(ti, ptrStruct, True)

SendMessage(m_tool.Handle, TTM_ADDTOOL, 0, ptrStruct)

ti = CType(Marshal.PtrToStructure(ptrStruct, ti.GetType()),
TOOLINFO)

Marshal.FreeHGlobal(ptrStruct)
</code>

HTH

Charles
" Just Me" <gr****@a-znet.com> wrote in message
news:eY**************@TK2MSFTNGP09.phx.gbl...
>I have SendMessage declared with the last two parameters as ByVal
>IntPtr
>
> I need to call it with an Integer value and a Byte array pointer.
> The Integer is [in] while the Byte array is [out]
>
> I could probably figure how to do the pointer using
> Marshal.AllocHGlobal , Marshal.StructureToPtr, ...
> If that's the simplest way to do it. But is it?
>
> Also, if the integer value was zero I'd use IntPtr.Zero, but it's not
> zero - is there a way to generate a IntPtr with the value of a given
> Integer.
>
>
>
> Thanks
>



Nov 21 '05 #6

P: n/a

"Charles Law" <bl***@nowhere.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Perhaps you have a slightly different set-up from me. I tried
Marshal.PtrToStringAnsi on a multi-line text box and it worked fine. It
might be an O/S or locale thing.
Interesting. I'm running XP which uses Unicode. Could it be you are using ME
or earilier, which uses ANSI?

If you have more time, here is the next thing I'd like to cleanup (meaning
use the SendMessage you gave me)

Seems like I need to move the Marshal to the call but I don't know how to do
that.
Public Declare Auto Function SendMsgObject Lib "user32" Alias "SendMessage"
(ByVal wnd As IntPtr, _

ByVal msg As Integer, ByVal wparam As Integer, _

<Runtime.InteropServices.MarshalAs(Runtime.Interop Services.UnmanagedType.Interface)>
_

ByRef lparam As Object) As Integer

Then

Dim lReo As Object

User.SendMsgObject(Me.Handle, RichEdit.EM_GETOLEINTERFACE, 0, lReo)

Thanks for all the help


Charles
" Just Me" <gr****@a-znet.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Thanks, this helped a lot.

PS
I had to change Marshal.PtrToStringAnsi to Marshal.PtrToStringAuto

"Charles Law" <bl***@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
One way would be like this

<code>
Const MAX_LENGTH As Integer = 50

Dim title As System.Text.StringBuilder
Dim ip As IntPtr

Dim retval As Integer
Dim answer As String

title = New System.Text.StringBuilder(MAX_LENGTH)
title.Insert(0, " ", MAX_LENGTH)

ip = Marshal.StringToHGlobalAuto(title.ToString)

retval = SendMessage(TextBox1.Handle, EM_GETLINE, 1, ip)

answer = Marshal.PtrToStringAnsi(ip)

Marshal.FreeHGlobal(ip)
</code>

Answer contains the string you want.

HTH

Charles
" Just Me" <gr****@a-znet.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Thanks, this helps a lot, but I still have problems with strings.
For example:
SendMessage (handle, EM_GETLINE, LineNum, Line)

Fills Line with the characters that make up line numbered: LineNum

I'd like to use your SendMessage(...byVal Integer, ByVal IntPtr)

How should I declare Line?

Thanks again


"Charles Law" <bl***@nowhere.com> wrote in message
news:u6**************@TK2MSFTNGP09.phx.gbl...
>I have SendMessage defined as follows:
>
> <DllImport("User32", SetLastError:=True)> _
> Private Shared Function SendMessage( _
> ByVal hWnd As IntPtr, _
> ByVal Msg As Integer, _
> ByVal wParam As Integer, _
> ByVal lParam As IntPtr) As Integer
>
> End Function
>
>> I could probably figure how to do the pointer using
>> Marshal.AllocHGlobal , Marshal.StructureToPtr, ...
>> If that's the simplest way to do it. But is it?
>
> Yes.
>
>> Also, if the integer value was zero I'd use IntPtr.Zero, but it's not
>> zero - is there a way to generate a IntPtr with the value of a given
>> Integer.
>
> Dim ip As Intptr = New IntPtr(20
>
> Here is an example, for a balloon tip:
>
> <code>
> Dim ti As TOOLINFO = New TOOLINFO
> ti.cbSize = Marshal.SizeOf(ti)
> ti.uFlags = TTF_TRANSPARENT Or TTF_SUBCLASS
> ti.hwnd = parent.Handle
> ti.lpszText = m_displayText
>
> ' get the display co-ordinates
> GetClientRect(parent.Handle, ti.rect)
>
> ' add the tool tip
> Dim ptrStruct As IntPtr =
> Marshal.AllocHGlobal(Marshal.SizeOf(ti))
> Marshal.StructureToPtr(ti, ptrStruct, True)
>
> SendMessage(m_tool.Handle, TTM_ADDTOOL, 0, ptrStruct)
>
> ti = CType(Marshal.PtrToStructure(ptrStruct, ti.GetType()),
> TOOLINFO)
>
> Marshal.FreeHGlobal(ptrStruct)
> </code>
>
> HTH
>
> Charles
>
>
> " Just Me" <gr****@a-znet.com> wrote in message
> news:eY**************@TK2MSFTNGP09.phx.gbl...
>>I have SendMessage declared with the last two parameters as ByVal
>>IntPtr
>>
>> I need to call it with an Integer value and a Byte array pointer.
>> The Integer is [in] while the Byte array is [out]
>>
>> I could probably figure how to do the pointer using
>> Marshal.AllocHGlobal , Marshal.StructureToPtr, ...
>> If that's the simplest way to do it. But is it?
>>
>> Also, if the integer value was zero I'd use IntPtr.Zero, but it's not
>> zero - is there a way to generate a IntPtr with the value of a given
>> Integer.
>>
>>
>>
>> Thanks
>>
>
>



Nov 21 '05 #7

P: n/a
Unfortunately I'm not especially familiar with this message. Perhaps some
else will be able to advise.

Sorry.

Charles
" Just Me" <gr****@a-znet.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...

"Charles Law" <bl***@nowhere.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Perhaps you have a slightly different set-up from me. I tried
Marshal.PtrToStringAnsi on a multi-line text box and it worked fine. It
might be an O/S or locale thing.


Interesting. I'm running XP which uses Unicode. Could it be you are using
ME or earilier, which uses ANSI?

If you have more time, here is the next thing I'd like to cleanup (meaning
use the SendMessage you gave me)

Seems like I need to move the Marshal to the call but I don't know how to
do that.
Public Declare Auto Function SendMsgObject Lib "user32" Alias
"SendMessage" (ByVal wnd As IntPtr, _

ByVal msg As Integer, ByVal wparam As Integer, _

<Runtime.InteropServices.MarshalAs(Runtime.Interop Services.UnmanagedType.Interface)>
_

ByRef lparam As Object) As Integer

Then

Dim lReo As Object

User.SendMsgObject(Me.Handle, RichEdit.EM_GETOLEINTERFACE, 0, lReo)

Thanks for all the help


Charles
" Just Me" <gr****@a-znet.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Thanks, this helped a lot.

PS
I had to change Marshal.PtrToStringAnsi to Marshal.PtrToStringAuto

"Charles Law" <bl***@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
One way would be like this

<code>
Const MAX_LENGTH As Integer = 50

Dim title As System.Text.StringBuilder
Dim ip As IntPtr

Dim retval As Integer
Dim answer As String

title = New System.Text.StringBuilder(MAX_LENGTH)
title.Insert(0, " ", MAX_LENGTH)

ip = Marshal.StringToHGlobalAuto(title.ToString)

retval = SendMessage(TextBox1.Handle, EM_GETLINE, 1, ip)

answer = Marshal.PtrToStringAnsi(ip)

Marshal.FreeHGlobal(ip)
</code>

Answer contains the string you want.

HTH

Charles
" Just Me" <gr****@a-znet.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
> Thanks, this helps a lot, but I still have problems with strings.
> For example:
>
>
> SendMessage (handle, EM_GETLINE, LineNum, Line)
>
> Fills Line with the characters that make up line numbered: LineNum
>
> I'd like to use your SendMessage(...byVal Integer, ByVal IntPtr)
>
> How should I declare Line?
>
> Thanks again
>
>
>
>
>
>
> "Charles Law" <bl***@nowhere.com> wrote in message
> news:u6**************@TK2MSFTNGP09.phx.gbl...
>>I have SendMessage defined as follows:
>>
>> <DllImport("User32", SetLastError:=True)> _
>> Private Shared Function SendMessage( _
>> ByVal hWnd As IntPtr, _
>> ByVal Msg As Integer, _
>> ByVal wParam As Integer, _
>> ByVal lParam As IntPtr) As Integer
>>
>> End Function
>>
>>> I could probably figure how to do the pointer using
>>> Marshal.AllocHGlobal , Marshal.StructureToPtr, ...
>>> If that's the simplest way to do it. But is it?
>>
>> Yes.
>>
>>> Also, if the integer value was zero I'd use IntPtr.Zero, but it's
>>> not zero - is there a way to generate a IntPtr with the value of a
>>> given Integer.
>>
>> Dim ip As Intptr = New IntPtr(20
>>
>> Here is an example, for a balloon tip:
>>
>> <code>
>> Dim ti As TOOLINFO = New TOOLINFO
>> ti.cbSize = Marshal.SizeOf(ti)
>> ti.uFlags = TTF_TRANSPARENT Or TTF_SUBCLASS
>> ti.hwnd = parent.Handle
>> ti.lpszText = m_displayText
>>
>> ' get the display co-ordinates
>> GetClientRect(parent.Handle, ti.rect)
>>
>> ' add the tool tip
>> Dim ptrStruct As IntPtr =
>> Marshal.AllocHGlobal(Marshal.SizeOf(ti))
>> Marshal.StructureToPtr(ti, ptrStruct, True)
>>
>> SendMessage(m_tool.Handle, TTM_ADDTOOL, 0, ptrStruct)
>>
>> ti = CType(Marshal.PtrToStructure(ptrStruct, ti.GetType()),
>> TOOLINFO)
>>
>> Marshal.FreeHGlobal(ptrStruct)
>> </code>
>>
>> HTH
>>
>> Charles
>>
>>
>> " Just Me" <gr****@a-znet.com> wrote in message
>> news:eY**************@TK2MSFTNGP09.phx.gbl...
>>>I have SendMessage declared with the last two parameters as ByVal
>>>IntPtr
>>>
>>> I need to call it with an Integer value and a Byte array pointer.
>>> The Integer is [in] while the Byte array is [out]
>>>
>>> I could probably figure how to do the pointer using
>>> Marshal.AllocHGlobal , Marshal.StructureToPtr, ...
>>> If that's the simplest way to do it. But is it?
>>>
>>> Also, if the integer value was zero I'd use IntPtr.Zero, but it's
>>> not zero - is there a way to generate a IntPtr with the value of a
>>> given Integer.
>>>
>>>
>>>
>>> Thanks
>>>
>>
>>
>
>



Nov 21 '05 #8

P: n/a
I think I have the Auto/Ansi mystry figured out. Maybe the following is
true?

You have SendMessaage declared with
CharSet=CharSet.Ansi or using the defaule which is Ansi

I have CharSet=CharSet.Auto

So I'm using SendMessageW and you are using SendMesssageA

I thought you'd want to know.

Seems to me, if I'm coding for XP I should always use Auto, actually maybe
even if I'm not. Do you agree? I'm coding only for XP so I plan to seach my
files and change all my API declares to Auto unless someone tells me that's
not a good idea.

Thanks for the original help


"Charles Law" <bl***@nowhere.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Perhaps you have a slightly different set-up from me. I tried
Marshal.PtrToStringAnsi on a multi-line text box and it worked fine. It
might be an O/S or locale thing.

Charles
" Just Me" <gr****@a-znet.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Thanks, this helped a lot.

PS
I had to change Marshal.PtrToStringAnsi to Marshal.PtrToStringAuto

"Charles Law" <bl***@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
One way would be like this

<code>
Const MAX_LENGTH As Integer = 50

Dim title As System.Text.StringBuilder
Dim ip As IntPtr

Dim retval As Integer
Dim answer As String

title = New System.Text.StringBuilder(MAX_LENGTH)
title.Insert(0, " ", MAX_LENGTH)

ip = Marshal.StringToHGlobalAuto(title.ToString)

retval = SendMessage(TextBox1.Handle, EM_GETLINE, 1, ip)

answer = Marshal.PtrToStringAnsi(ip)

Marshal.FreeHGlobal(ip)
</code>

Answer contains the string you want.

HTH

Charles
" Just Me" <gr****@a-znet.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Thanks, this helps a lot, but I still have problems with strings.
For example:
SendMessage (handle, EM_GETLINE, LineNum, Line)

Fills Line with the characters that make up line numbered: LineNum

I'd like to use your SendMessage(...byVal Integer, ByVal IntPtr)

How should I declare Line?

Thanks again


"Charles Law" <bl***@nowhere.com> wrote in message
news:u6**************@TK2MSFTNGP09.phx.gbl...
>I have SendMessage defined as follows:
>
> <DllImport("User32", SetLastError:=True)> _
> Private Shared Function SendMessage( _
> ByVal hWnd As IntPtr, _
> ByVal Msg As Integer, _
> ByVal wParam As Integer, _
> ByVal lParam As IntPtr) As Integer
>
> End Function
>
>> I could probably figure how to do the pointer using
>> Marshal.AllocHGlobal , Marshal.StructureToPtr, ...
>> If that's the simplest way to do it. But is it?
>
> Yes.
>
>> Also, if the integer value was zero I'd use IntPtr.Zero, but it's not
>> zero - is there a way to generate a IntPtr with the value of a given
>> Integer.
>
> Dim ip As Intptr = New IntPtr(20
>
> Here is an example, for a balloon tip:
>
> <code>
> Dim ti As TOOLINFO = New TOOLINFO
> ti.cbSize = Marshal.SizeOf(ti)
> ti.uFlags = TTF_TRANSPARENT Or TTF_SUBCLASS
> ti.hwnd = parent.Handle
> ti.lpszText = m_displayText
>
> ' get the display co-ordinates
> GetClientRect(parent.Handle, ti.rect)
>
> ' add the tool tip
> Dim ptrStruct As IntPtr =
> Marshal.AllocHGlobal(Marshal.SizeOf(ti))
> Marshal.StructureToPtr(ti, ptrStruct, True)
>
> SendMessage(m_tool.Handle, TTM_ADDTOOL, 0, ptrStruct)
>
> ti = CType(Marshal.PtrToStructure(ptrStruct, ti.GetType()),
> TOOLINFO)
>
> Marshal.FreeHGlobal(ptrStruct)
> </code>
>
> HTH
>
> Charles
>
>
> " Just Me" <gr****@a-znet.com> wrote in message
> news:eY**************@TK2MSFTNGP09.phx.gbl...
>>I have SendMessage declared with the last two parameters as ByVal
>>IntPtr
>>
>> I need to call it with an Integer value and a Byte array pointer.
>> The Integer is [in] while the Byte array is [out]
>>
>> I could probably figure how to do the pointer using
>> Marshal.AllocHGlobal , Marshal.StructureToPtr, ...
>> If that's the simplest way to do it. But is it?
>>
>> Also, if the integer value was zero I'd use IntPtr.Zero, but it's not
>> zero - is there a way to generate a IntPtr with the value of a given
>> Integer.
>>
>>
>>
>> Thanks
>>
>
>



Nov 21 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.