Slavik
驱动牛犊
驱动牛犊
  • 注册日期2004-06-08
  • 最后登录2004-08-16
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1187回复:1

为什么VirtualCopy没有定义

楼主#
更多 发布于:2004-06-23 14:04
为什么我在evc里使用VirtualCopy,编译返回没有定义?
MSDN里有这个啊。
Slavik
驱动牛犊
驱动牛犊
  • 注册日期2004-06-08
  • 最后登录2004-08-16
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2004-06-24 10:36
我用
extern "C" __declspec(dllimport) BOOL VirtualCopy( LPVOID lpvDest, LPVOID lpvSrc, DWORD cbSize, DWORD fdwProtect );
解决了没有定义的问题。但是老是返回FALSE。
用GetLastError返回87号错误,非法参数。真莫名其妙啊。

我的代码是
//#include "stdafx.h"
#include <windows.h>
//#include <Pkfuncs.h>
#include <string.h>
#define PHYSADDR  ((PVOID)0x0080000024)
// PHYSADDR is the physical address of the peripheral
// registers

extern "C" __declspec(dllimport) BOOL VirtualCopy( LPVOID lpvDest, LPVOID lpvSrc,
DWORD cbSize, DWORD fdwProtect );

#define SIZE  (4800*4)

void ShowError( LPTSTR message ) {

static RECT rect = { 0, 0, 640, 15 };
static HDC hdc = GetDC(0);

DWORD error = GetLastError();
TCHAR lpMsgBuf[100];

wsprintf( lpMsgBuf, TEXT("%Xn"), error );

DrawText( hdc, lpMsgBuf, wcslen( lpMsgBuf ), &rect, DT_NOCLIP|DT_SINGLELINE );
rect.top += 15;
rect.bottom += 15;

// Process any inserts in lpMsgBuf.
// ...
// Display the string.
OutputDebugString( message );
OutputDebugString( lpMsgBuf );
OutputDebugString( L"n" );
// Free the buffer.
//LocalFree( lpMsgBuf );
}

int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR    lpCmdLine,
int       nCmdShow)
{
  // TODO: Place code here.
TCHAR buf[100];

LPVOID lpv;
WORD* io;
BOOL bRet;

lpv = VirtualAlloc( 0, SIZE, MEM_RESERVE, PAGE_NOACCESS);
// For a user mode driver, always leave the first
// parameter 0 and use only the flags MEM_RESERVE
// and PAGE_NOACCESS Check the return value: lpv == 0
// is an error

wsprintf( buf, TEXT("VirtualAlloc reservation @%8.8lxrn"), lpv);
OutputDebugString( buf );
bRet = VirtualCopy( lpv, PHYSADDR, SIZE, PAGE_READWRITE | PAGE_NOCACHE);
// The lpv parameter is the virtual address returned
// by VirtualAlloc().
// Always use PAGE_NOCACHE */

// Check the return value: bRet ==0 is an error */
wsprintf( buf, TEXT("VirtualCopy returned: %drn"), bRet);
OutputDebugString( buf );

if( bRet == FALSE ) {
ShowError( TEXT("FAILEDn") );
return -1;
}

// At this point lpv is a virtual address which maps
// the I/O registers
// at PHYSADDR for SIZE bytes */
io = (WORD*)lpv;
*io = 1;
while( true ) {
*io = ~(*io);
Sleep(1000);
}

return 0;
}
那位能帮我看看吗?

[编辑 -  6/25/04 by  Slavik]
游客

返回顶部