*Experts* Merrion Posted November 17, 2002 *Experts* Posted November 17, 2002 The structure PRINTER_NOTIFY_OPTIONS_TYPE has a pointer to a variable length array of 16 bit integer flags as it's last member. In VB-Classic I filled this by using the VarPtr keyword....how do I go about doing this in VB.Net? i.e. Private Structure PRINTER_NOTIFY_OPTIONS_TYPE Dim wType As Int16 Dim wReserved0 As Int16 Dim dwReserved1 As Int32 Dim dwReserved2 As Int32 Dim Count As Int32 '\\Number of elements in the array Dim pFields As Int32 '\\Pointer to the array End Type which is populated.... Dim arTypes(0) As Int16 arTypes(0) = Job_Notify_Indexes.JOB_NOTIFY_FIELD_STATUS With pTypeJob .wType = Printer_Notification_Types.JOB_NOTIFY_TYPE .Count = 1 '.pFields = ???? (was VarPtr(arTypes(0)) End With Thanks in advance, Duncan Quote Printer Monitor for .NET? - see Merrion Computing Ltd for details
*Gurus* Derek Stone Posted November 17, 2002 *Gurus* Posted November 17, 2002 There really isn't a .NET equivalent to VarPtr, in managed memory at least. What you have to do is allocate unmanaged memory using System.Runtime.InteropServices.AllocHGlobal(), which will then return an IntPtr. This is your variable pointer. Quote Posting Guidelines
*Gurus* divil Posted November 17, 2002 *Gurus* Posted November 17, 2002 Is there not a Marshalling attribute which will pass a pointer to the variable rather than the variable itself? Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
*Experts* Merrion Posted November 17, 2002 Author *Experts* Posted November 17, 2002 **untested**`VarPtr equivalent It may be possible thus:- <StructLayout(LayoutKind.Sequential>_ Private Structure PRINTER_NOTIFY_OPTIONS_TYPE Dim wType As Int16 Dim wReserved0 As Int16 Dim dwReserved1 As Int32 Dim dwReserved2 As Int32 Dim Count As Int32 <MarshalAs(UnmanagedType.LPArray)>Dim pFields() As Int16 End Structure unfortunately I've a whole heap more converting of old VB6 code to go beforte I can test this out. Thanks in advance, Duncan Quote Printer Monitor for .NET? - see Merrion Computing Ltd for details
*Gurus* Derek Stone Posted November 17, 2002 *Gurus* Posted November 17, 2002 Yeah, both ways will work. You can teach people shortcuts or teach them how it really works. Generally I like a mix of the two. That's why I suggested AllocHGlobal(). Quote Posting Guidelines
*Experts* Merrion Posted November 17, 2002 Author *Experts* Posted November 17, 2002 In fact AllocHGlobal seems to be a better solution as I don't know the array size and the <MarshalAs()> will only get the first element in that case... Quote Printer Monitor for .NET? - see Merrion Computing Ltd for details
*Experts* Nerseus Posted December 11, 2002 *Experts* Posted December 11, 2002 (edited) You could try this (sorry, it's C# but should show what you need) GCHandle p = GCHandle.Alloc(arTypes, GCHandleType.Pinned); .pFields = p.AddrOfPinnedObject().ToInt32(); p.Free() -ner Edited December 11, 2002 by divil Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Recommended Posts