Using PrtDevMode en PrtDevNames of MS Access Scripting lib in VB.NET

V

veerleverbr

Hi,

Can anyone give me sample code on how to use de info in PrtDevMode en
PrtDevNames of Access from within VB.NET?

This is how it's done in VB6:
http://msdn.microsoft.com/library/d...s/vbaac11/html/acproPrtDevMode_HV05187912.asp

I tried redefining the type declarations in VB.NET using structures:
Private Structure str_DEVMODE
<VBFixedString(94)> Public RGB As String
End Structure
Private Structure type_DEVMODE
<VBFixedString(32)> Public strDeviceName As String
Public intSpecVersion As Integer
Public intDriverVersion As Integer
Public intSize As Integer
Public intDriverExtra As Integer
Public lngFields As Long
Public intOrientation As Integer
Public intPaperSize As Integer
Public intPaperLength As Integer
Public intPaperWidth As Integer
Public intScale As Integer
Public intCopies As Integer
Public intDefaultSource As Integer
Public intPrintQuality As Integer
Public intColor As Integer
Public intDuplex As Integer
Public intResolution As Integer
Public intTTOption As Integer
Public intCollate As Integer
<VBFixedString(32)> Public strFormName As String
Public lngPad As Long
Public lngBits As Long
Public lngPW As Long
Public lngPH As Long
Public lngDFI As Long
Public lngDFr As Long
End Structure

But now I have no idea how to get the info of rpt.PrtDevMode into these
structures... When I try to assign rpt.PrtDevMode to a String variable
like in the VB6 code, I get a cast error because rpt.PrtDevMode is an
array of bytes. So I tried converting that in a proper way using
BitConverter.ToString but that gives a different String as in VB6 so
that doesn't work.

Anyone knows how I can do that?

Veerle
 
D

Dragon

Hi Veerle,

I believe you should do the following (quick-&-dirty sample):

~
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> Private
Structure DevMode_Access
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)> Public
DeviceName As String
Public SpecVersion As Int16
Public DriverVersion As Int16
Public Size As Int16
Public DriverExtra As Int16
Public Fields As Int32
Public Orientation As Int16
Public PaperSize As Int16
Public PaperLength As Int16
Public PaperWidth As Int16
Public Scale As Int16
Public Copies As Int16
Public DefaultSource As Int16
Public PrintQuality As Int16
Public Color As Int16
Public Duplex As Int16
Public YResolution As Int16
Public TTOption As Int16
Public Collate As Int16
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)> Public
FormName As String
Public Pad As Int32
Public Bits As Int32
Public PW As Int32
Public PH As Int32
Public DFI As Int32
Public DFR As Int32
End Structure

Private Sub Form1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Click
Dim Acc As New Access.Application
Acc.OpenCurrentDatabase("D:\Program Files\Microsoft
Office\Office\Samples\Áîðåé.mdb")
Dim Cat As Access.Report
Acc.DoCmd.OpenReport("Êàòàëîã", Access.AcView.acViewDesign)
Cat = Acc.Reports(0)
Acc.Visible = True
Dim DM As DevMode_Access
DM =
CType(Marshal.PtrToStructure(Marshal.UnsafeAddrOfPinnedArrayElement(CTyp
e(Cat.PrtDevMode, Byte()), 0), GetType(DevMode_Access)), DevMode_Access)
Stop
End Sub
~

I hope this gives an idea,
Roman
 
V

veerleverbr

Hi Veerle,
I believe you should do the following (quick-&-dirty sample):
DM =
CType(Marshal.PtrToStructure(Marshal.UnsafeAddrOfPinnedArrayElement(CTyp
e(Cat.PrtDevMode, Byte()), 0), GetType(DevMode_Access)), DevMode_Access)

I hope this gives an idea,
Roman



Yes it does! This is exactly what I was looking for! Thanks a lot!
Veerle
 

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

Top