找回密码
 注册
搜索
查看: 595|回复: 1

[ARM资料] 编写的一个C语言调用COM的函数,请指教!

[复制链接]
发表于 2008-5-29 09:18:08 | 显示全部楼层 |阅读模式
我编写了一个用C语言程序,过程是将COMMAND.COM文件读入到内存中,然后从该内存地址开始执行。但总是重启?请高人指点。
我的系统:在WINDOWS2000 SERVER下装了一个VMware Workstation,虚拟计算机中装的是MS_DOS7.1 PROMPT版本。
源程序:
  #include "stdio.h"
#include<stdlib.h>

void main()
{
struct st
{
     short exSignature;
     short exExraBytes;
     short exPages;
     short exRelocItems;
     short exHeaderSize;
     short exMinAlloc;
     short exMaxAlloc;
     short exInitSS;
     short exInitSP;
     short exChechSum;
     short exInitIP;
     short exInitCS;
     short exRelocTable;
     short exOverlay;
}fhandle;


FILE *fp;
char ch[28];
unsigned long temp,i;
char a,b;
long *p;
void(*p1)();
fp=fopen("D:\\program\\c\\command.com","rb");
if (fp==NULL)
{
     printf("error\n");
     getch();
     exit(0);
}
else printf("the file has been open!\n");
fseek(fp,0L,SEEK_END);
temp=(unsigned long)ftell(fp);
printf("%x\n",temp);
getch();
printf("now,let's go!\n");
i=0;
fseek(fp,0,SEEK_SET);
p=malloc(temp);
if(p==NULL)
  {
      printf("the memory is not enought!\n");
      getch();
      exit(0);
  }
b=fread(p,temp,1,fp);
if (b==0)
{
     printf("read failure");
     getch();
     fclose(fp);
     exit(0);
}
printf("the file has been read into the memory!\n");
getch();
*p1=(void*)(256+p);
p1();


getch();
free(p);
fclose(fp);
}
[此贴子已经被作者于2008-5-30 8:14:33编辑过]
 楼主| 发表于 2008-5-31 16:33:39 | 显示全部楼层
希望高人指点
点评回复

使用道具 举报

高级模式
B Color Image Link Quote Code Smilies

本版积分规则

Archiver|手机版|小黑屋|52RD我爱研发网 ( 沪ICP备2022007804号-2 )

GMT+8, 2024-11-25 14:29 , Processed in 0.122419 second(s), 16 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表