473,769 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Some Marshaling questions

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.AllocHG lobal ,
Marshal.Structu reToPtr, ...
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
8 1383
I have SendMessage defined as follows:

<DllImport("Use r32", SetLastError:=T rue)> _
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.AllocHG lobal ,
Marshal.Structu reToPtr, ...
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(p arent.Handle, ti.rect)

' add the tool tip
Dim ptrStruct As IntPtr = Marshal.AllocHG lobal(Marshal.S izeOf(ti))
Marshal.Structu reToPtr(ti, ptrStruct, True)

SendMessage(m_t ool.Handle, TTM_ADDTOOL, 0, ptrStruct)

ti = CType(Marshal.P trToStructure(p trStruct, ti.GetType()),
TOOLINFO)

Marshal.FreeHGl obal(ptrStruct)
</code>

HTH

Charles
" Just Me" <gr****@a-znet.com> wrote in message
news:eY******** ******@TK2MSFTN GP09.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.AllocHG lobal ,
Marshal.Structu reToPtr, ...
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
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******** ******@TK2MSFTN GP09.phx.gbl...
I have SendMessage defined as follows:

<DllImport("Use r32", SetLastError:=T rue)> _
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.AllocHG lobal
, Marshal.Structu reToPtr, ...
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(p arent.Handle, ti.rect)

' add the tool tip
Dim ptrStruct As IntPtr = Marshal.AllocHG lobal(Marshal.S izeOf(ti))
Marshal.Structu reToPtr(ti, ptrStruct, True)

SendMessage(m_t ool.Handle, TTM_ADDTOOL, 0, ptrStruct)

ti = CType(Marshal.P trToStructure(p trStruct, ti.GetType()),
TOOLINFO)

Marshal.FreeHGl obal(ptrStruct)
</code>

HTH

Charles
" Just Me" <gr****@a-znet.com> wrote in message
news:eY******** ******@TK2MSFTN GP09.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.AllocHG lobal
, Marshal.Structu reToPtr, ...
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
One way would be like this

<code>
Const MAX_LENGTH As Integer = 50

Dim title As System.Text.Str ingBuilder
Dim ip As IntPtr

Dim retval As Integer
Dim answer As String

title = New System.Text.Str ingBuilder(MAX_ LENGTH)
title.Insert(0, " ", MAX_LENGTH)

ip = Marshal.StringT oHGlobalAuto(ti tle.ToString)

retval = SendMessage(Tex tBox1.Handle, EM_GETLINE, 1, ip)

answer = Marshal.PtrToSt ringAnsi(ip)

Marshal.FreeHGl obal(ip)
</code>

Answer contains the string you want.

HTH

Charles
" Just Me" <gr****@a-znet.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.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******** ******@TK2MSFTN GP09.phx.gbl...
I have SendMessage defined as follows:

<DllImport("Use r32", SetLastError:=T rue)> _
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.AllocHG lobal
, Marshal.Structu reToPtr, ...
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(p arent.Handle, ti.rect)

' add the tool tip
Dim ptrStruct As IntPtr = Marshal.AllocHG lobal(Marshal.S izeOf(ti))
Marshal.Structu reToPtr(ti, ptrStruct, True)

SendMessage(m_t ool.Handle, TTM_ADDTOOL, 0, ptrStruct)

ti = CType(Marshal.P trToStructure(p trStruct, ti.GetType()),
TOOLINFO)

Marshal.FreeHGl obal(ptrStruct)
</code>

HTH

Charles
" Just Me" <gr****@a-znet.com> wrote in message
news:eY******** ******@TK2MSFTN GP09.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.AllocHG lobal
, Marshal.Structu reToPtr, ...
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
Thanks, this helped a lot.

PS
I had to change Marshal.PtrToSt ringAnsi to Marshal.PtrToSt ringAuto

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

<code>
Const MAX_LENGTH As Integer = 50

Dim title As System.Text.Str ingBuilder
Dim ip As IntPtr

Dim retval As Integer
Dim answer As String

title = New System.Text.Str ingBuilder(MAX_ LENGTH)
title.Insert(0, " ", MAX_LENGTH)

ip = Marshal.StringT oHGlobalAuto(ti tle.ToString)

retval = SendMessage(Tex tBox1.Handle, EM_GETLINE, 1, ip)

answer = Marshal.PtrToSt ringAnsi(ip)

Marshal.FreeHGl obal(ip)
</code>

Answer contains the string you want.

HTH

Charles
" Just Me" <gr****@a-znet.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.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******** ******@TK2MSFTN GP09.phx.gbl...
I have SendMessage defined as follows:

<DllImport("Use r32", SetLastError:=T rue)> _
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.AllocHG lobal , Marshal.Structu reToPtr, ...
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(p arent.Handle, ti.rect)

' add the tool tip
Dim ptrStruct As IntPtr =
Marshal.AllocHG lobal(Marshal.S izeOf(ti))
Marshal.Structu reToPtr(ti, ptrStruct, True)

SendMessage(m_t ool.Handle, TTM_ADDTOOL, 0, ptrStruct)

ti = CType(Marshal.P trToStructure(p trStruct, ti.GetType()),
TOOLINFO)

Marshal.FreeHGl obal(ptrStruct)
</code>

HTH

Charles
" Just Me" <gr****@a-znet.com> wrote in message
news:eY******** ******@TK2MSFTN GP09.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.AllocHG lobal , Marshal.Structu reToPtr, ...
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
Perhaps you have a slightly different set-up from me. I tried
Marshal.PtrToSt ringAnsi 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******** ********@TK2MSF TNGP14.phx.gbl. ..
Thanks, this helped a lot.

PS
I had to change Marshal.PtrToSt ringAnsi to Marshal.PtrToSt ringAuto

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

<code>
Const MAX_LENGTH As Integer = 50

Dim title As System.Text.Str ingBuilder
Dim ip As IntPtr

Dim retval As Integer
Dim answer As String

title = New System.Text.Str ingBuilder(MAX_ LENGTH)
title.Insert(0, " ", MAX_LENGTH)

ip = Marshal.StringT oHGlobalAuto(ti tle.ToString)

retval = SendMessage(Tex tBox1.Handle, EM_GETLINE, 1, ip)

answer = Marshal.PtrToSt ringAnsi(ip)

Marshal.FreeHGl obal(ip)
</code>

Answer contains the string you want.

HTH

Charles
" Just Me" <gr****@a-znet.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.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******** ******@TK2MSFTN GP09.phx.gbl...
I have SendMessage defined as follows:

<DllImport("Use r32", SetLastError:=T rue)> _
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.AllocHG lobal , Marshal.Structu reToPtr, ...
> 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(p arent.Handle, ti.rect)

' add the tool tip
Dim ptrStruct As IntPtr =
Marshal.AllocHG lobal(Marshal.S izeOf(ti))
Marshal.Structu reToPtr(ti, ptrStruct, True)

SendMessage(m_t ool.Handle, TTM_ADDTOOL, 0, ptrStruct)

ti = CType(Marshal.P trToStructure(p trStruct, ti.GetType()),
TOOLINFO)

Marshal.FreeHGl obal(ptrStruct)
</code>

HTH

Charles
" Just Me" <gr****@a-znet.com> wrote in message
news:eY******** ******@TK2MSFTN GP09.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.AllocHG lobal , Marshal.Structu reToPtr, ...
> 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

"Charles Law" <bl***@nowhere. com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Perhaps you have a slightly different set-up from me. I tried
Marshal.PtrToSt ringAnsi 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 "SendMessag e"
(ByVal wnd As IntPtr, _

ByVal msg As Integer, ByVal wparam As Integer, _

<Runtime.Intero pServices.Marsh alAs(Runtime.In teropServices.U nmanagedType.In terface)>
_

ByRef lparam As Object) As Integer

Then

Dim lReo As Object

User.SendMsgObj ect(Me.Handle, RichEdit.EM_GET OLEINTERFACE, 0, lReo)

Thanks for all the help


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

PS
I had to change Marshal.PtrToSt ringAnsi to Marshal.PtrToSt ringAuto

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

<code>
Const MAX_LENGTH As Integer = 50

Dim title As System.Text.Str ingBuilder
Dim ip As IntPtr

Dim retval As Integer
Dim answer As String

title = New System.Text.Str ingBuilder(MAX_ LENGTH)
title.Insert(0, " ", MAX_LENGTH)

ip = Marshal.StringT oHGlobalAuto(ti tle.ToString)

retval = SendMessage(Tex tBox1.Handle, EM_GETLINE, 1, ip)

answer = Marshal.PtrToSt ringAnsi(ip)

Marshal.FreeHGl obal(ip)
</code>

Answer contains the string you want.

HTH

Charles
" Just Me" <gr****@a-znet.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.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******** ******@TK2MSFTN GP09.phx.gbl...
>I have SendMessage defined as follows:
>
> <DllImport("Use r32", SetLastError:=T rue)> _
> 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.AllocHG lobal , Marshal.Structu reToPtr, ...
>> 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(p arent.Handle, ti.rect)
>
> ' add the tool tip
> Dim ptrStruct As IntPtr =
> Marshal.AllocHG lobal(Marshal.S izeOf(ti))
> Marshal.Structu reToPtr(ti, ptrStruct, True)
>
> SendMessage(m_t ool.Handle, TTM_ADDTOOL, 0, ptrStruct)
>
> ti = CType(Marshal.P trToStructure(p trStruct, ti.GetType()),
> TOOLINFO)
>
> Marshal.FreeHGl obal(ptrStruct)
> </code>
>
> HTH
>
> Charles
>
>
> " Just Me" <gr****@a-znet.com> wrote in message
> news:eY******** ******@TK2MSFTN GP09.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.AllocHG lobal , Marshal.Structu reToPtr, ...
>> 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
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******** ********@TK2MSF TNGP14.phx.gbl. ..

"Charles Law" <bl***@nowhere. com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Perhaps you have a slightly different set-up from me. I tried
Marshal.PtrToSt ringAnsi 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
"SendMessag e" (ByVal wnd As IntPtr, _

ByVal msg As Integer, ByVal wparam As Integer, _

<Runtime.Intero pServices.Marsh alAs(Runtime.In teropServices.U nmanagedType.In terface)>
_

ByRef lparam As Object) As Integer

Then

Dim lReo As Object

User.SendMsgObj ect(Me.Handle, RichEdit.EM_GET OLEINTERFACE, 0, lReo)

Thanks for all the help


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

PS
I had to change Marshal.PtrToSt ringAnsi to Marshal.PtrToSt ringAuto

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

<code>
Const MAX_LENGTH As Integer = 50

Dim title As System.Text.Str ingBuilder
Dim ip As IntPtr

Dim retval As Integer
Dim answer As String

title = New System.Text.Str ingBuilder(MAX_ LENGTH)
title.Insert(0, " ", MAX_LENGTH)

ip = Marshal.StringT oHGlobalAuto(ti tle.ToString)

retval = SendMessage(Tex tBox1.Handle, EM_GETLINE, 1, ip)

answer = Marshal.PtrToSt ringAnsi(ip)

Marshal.FreeHGl obal(ip)
</code>

Answer contains the string you want.

HTH

Charles
" Just Me" <gr****@a-znet.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.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******** ******@TK2MSFTN GP09.phx.gbl...
>>I have SendMessage defined as follows:
>>
>> <DllImport("Use r32", SetLastError:=T rue)> _
>> 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.AllocHG lobal , Marshal.Structu reToPtr, ...
>>> 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(p arent.Handle, ti.rect)
>>
>> ' add the tool tip
>> Dim ptrStruct As IntPtr =
>> Marshal.AllocHG lobal(Marshal.S izeOf(ti))
>> Marshal.Structu reToPtr(ti, ptrStruct, True)
>>
>> SendMessage(m_t ool.Handle, TTM_ADDTOOL, 0, ptrStruct)
>>
>> ti = CType(Marshal.P trToStructure(p trStruct, ti.GetType()),
>> TOOLINFO)
>>
>> Marshal.FreeHGl obal(ptrStruct)
>> </code>
>>
>> HTH
>>
>> Charles
>>
>>
>> " Just Me" <gr****@a-znet.com> wrote in message
>> news:eY******** ******@TK2MSFTN GP09.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.AllocHG lobal , Marshal.Structu reToPtr, ...
>>> 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
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******** ********@tk2msf tngp13.phx.gbl. ..
Perhaps you have a slightly different set-up from me. I tried
Marshal.PtrToSt ringAnsi 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******** ********@TK2MSF TNGP14.phx.gbl. ..
Thanks, this helped a lot.

PS
I had to change Marshal.PtrToSt ringAnsi to Marshal.PtrToSt ringAuto

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

<code>
Const MAX_LENGTH As Integer = 50

Dim title As System.Text.Str ingBuilder
Dim ip As IntPtr

Dim retval As Integer
Dim answer As String

title = New System.Text.Str ingBuilder(MAX_ LENGTH)
title.Insert(0, " ", MAX_LENGTH)

ip = Marshal.StringT oHGlobalAuto(ti tle.ToString)

retval = SendMessage(Tex tBox1.Handle, EM_GETLINE, 1, ip)

answer = Marshal.PtrToSt ringAnsi(ip)

Marshal.FreeHGl obal(ip)
</code>

Answer contains the string you want.

HTH

Charles
" Just Me" <gr****@a-znet.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.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******** ******@TK2MSFTN GP09.phx.gbl...
>I have SendMessage defined as follows:
>
> <DllImport("Use r32", SetLastError:=T rue)> _
> 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.AllocHG lobal , Marshal.Structu reToPtr, ...
>> 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(p arent.Handle, ti.rect)
>
> ' add the tool tip
> Dim ptrStruct As IntPtr =
> Marshal.AllocHG lobal(Marshal.S izeOf(ti))
> Marshal.Structu reToPtr(ti, ptrStruct, True)
>
> SendMessage(m_t ool.Handle, TTM_ADDTOOL, 0, ptrStruct)
>
> ti = CType(Marshal.P trToStructure(p trStruct, ti.GetType()),
> TOOLINFO)
>
> Marshal.FreeHGl obal(ptrStruct)
> </code>
>
> HTH
>
> Charles
>
>
> " Just Me" <gr****@a-znet.com> wrote in message
> news:eY******** ******@TK2MSFTN GP09.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.AllocHG lobal , Marshal.Structu reToPtr, ...
>> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1891
by: Ash | last post by:
Hi, Has anyone ever tried using "COM marshaling" for cross- process communication? In particular, I am interested in cross-process marshaling between Managed Server and Unmanaged Client. There seems to be very little documentation/examples on this. I have a "Service" that needs to have a COM
4
11706
by: Vadym Stetsyak | last post by:
Hi there!!! I'm looking for any resources on the subject. Any help will be appreciated! -- Vadym Stetsyak ICQ 161730125 He, who commands the past - commands the future
3
1312
by: Stephen Gennard | last post by:
Hello, I having a problem dynamically invoking a static method that takes a reference to a SByte*. If I do it directly it works just fine. Anyone any ideas why? I have include a example below... --
3
3644
by: Rudy Velthuis | last post by:
Hello, Does anyone know how to create a struct that will marshal to the following C++ struct A, containing an array of the user defined String10 type: struct String10 { char SLen; char S;
1
2481
by: Nadav | last post by:
Hi I am about to write a performance crutial system, I am considering writing this system based on native COM or unmanaged C++ exposed as CLI, Now, I Wonder... does exposing a native code through CLI ( using a mixed mode DLL ) have any performance penalty? consider one Native C++ CLI assembly calling a methos od another CLI Native C++ Assembly, will there be any marshaling penalty, will there be any penelty at-all? is it possible to pass a...
2
3954
by: mirek | last post by:
Hi, I'm trying to import my old code to the .NET using managed wrappers. I've read "Managed Extensions for C++ Migration Guide" document and was trying to do what it stated in it. For example if my function takes mfc's CString I was converting it this way: char __pin* szUser = static_cast<char*>(Marshal::StringToHGlobalAnsi(sUser).ToPointer()); and pass szUser to the function.
7
9074
by: Greg Roberts | last post by:
Hi 1. Is there any way to access a static function in a class via the syntax ? e.g. in C# static extern void MyClass::MyFunc(); The compiler does not like the class reference ...
0
947
by: chowsaikeet | last post by:
Dear All, I have trouble doing marshaling for polymorphism. Please look at the code below: //C++ code, sample.dll Class A {
0
1876
by: jpogorman | last post by:
Hello, I am trying to get c# custom marshaling working in a particular scenario but it does not appear to be working or not jumping into my marshaling class when I try to debug it. I am try to implement a performance improvement in the transfer of thousands of objects (ClientInfoDescriptor) over a remote call. The objects all have a model object (IDataDrivenModel) to describe them but there may only two or three model objects in total. These...
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9422
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
10208
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10038
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
9857
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
5294
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
5444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3952
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
3
2812
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.