Some Marshaling questions

  • Thread starter Thread starter Just Me
  • Start date Start date
J

Just Me

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
 
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 said:
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
 
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 said:
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 said:
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
 
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 said:
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 said:
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 said:
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
 
Thanks, this helped a lot.

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

Charles Law said:
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 said:
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 said:
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


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
 
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 said:
Thanks, this helped a lot.

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

Charles Law said:
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 said:
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






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


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
 
Charles Law said:
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.InteropServices.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 said:
Thanks, this helped a lot.

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

Charles Law said:
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


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






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


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
 
Unfortunately I'm not especially familiar with this message. Perhaps some
else will be able to advise.

Sorry.

Charles


Just Me said:
Charles Law said:
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.InteropServices.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 said:
Thanks, this helped a lot.

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

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


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






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


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
 
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 said:
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 said:
Thanks, this helped a lot.

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

Charles Law said:
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


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






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


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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top