How to wrap SendMessage

  • Thread starter Thread starter SamSpade
  • Start date Start date
S

SamSpade

I'd like to define a wrapped SendMessage. Something like:

function zz (TxtHandle as IntPtr, Msg1 as integer, Msg2 as Integer, Struct
as Structure, StructSize as integer, StructType as ???) as integer

Dim TmpStruc As IntPtr = Marshal.AllocHGlobal(StructSize)

Marshal.StructureToPtr(Struct, TmpStruc, True)

zz=SendMessage(TxtHandle, Msg1, Msg2, TmpStruc)

Struct = CType(Marshal.PtrToStructure(TmpStruc, GetType(StructType)),
StructType)

Marshal.FreeHGlobal(TmpStruc)

end function

I'm not sure about the parameter Struct as Structure. Maybe Object should be
the type?

But I have no idea how to pass the type "StructType" for CType

Think this can be done?

Any idea how?



Thanks in advance
 
I'm not sure about the parameter Struct as Structure. Maybe Object should be
the type?

Yes, unless you want to write separate overloads for each structure
type (or wait for generics in Whidbey).

But I have no idea how to pass the type "StructType" for CType

Think this can be done?

If you declare the Struct parameter as Object, you don't need the
CType. Let the caller cast it back to the expected type.



Mattias
 
Back
Top