调用一个*.c文件的问题

green221 2003-08-18 06:01:52
我在一个MFC的工程里
调用这个文件

Physmem.c

//========================================================
//
// Physmem
//
//
// This program demonstrates how you can open and
// map physical memory. This is essentially the NT
// equivalent of the \dev\kmem device in UNIX.
//
//========================================================
#include <windows.h>
#include <stdio.h>
#include <memory.h>
#include <stdlib.h>
#include <string.h>
#include "native.h"

//
// Number of bytes to print per line
//
#define BYTESPERLINE 16

//
// Lines to print before pause
//
#define LINESPERSCREEN 25


//
// Functions in NTDLL that we dynamically locate
//

NTSTATUS (__stdcall *NtUnmapViewOfSection)
(
IN HANDLE ProcessHandle,
IN PVOID BaseAddress
);

NTSTATUS (__stdcall *NtOpenSection)
(
OUT PHANDLE SectionHandle,
IN ACCESS_MASK DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes
);

NTSTATUS (__stdcall *NtMapViewOfSection)
(
IN HANDLE SectionHandle,
IN HANDLE ProcessHandle,
IN OUT PVOID *BaseAddress,
IN ULONG ZeroBits,
IN ULONG CommitSize,
IN OUT PLARGE_INTEGER SectionOffset, /* optional */
IN OUT PULONG ViewSize,
IN SECTION_INHERIT InheritDisposition,
IN ULONG AllocationType,
IN ULONG Protect
);

VOID (__stdcall *RtlInitUnicodeString)
(
IN OUT PUNICODE_STRING DestinationString,
IN PCWSTR SourceString
);

ULONG (__stdcall *RtlNtStatusToDosError)
(
IN NTSTATUS Status
);

//----------------------------------------------------------------------
//
// PrintError
//
// Formats an error message for the last error
//
//----------------------------------------------------------------------
void PrintError( char *message, NTSTATUS status )
{
char *errMsg;

FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, RtlNtStatusToDosError( status ),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &errMsg, 0, NULL );
printf("%s: %s\n", message, errMsg );
LocalFree( errMsg );
}


//--------------------------------------------------------
//
// UnmapPhysicalMemory
//
// Maps a view of a section.
//
//--------------------------------------------------------
VOID UnmapPhysicalMemory( DWORD Address )
{
NTSTATUS status;

status = NtUnmapViewOfSection( (HANDLE) -1, (PVOID) Address );
if( !NT_SUCCESS(status))
{
PrintError("Unable to unmap view", status );
}
}


//--------------------------------------------------------
//
// MapPhysicalMemory
//
// Maps a view of a section.
//
//--------------------------------------------------------
BOOLEAN MapPhysicalMemory( HANDLE PhysicalMemory,
PDWORD Address, PDWORD Length,
PDWORD VirtualAddress )
{
NTSTATUS ntStatus;
PHYSICAL_ADDRESS viewBase;
char error[256];

*VirtualAddress = 0;
viewBase.QuadPart = (ULONGLONG) (*Address);
ntStatus = NtMapViewOfSection (PhysicalMemory,
(HANDLE) -1,
(PVOID) VirtualAddress,
0L,
*Length,
&viewBase,
Length,
ViewShare,
0,
PAGE_READONLY );

if( !NT_SUCCESS( ntStatus ))
{
sprintf( error, "Could not map view of %X length %X",
*Address, *Length );
PrintError( error, ntStatus );
return FALSE;
}

*Address = viewBase.LowPart;
return TRUE;
}


//--------------------------------------------------------
//
// OpensPhysicalMemory
//
// This function opens the physical memory device. It
// uses the native API since
//
//--------------------------------------------------------
HANDLE OpenPhysicalMemory()
{
NTSTATUS status;
HANDLE physmem;
UNICODE_STRING physmemString;
OBJECT_ATTRIBUTES attributes;
WCHAR physmemName[] = L"\\device\\physicalmemory";

RtlInitUnicodeString( &physmemString, physmemName );

InitializeObjectAttributes( &attributes, &physmemString,
OBJ_CASE_INSENSITIVE, NULL, NULL );
status = NtOpenSection( &physmem, SECTION_MAP_READ, &attributes );

if( !NT_SUCCESS( status ))
{
PrintError( "Could not open \\device\\physicalmemory", status );
return NULL;
}

return physmem;
}


//--------------------------------------------------------
//
// LocateNtdllEntryPoints
//
// Finds the entry points for all the functions we
// need within NTDLL.DLL.
//
//--------------------------------------------------------
BOOLEAN LocateNtdllEntryPoints()
{
if( !(RtlInitUnicodeString = (void *) GetProcAddress( GetModuleHandle("ntdll.dll"),
"RtlInitUnicodeString" )) )
{
return FALSE;
}

if( !(NtUnmapViewOfSection = (void *) GetProcAddress( GetModuleHandle("ntdll.dll"),
"NtUnmapViewOfSection" )) )
{
return FALSE;
}

if( !(NtOpenSection = (void *) GetProcAddress( GetModuleHandle("ntdll.dll"),
"NtOpenSection" )) )
{
return FALSE;
}

if( !(NtMapViewOfSection = (void *) GetProcAddress( GetModuleHandle("ntdll.dll"),
"NtMapViewOfSection" )) )
{
return FALSE;
}

if( !(RtlNtStatusToDosError = (void *) GetProcAddress( GetModuleHandle("ntdll.dll"),
"RtlNtStatusToDosError" )) )
{
return FALSE;
}
return TRUE;
}

/* My function------2001.9.29 zhouying */
/* search string in f000:0000-ffff */
ULONG FindBiosString(char* strTarget, int nLength)
{
HANDLE physmem;
DWORD vaddress, paddress, length;
BOOL bFind = 0;
int i;
void *pCur;
ULONG lSearchNum = 0 ;

//
// Load NTDLL entry points
//
if( !LocateNtdllEntryPoints() )
{
//printf("Unable to locate NTDLL entry points.\n\n");
MessageBox(NULL,"Unable to locate NTDLL entry points.","error",MB_OK);
return -1;
}

//
// Open physical memory
//
if( !(physmem = OpenPhysicalMemory()))
{
return -1;
}

paddress = 0xf0000;
length = 0xffff;

//
// Map it
//
if( !MapPhysicalMemory( physmem, &paddress, &length, &vaddress ))
{
CloseHandle( physmem );
return FALSE;
}

//here do the search
for (i = 0; i<(0xffff-nLength); i++)
{
pCur = (void*)(vaddress+i);
if (0 == memcmp(pCur, strTarget, nLength))
{
//bFind = 1;
lSearchNum ++ ;
//break;
}
}

//
// Unmap
//
UnmapPhysicalMemory( vaddress );

//
// Close physical memory section
//
CloseHandle( physmem );

return lSearchNum;

}

我也加了头文件native.h 为什么编译总是出现这个错误
fatal error C1010: unexpected end of file while looking for precompiled header directive
而别人的提供的源代码 编译这个文件却可以通过???




...全文
60 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
StdAfx 2003-08-19
  • 打赏
  • 举报
回复
//========================================================
//
// Physmem
//
//
// This program demonstrates how you can open and
// map physical memory. This is essentially the NT
// equivalent of the \dev\kmem device in UNIX.
//
//========================================================
#include <windows.h>
#include <stdio.h>
#include <memory.h>
#include <stdlib.h>
#include <string.h>
#include "native.h"

//
// Number of bytes to print per line
//
#define BYTESPERLINE 16

//
// Lines to print before pause
//
#define LINESPERSCREEN 25
// 强制使用 C 语言方式编译
#ifdef __cplusplus
extern "C"
{
#endif // __cplusplus
//下面是你的代码
...................
...................
...................
//到了你的代码的结束的地方
////////////////////////////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
}
#endif // __cplusplus
hudp 2003-08-19
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/topic/1946/1946092.xml?temp=.9622003
green221 2003-08-19
  • 打赏
  • 举报
回复
很急阿
green221 2003-08-18
  • 打赏
  • 举报
回复
还是不行 他是一个 C语言的文件

怎么编译呢?

我重新编译全部 不行啊
Luxm 2003-08-18
  • 打赏
  • 举报
回复
选择重新编译全部。
green221 2003-08-18
  • 打赏
  • 举报
回复
fatal error C1853: 'Debug/test11.pch' is not a precompiled header file created with this compiler
Error executing cl.exe.

不行啊
inwin8 2003-08-18
  • 打赏
  • 举报
回复
在这个文件中加
#include "stdafx.h"
通过该课程的学习,掌握0行代码写服务框架的服务发布,参数验证,代码生成功能,具备初步的使用能力 该项目本身设计的内容非常多,后期会逐步开放讲解框架后期内容参考:https://mp.csdn.net/editor/html/112142371与Springboot+mybatis和Springboot+jdbctemplate对比:https://editor.csdn.net/md/?articleId=106091083框架主要功能:生成自定义sql模板文件1.一键生成数据库所有列表增、删、改、查接口通过代码生成器,一键生成增、删、改、查代码,分为有代码和无代码两种方式。有代码方式可以在需要业务封装时直接调用生成的代码进行业务组装。有代码方式和无代码方式都可以直接调用访问。2.可指定单表生成接口可以指定生成那张表的数据接口,以免对已有接口造成影响。3.一键生成接口测试postman调用文件生成postman调用接口,直接导入即可测试,不需要单独也写接口文档,也不需要使用swangger在代码中单独增加注释。字段长度类型,大小一目了然。4.可生成controller、service、dao、model、自定义sql、postman测试文件可以根据实际需要进行单独配置5.接口任意参数可自动配置多维度验证比如一个参数phone,在不需要编程的情况下,可以配置验证是否为空、长度、是否是电话号码6.数据接口可以任意组合形成新的接口比如、查询学校是一个接口、查询城市是一个接口,通常情况下在前端是需要两次请求,现在可以通过一次请求自动合并两个接口的数据结果,一次性返回。而这样的组合可以是无限个组合。7.所有接口参数均可自动封装比如查询省份接口,里面有10个参数,前端传入几个参数,便可自动封装几个参数。8.所有查询接口自带分页列表查询,有码方式和无码方式,均自带分页。9.通过简单sql的编辑即可完成服务发布只要会写sql便可生成服务,不需要任何多余操作10.接口可以进行限流配置,可以根据ip、token、ak进行限流操作多维度自定义限流,可设置次数、时限、限流方式11.所有接口可以进行签名认证所有接口通过接口sign签名认证12.所有接口可以进行登录认证限制,也可单独配置不需要登录认证可以指定接口单独授权不需要登录验证,比如验证码接口13.所有接口均可设置需要验证码验证所有的接口都可以通过参数配置设置短信验证码和图片验证码14.所有查询接口均可单独设置缓存所有接口皆可设置单独缓存,缓存周期15.所有接口均可监控访问次数同一接口访问次数记录,很容易监控服务访问,可以做更细致的服务优化16.所有接口均可记录访问日志,包括请求来源请求参数、获得结果入参出参所有访问皆有详细记录17.项目中的代码可以进行自动统计代码量一键统计代码量,包括前后端代码行数和体积18.可以自动进行数据统计,可配置单表数据量统计、也可以配置定时任务数据统计自动表数据统计,方便做BI可视化报表,不需要开发直接配置即可19.可进行跨域设置跨域通过配置文件配置20.可进行IP禁用对于恶意访问ip进行封禁21.可进行访问次数限制所有接口可以进行访问次数限制22.可进行访问来源设备、应用检查验证验证请求来源所用设备和请求发起的应用

16,471

社区成员

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

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

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