take a look at the Marshal.AllocHGlobal method. Here's how you could do
this:
Dim ptr As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(GetType(Boolean)))
Then you can retrieve the boolean pointed to by ptr (after your function has
executed and populated the values) as:
Dim b As Byte = Marshal.ReadByte(ptr)
And ofcourse dispose off the allocated memory:
Marshal.FreeHGlobal(ptr)
hope that helps..
Imran.
> Wrapping an unmanaged DLL I've got this declaration:
> '------------------------------------------Set Attribute Value
[quoted text clipped - 11 lines]
>
> Thanks.
M K - 09 Dec 2004 19:51 GMT
That helps, only thing is, how do I set the boolean in the pointer to false
before I pass it to my function?
> take a look at the Marshal.AllocHGlobal method. Here's how you could do
> this:
[quoted text clipped - 26 lines]
> >
> > Thanks.
Imran Koradia - 09 Dec 2004 20:09 GMT
My apologies. To read the boolean value, you'll have to use ReadInt16
instead of ReadByte (what was I thinking ?!?) since booleans are stored as
16-bit numbers. So, to write a boolean, you can use the counter part of the
Read method - the WriteInt16 method off the Marshal class.
Marshal.WriteInt16(ptr, CShort(b))
and then when reading:
Dim bResult As Boolean = CBool(Marshal.ReadInt16(ptr))
hope that helps..
Imran.
> That helps, only thing is, how do I set the boolean in the pointer to false
> before I pass it to my function?
[quoted text clipped - 29 lines]
> > >
> > > Thanks.
>So, inType is an enumerator that tells the function what type (Integer,
>String, Boolean) inAttrValue is, or actually is pointing to. So how to I
>create a pointer to a boolean? I've created pointers that get passed by
>reference and filled by the unmanaged library, but I haven't filled a pointer
>myself.
The easiest way is to write strongly typed overloads for each possible
parameter type:
Declare Auto Function KSetAttributeValue Lib "DCSPro4SLR.dll" Alias
"KPDCSetAttributeValue" (ByVal inRef As IntPtr, ByVal inAttrID As
Integer, ByVal inType As KPDCDataTypes, ByVal inAttrSize As Integer,
ByVal inAttrValue As String) As Integer
Declare Auto Function KSetAttributeValue Lib "DCSPro4SLR.dll" Alias
"KPDCSetAttributeValue" (ByVal inRef As IntPtr, ByVal inAttrID As
Integer, ByVal inType As KPDCDataTypes, ByVal inAttrSize As Integer,
ByRef inAttrValue As Boolean) As Integer
Declare Auto Function KSetAttributeValue Lib "DCSPro4SLR.dll" Alias
"KPDCSetAttributeValue" (ByVal inRef As IntPtr, ByVal inAttrID As
Integer, ByVal inType As KPDCDataTypes, ByVal inAttrSize As Integer,
ByRef inAttrValue As Integer) As Integer
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
M K - 10 Dec 2004 13:55 GMT
Duh, yes, that could do it. Thank you so much. Let me try...
"Mattias Sjögren" wrote:
> >So, inType is an enumerator that tells the function what type (Integer,
> >String, Boolean) inAttrValue is, or actually is pointing to. So how to I
[quoted text clipped - 21 lines]
>
> Mattias