468,321 Members | 1,818 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,321 developers. It's quick & easy.

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

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/de...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

Nov 21 '05 #1
2 4141
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.UnsafeAddrOfP innedArrayElement(CTyp
e(Cat.PrtDevMode, Byte()), 0), GetType(DevMode_Access)), DevMode_Access)
Stop
End Sub
~

I hope this gives an idea,
Roman
Nov 21 '05 #2
> Hi Veerle,

I believe you should do the following (quick-&-dirty sample):
DM =
CType(Marshal.PtrToStructure(Marshal.UnsafeAddrOfP innedArrayElement(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

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Jeff T. | last post: by
13 posts views Thread by Leslie Coover | last post: by
1 post views Thread by howard w | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.