Has anyone used CopyMemory with DotNet?
In this instance I define it as:
Private Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" (ByRef
hpvDest As DEVMODE, ByRef hpvSource As Byte, ByVal cbCopy As Integer)
Private Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" (ByRef
hpvDest As Byte, ByRef hpvSource As DEVMODE, ByVal cbCopy As Integer)
and use it with
Call CopyMemory(pDevMode, aDevMode(1), Len(pDevMode))
where
Dim pDevMode As New DEVMODE
Dim aDevMode() As Byte
and
Private Structure DEVMODE
<VBFixedArray(CCHDEVICENAME)> Dim dmDeviceName() As Byte
Dim dmSpecVersion As Short
Dim dmDriverVersion As Short
Dim dmSize As Short
Dim dmDriverExtra As Short
Dim dmFields As Integer
Dim dmOrientation As Short
Dim dmPaperSize As Short
Dim dmPaperLength As Short
Dim dmPaperWidth As Short
Dim dmScale As Short
Dim dmCopies As Short
Dim dmDefaultSource As Short
Dim dmPrintQuality As Short
Dim dmColor As Short
Dim dmDuplex As Short
Dim dmYResolution As Short
Dim dmTTOption As Short
Dim dmCollate As Short
<VBFixedArray(CCHFORMNAME)> Dim dmFormName() As Byte
Dim dmUnusedPadding As Short
Dim dmBitsPerPel As Short
Dim dmPelsWidth As Integer
Dim dmPelsHeight As Integer
Dim dmDisplayFlags As Integer
Dim dmDisplayFrequency As Integer
End Structure
Plus I do
ReDim pDevMode.dmDeviceName(CCHDEVICENAME)
ReDim pDevMode.dmFormName(CCHFORMNAME)
Thanks,
CAl 5 5639
Hi,
I have used copymemory with vb.net. I do prefer to use the
Marshal class whenever possible. Is there a problem with your code? http://msdn.microsoft.com/library/de...mberstopic.asp
Ken
-----------------
" active" <ac****@REMOVEa-znet.com> wrote in message
news:uh**************@TK2MSFTNGP11.phx.gbl... Has anyone used CopyMemory with DotNet? In this instance I define it as: Private Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" (ByRef hpvDest As DEVMODE, ByRef hpvSource As Byte, ByVal cbCopy As Integer)
Private Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" (ByRef hpvDest As Byte, ByRef hpvSource As DEVMODE, ByVal cbCopy As Integer)
and use it with
Call CopyMemory(pDevMode, aDevMode(1), Len(pDevMode)) where
Dim pDevMode As New DEVMODE
Dim aDevMode() As Byte
and Private Structure DEVMODE
<VBFixedArray(CCHDEVICENAME)> Dim dmDeviceName() As Byte
Dim dmSpecVersion As Short
Dim dmDriverVersion As Short
Dim dmSize As Short
Dim dmDriverExtra As Short
Dim dmFields As Integer
Dim dmOrientation As Short
Dim dmPaperSize As Short
Dim dmPaperLength As Short
Dim dmPaperWidth As Short
Dim dmScale As Short
Dim dmCopies As Short
Dim dmDefaultSource As Short
Dim dmPrintQuality As Short
Dim dmColor As Short
Dim dmDuplex As Short
Dim dmYResolution As Short
Dim dmTTOption As Short
Dim dmCollate As Short
<VBFixedArray(CCHFORMNAME)> Dim dmFormName() As Byte
Dim dmUnusedPadding As Short
Dim dmBitsPerPel As Short
Dim dmPelsWidth As Integer
Dim dmPelsHeight As Integer
Dim dmDisplayFlags As Integer
Dim dmDisplayFrequency As Integer
End Structure Plus I do
ReDim pDevMode.dmDeviceName(CCHDEVICENAME)
ReDim pDevMode.dmFormName(CCHFORMNAME) Thanks,
CAl
I get a "Object reference not set to an instance of an object." at the
CopyMemory
If my Declares look OK maybe it's the structure that is giving me the
problem. It was generated by the conversion wizard.
Have you used DEVMODE?
I've read some about Marshaling and tried some things but probably need more
samples.
I'll look at the site you included and see if that helps.
Thanks for replying,
Cal
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:uQ**************@TK2MSFTNGP12.phx.gbl... Hi,
I have used copymemory with vb.net. I do prefer to use
the Marshal class whenever possible. Is there a problem with your code?
http://msdn.microsoft.com/library/de...mberstopic.asp Ken ----------------- " active" <ac****@REMOVEa-znet.com> wrote in message news:uh**************@TK2MSFTNGP11.phx.gbl... Has anyone used CopyMemory with DotNet? In this instance I define it as: Private Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory"
(ByRef hpvDest As DEVMODE, ByRef hpvSource As Byte, ByVal cbCopy As Integer)
Private Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory"
(ByRef hpvDest As Byte, ByRef hpvSource As DEVMODE, ByVal cbCopy As Integer)
and use it with
Call CopyMemory(pDevMode, aDevMode(1), Len(pDevMode)) where
Dim pDevMode As New DEVMODE
Dim aDevMode() As Byte
and Private Structure DEVMODE
<VBFixedArray(CCHDEVICENAME)> Dim dmDeviceName() As Byte
Dim dmSpecVersion As Short
Dim dmDriverVersion As Short
Dim dmSize As Short
Dim dmDriverExtra As Short
Dim dmFields As Integer
Dim dmOrientation As Short
Dim dmPaperSize As Short
Dim dmPaperLength As Short
Dim dmPaperWidth As Short
Dim dmScale As Short
Dim dmCopies As Short
Dim dmDefaultSource As Short
Dim dmPrintQuality As Short
Dim dmColor As Short
Dim dmDuplex As Short
Dim dmYResolution As Short
Dim dmTTOption As Short
Dim dmCollate As Short
<VBFixedArray(CCHFORMNAME)> Dim dmFormName() As Byte
Dim dmUnusedPadding As Short
Dim dmBitsPerPel As Short
Dim dmPelsWidth As Integer
Dim dmPelsHeight As Integer
Dim dmDisplayFlags As Integer
Dim dmDisplayFrequency As Integer
End Structure Plus I do
ReDim pDevMode.dmDeviceName(CCHDEVICENAME)
ReDim pDevMode.dmFormName(CCHFORMNAME) Thanks,
CAl
Your reference helpped a lot. I looked at Marshal in the past with regard
to Declare parameters and did not notice the Copy method.
I still have a stumbling block - I don't know how to create an IntPtr for
the Copy, that points to the DEVMODE variable.
Got a suggestion?
Cal If my Declares look OK maybe it's the structure that is giving me the problem. It was generated by the conversion wizard.
Have you used DEVMODE? I still have a stumbling block - I don't know how to create an IntPtr for the Copy, that points to the DEVMODE variable.
You should probably look at the PtrToStructure and StructureToPtr
methods rather than Copy.
Where do you get the source data (aDevMode) from? Have you used DEVMODE?
For a discussion on how to properly declare DEVMODE (in C#, but the
same applies to VB.NET) see http://blogs.gotdotnet.com/anathan/p...7-9e63033ec112
Specifically, you should add <MarshalAs(UnmanagedType.ByValArray,
SizeConst:=TheArraySize)> to the array members.
Mattias
--
Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Thanks, you've given me plenty to investigate,
Cal
"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:OK**************@TK2MSFTNGP12.phx.gbl... I still have a stumbling block - I don't know how to create an IntPtr for the Copy, that points to the DEVMODE variable. You should probably look at the PtrToStructure and StructureToPtr methods rather than Copy.
Where do you get the source data (aDevMode) from?
Have you used DEVMODE?
For a discussion on how to properly declare DEVMODE (in C#, but the same applies to VB.NET) see
http://blogs.gotdotnet.com/anathan/p...7-9e63033ec112 Specifically, you should add <MarshalAs(UnmanagedType.ByValArray, SizeConst:=TheArraySize)> to the array members. Mattias
-- Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Mikael Lundberg |
last post by:
Hi!
Just one question
Is it legal to copy the array descriptor in this way :
Dim lngArr1() as Long
Dim lngArr2() as Long
Redim lngArr1(2) as Long
|
by: RaviAmbani |
last post by:
I am facing a problem in copymemory api in vb.net .
the problem is that i have used copymemory api extensively in my
project originally written in vb6.0 ,
now when i'm migrating my project to...
|
by: Paul W |
last post by:
Hello Group,
I'm a .net newbie with a couple of questions. First, Debug.WriteLine()
doesn't send any output to the immediate window, anybody know why that might
be?
Second, what is the .net...
|
by: Turtle |
last post by:
I've been using SendKeys to automate a small utility which doesn't expose an
automation interface, but ran into a problem, for which I found the
suggestion that I use the WinAPI SendInput call...
|
by: Dennis |
last post by:
I am trying to use CopyMemory to copy arrays as follows:
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal
pDst As Long, ByVal pSrc As Long, ByVal ByteLen As Integer)
...
|
by: android |
last post by:
Hi all.
I should migrate old vb6 code in vb.net but I been clashed with the copymemory api!
Here below is a vb6 method that manages the current sample of a waveform file in a buffer for retrieving...
|
by: vb newbie |
last post by:
I need to copy the contents of one byte array to another one. I was
hoping to do it quickly uisng the CopyMemory api call. However, I'm
getting:
FatalExecutionEngineError was detected...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |