VirtualAlloc, VirtualCopy available in WinCE

  • Thread starter Thread starter Jeroen Ceuppens
  • Start date Start date
J

Jeroen Ceuppens

Hi,

Does anybody know if the API calls VirtualAlloc, VirtualCopy are available
in WinCE through an dll import?

Thx
JC
 
Yes, they are available in Windows CE and, hence, via P/Invoke. Why would
you want them, though?

Paul T.
 
I'm working on a thesis, and at the compagny they want to know if the VA and
VC are available

Does I need an .dll import to use these API calls?

Greetz
JC
 
coredll.dll

Jeroen Ceuppens said:
I'm working on a thesis, and at the compagny they want to know if the VA and
VC are available

Does I need an .dll import to use these API calls?

Greetz
JC
 
Direct hardware access from the CF doesn't strike me as a very .NET (or very
wise) thing to be doing....
 
I've used VirtualAllocEx to allocate a buffer in another process' memory to
read window text and other data from that process, but that was on the
desktop...
 
Hi

Given the questions on "why" and VirtualAlloc,VirtualCopy I thought I'd
offer our use of them as well... Basically a C app and the cf app
communicate some data through the VirtualXXXX mechanism as follows:

<sample VB code>
Private ip As IntPtr '//at class level
ip = Win32Api.VirtualAlloc(0, 32, Win32Api.MEM_RESERVE,
Win32Api.PAGE_READWRITE Or Win32Api.PAGE_NOCACHE)
If ip.ToInt32() = 0 Then
'//"VirtualAlloc failed"
Else
If Win32Api.VirtualCopy(ip, PHYS_ADDR, 32, Win32Api.PAGE_READWRITE
Or Win32Api.PAGE_NOCACHE) = True Then
'//TODO Ensure the GC will not write over this memory
Else
'// "VirtualCopy failed"
End If
End If
</sample VB code>

....where ip is an IntPtr that contains data I can marshal into a predefined
struct... the C app uses the same mechanism except of course it writes the
data/pointer...

Cheers
Daniel
 
An interesting thought.

-Chris


Daniel Moth said:
Hi

Given the questions on "why" and VirtualAlloc,VirtualCopy I thought I'd
offer our use of them as well... Basically a C app and the cf app
communicate some data through the VirtualXXXX mechanism as follows:

<sample VB code>
Private ip As IntPtr '//at class level
ip = Win32Api.VirtualAlloc(0, 32, Win32Api.MEM_RESERVE,
Win32Api.PAGE_READWRITE Or Win32Api.PAGE_NOCACHE)
If ip.ToInt32() = 0 Then
'//"VirtualAlloc failed"
Else
If Win32Api.VirtualCopy(ip, PHYS_ADDR, 32, Win32Api.PAGE_READWRITE
Or Win32Api.PAGE_NOCACHE) = True Then
'//TODO Ensure the GC will not write over this memory
Else
'// "VirtualCopy failed"
End If
End If
</sample VB code>

...where ip is an IntPtr that contains data I can marshal into a predefined
struct... the C app uses the same mechanism except of course it writes the
data/pointer...

Cheers
Daniel
 
Interesting, but where is MEM_COMMIT?

Daniel Moth said:
Hi

Given the questions on "why" and VirtualAlloc,VirtualCopy I thought I'd
offer our use of them as well... Basically a C app and the cf app
communicate some data through the VirtualXXXX mechanism as follows:

<sample VB code>
Private ip As IntPtr '//at class level
ip = Win32Api.VirtualAlloc(0, 32, Win32Api.MEM_RESERVE,
Win32Api.PAGE_READWRITE Or Win32Api.PAGE_NOCACHE)
If ip.ToInt32() = 0 Then
'//"VirtualAlloc failed"
Else
If Win32Api.VirtualCopy(ip, PHYS_ADDR, 32, Win32Api.PAGE_READWRITE
Or Win32Api.PAGE_NOCACHE) = True Then
'//TODO Ensure the GC will not write over this memory
Else
'// "VirtualCopy failed"
End If
End If
</sample VB code>

...where ip is an IntPtr that contains data I can marshal into a predefined
struct... the C app uses the same mechanism except of course it writes the
data/pointer...

Cheers
Daniel
 
Hi

This is not paged memory... It is part of the global data area (free memory
space kicking about on our platform that noone is using) hence no need to
commit it... If I have misunderstood your question please let me know...

Cheers
Daniel
 
No, that's allright. I've only used VirtualAlloc on the desktop and there it
is apparently something different and more restricitve
 
Clarification:
VirtualAlloc allocates virtual memory but does not connect it with any
physical memory (e.g. COMMIT). VirtualCopy (the second call in the sample
code) connects the allocated virtual region to a specific physical region
and thus is performing the commit at that time. The use of these 2 functions
is particularly tricky and I don't recommend using them directly. Instead
it's best to use TransBusAddrToVirtual() - it wraps up the correct sequence
of calls to HalTranslateBusAddress and MmMapIoSpace if needed, which in turn
wraps up the calls to VirtualAlloc and VirtualCopy.
 
Back
Top