函数问题

wshcdr 2004-04-05 02:38:40
我的文件中包含了MapUserPhysicalPages
尽管INCLUDE了Windows.h,还是死活编译不过

哪个大侠说说呢
...全文
58 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
byf2002 2004-04-14
  • 打赏
  • 举报
回复
另外:


MapUserPhysicalPages
The MapUserPhysicalPages function maps previously allocated physical memory pages at the specified address within an Address Windowing Extensions (AWE) region.

To perform "batch" mapping and unmapping of multiple regions, use the MapUserPhysicalPagesScatter function.

BOOL MapUserPhysicalPages(
PVOID lpAddress, // starting address of region
ULONG_PTR NumberOfPages, // size of physical memory
PULONG_PTR UserPfnArray // array of page frame numbers
);
Parameters
lpAddress
[in] Pointer to the starting address of the region of memory to remap. The value of lpAddress must be within the address range returned by the VirtualAlloc function when the AWE region was allocated.
NumberOfPages
[in] Specifies the size, in pages, of the physical memory (and virtual address space) to establish translations for. The virtual address range is contiguous starting at lpAddress. The physical frames are specified by the UserPfnArray. The total number of pages cannot extend from the starting address beyond the end of the range specified in AllocateUserPhysicalPages.
UserPfnArray
[in] Specifies the address of an array of physical page frame numbers. These frames will be mapped by the argument lpAddress upon return from this function. The size of the memory allocated should be at least NumberOfPages times the size of the data type ULONG_PTR.
Do not attempt to modify this buffer. It contains operating system data, corruption of which could be catastrophic. There is no information in it that is useful to your application.

Specifying NULL for this parameter results in the specified address range being unmapped. (The specified physical pages are not freed. You must call FreeUserPhysicalPages to free them.)

Return Values
If the function succeeds, the return value is TRUE.

If the function fails, the return value is FALSE and no mapping (partial or otherwise) will have been done. To get extended error information, call GetLastError.

Remarks
Any number of physical memory pages can be specified, provided the memory would not extend outside the virtual address space allocated by VirtualAlloc. Any existing address maps are automatically overwritten with the new translations, and the old translations are unmapped.

You cannot map physical memory pages outside the range specified in AllocateUserPhysicalPages.

Note The physical pages are unmapped but they are not freed. You must call FreeUserPhysicalPages to free the physical pages.

Physical pages can reside at any physical address. You should make no assumptions about the contiguity of the physical pages.

To simply unmap the current address range, specify NULL as the physical memory page array parameter. Any currently mapped pages are unmapped, but are not freed. You must call FreeUserPhysicalPages to free the physical pages.

In a multiprocessor environment, this function maintains hardware translation buffer coherence. Upon return from this function, all threads on all processors are guaranteed to see the correct mapping.

Requirements
Windows NT/2000: Requires Windows 2000.
Windows 95/98: Unsupported.
Header: Declared in Winbase.h; include Windows.h.
Library: Use Kernel32.lib.

byf2002 2004-04-14
  • 打赏
  • 举报
回复
给你个例子吧:

#include <windows.h>
#include <stdio.h>

#define MEMORY_REQUESTED 1024*1024 // request a megabyte

BOOL
LoggedSetLockPagesPrivilege ( HANDLE hProcess,
BOOL bEnable);

void _cdecl main()
{
BOOL bResult; // generic boolean value
ULONG_PTR NumberOfPages, // number of pages we will request
NumberOfPagesInitial; // initial number of pages requested
ULONG_PTR *aPFNs; // page info; holds opaque data
PVOID lpMemReserved; // AWE window
SYSTEM_INFO sSysInfo; // useful system information
int PFNArraySize; // memory to request for PFN array

GetSystemInfo(&sSysInfo); // populate the system information structure

printf ("This computer has a page size of %d.\n", sSysInfo.dwPageSize);

// Calculate the number of pages of memory we'll request.

NumberOfPages = MEMORY_REQUESTED/sSysInfo.dwPageSize;
printf ("Requesting %d pages of memory.\n", NumberOfPages);

// Calculate the size of the user PFN array.

PFNArraySize = NumberOfPages * sizeof (ULONG_PTR);

printf ("Requesting a PFN array of %d bytes.\n", PFNArraySize);

aPFNs = (ULONG_PTR *) HeapAlloc (GetProcessHeap (), 0, PFNArraySize);

if (aPFNs == NULL) {
printf ("Failed to allocate on heap.\n");
return;
}

// Enable the privilege.

if( ! LoggedSetLockPagesPrivilege( GetCurrentProcess(), TRUE ) ) {
return;
}

// Allocate the physical memory we want.

NumberOfPagesInitial = NumberOfPages;
bResult = AllocateUserPhysicalPages( GetCurrentProcess(),
&NumberOfPages,
aPFNs );

if( bResult != TRUE )
{
printf("Cannot allocate physical pages, error %u.\n", GetLastError() );
return;
}

if( NumberOfPagesInitial != NumberOfPages )
{
printf("Allocated only %p pages.\n", NumberOfPages );
return;
}

// Reserve the virtual memory.

lpMemReserved = VirtualAlloc( NULL,
MEMORY_REQUESTED,
MEM_RESERVE | MEM_PHYSICAL,
PAGE_READWRITE );

if( lpMemReserved == NULL )
{
printf("Cannot reserve memory.\n");
return;
}

// Map the physical memory into our window.

bResult = MapUserPhysicalPages( lpMemReserved,
NumberOfPages,
aPFNs );

if( bResult != TRUE )
{
printf("MapUserPhysicalPages failed to map, error %u.\n", GetLastError() );
return;
}

// unmap

bResult = MapUserPhysicalPages( lpMemReserved,
NumberOfPages,
NULL );

if( bResult != TRUE )
{
printf("MapUserPhysicalPages failed to unmap, error %u.\n", GetLastError() );
return;
}

// Free the physical pages.

bResult = FreeUserPhysicalPages( GetCurrentProcess(),
&NumberOfPages,
aPFNs );

if( bResult != TRUE )
{
printf("Cannot free physical pages, error %u.\n", GetLastError() );
return;
}

// Free virtual memory.

bResult = VirtualFree( lpMemReserved,
0,
MEM_RELEASE );
}

/*****************************************************************
LoggedSetLockPagesPrivilege: a function to obtain, if possible, or
release the privilege of locking physical pages.

Inputs:

HANDLE hProcess: Handle for the process for which we seek the
privilege

BOOL bEnable: Shall we enable (TRUE) or disable?

Return value: TRUE indicates success, FALSE failure.

*****************************************************************/
BOOL
LoggedSetLockPagesPrivilege ( HANDLE hProcess,
BOOL bEnable)
{
struct {
DWORD Count;
LUID_AND_ATTRIBUTES Privilege [1];
} Info;

HANDLE Token;
BOOL Result;

// Open the token.

Result = OpenProcessToken ( hProcess,
TOKEN_ADJUST_PRIVILEGES,
& Token);

if( Result != TRUE ) {
printf( "Cannot open process token.\n" );
return FALSE;
}

// Enable or disable?

Info.Count = 1;
if( bEnable )
{
Info.Privilege[0].Attributes = SE_PRIVILEGE_ENABLED;
}
else
{
Info.Privilege[0].Attributes = 0;
}

// Get the LUID.

Result = LookupPrivilegeValue ( NULL,
SE_LOCK_MEMORY_NAME,
&(Info.Privilege[0].Luid));

if( Result != TRUE )
{
printf( "Cannot get privilege value for %s.\n", SE_LOCK_MEMORY_NAME );
return FALSE;
}

// Adjust the privilege.

Result = AdjustTokenPrivileges ( Token, FALSE,
(PTOKEN_PRIVILEGES) &Info,
NULL, NULL, NULL);

// Check the result.

if( Result != TRUE )
{
printf ("Cannot adjust token privileges, error %u.\n", GetLastError() );
return FALSE;
}
else
{
if( GetLastError() != ERROR_SUCCESS )
{
printf ("Cannot enable SE_LOCK_MEMORY privilege, please check the local policy.\n");
return FALSE;
}
}

CloseHandle( Token );

return TRUE;
}
byf2002 2004-04-14
  • 打赏
  • 举报
回复
编译不通过,出现什么提示啊.

讲详细点

你惜字如金哪.
wshcdr 2004-04-14
  • 打赏
  • 举报
回复
用 GetLastError 看看返回什么错误.
===========

编译都不过的,怎么看?
我是不知道了
王国凡 2004-04-07
  • 打赏
  • 举报
回复
用 GetLastError 看看返回什么错误.
wshcdr 2004-04-07
  • 打赏
  • 举报
回复
还有就是只能在2000以后的系统中使用

=========
是在WIN2K下使用的
wshcdr 2004-04-06
  • 打赏
  • 举报
回复
已经包含了Kernerl32.lib

还是不行

新建了一个Win32 Application的工程
也是编译不过

郁闷
pomelowu 2004-04-06
  • 打赏
  • 举报
回复
还有就是只能在2000以后的系统中使用
pomelowu 2004-04-06
  • 打赏
  • 举报
回复
在选项中看看有没有添加Kernel32.lib所在的路径。
pomelowu 2004-04-05
  • 打赏
  • 举报
回复
是Windows.h,但是还要包含库文件Kernel32.lib.

QunKangLi 2004-04-05
  • 打赏
  • 举报
回复
W2K以上版本才支持.
在#include <Windows.h>前加上:
#define _WIN32_WINNT 0x0500
快乐鹦鹉 2004-04-05
  • 打赏
  • 举报
回复
可是MapUserPhysicalPages函数好像不在WIndow.h中啊。
酒红绿叶 2004-04-05
  • 打赏
  • 举报
回复
新建一个程序,只写这一个东西!
看看是不是由于别的东西造成的!

我也遇到过这种情况!
虽然不是这个,
就是死活不对!



16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧