精华区 [关闭][返回]

当前位置:网易精华区>>讨论区精华>>编程开发>>C/C++>>技术精解:内存、进程、线程等>>vc在win95下直接访问内存(转载)

主题:vc在win95下直接访问内存(转载)
发信人: zelor()
整理人: wenbobo(2002-12-06 23:07:14), 站内信件
水木清华的一篇老帖,看看哪位需要(希望有点用):

【 在 lhy (xixi) 的大作中提到: 】
: 我在win95下想访问0000:0408开始的两个字节,方法是在vc4.2中嵌入汇编直接
: 访问,但这段地址好象被win95禁止访问的,一执行就出错。有什么间接的方法
: 访问这个地址呢?
the following note is for win3.x, i heard it was ok for win95,
so have a try, good luck.

------------------------------------------------------------------
Accessing Physical Memory Using Kernel Exported Selectors

Summary

In Windows, the Kernel exports a number of selectors that Windows  pro
grams
can use to access commonly used hardware memory. The  exported selecto
rs
include the following:


__0000h, __0040h, __A000h, __B000h, __B800h, __C000h, __D000h, __E000h
,
__F000h                                   

The four letters after the leading "__" represent the real mode addres
s that
the selector is for. Each of the selectors has a 64K limit.

To use one of these selectors, implement one of the following methods:


Method 1


If the code is being written in assembler, declare the selector variab
le as
follows:



      extrn MySelector:ABS
      (or "externA MySelector" using C-macros)


Then import the selector in the definition file, as follows:


      IMPORTS MySelector = KERNEL.__B000h


In the same program, if the C routines need to use the selector value,

another global selector may be declared across the assembly code and t
he
C code. Then, assign "MySelector" to the variable in the assembly code
.


Method 2

Declare an extern variable in the C routine and then use the address o
f
the extern variable as the selector. For example:


      extern WORD _MyB000h ;
      #define MySelector (&_MyB000h)


Now the variable MySelector can be used to access segment B000h.

 Remember to import it using the correct name (one more underscore). F
or
example:


      IMPORTS
           __MyB000h = KERNEL.__B000h



Method 3


GetProcAddress may also be called with the Kernel's module handle and 
the
name of the selector. The lower word of the return value is the select
or
value.

More Information

There are no protections on these selectors. Any other Windows program
 may
access them at the same time. It is strongly recommended to only use t
hese
selectors in a Windows dynamic-link library (DLL). By accessing the ha
rdware
memory only through a DLL, the Windows application is given the maximu
m
hardware independence. It will also minimize possibilities of conflict
s
raised by different Windows applications trying to access the same mem
ory
at the same time.   

--
世上惟三件事可以掀起我的激情:
 
爱情,
艺术,
编程。

※ 来源:.月光软件站 http://www.moon-soft.com.[FROM: 202.103.46.104]

[关闭][返回]