newlife
驱动牛犊
驱动牛犊
  • 注册日期2004-11-25
  • 最后登录2005-05-29
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1192回复:3

请帮忙看看这段代码到底出错在哪?(filedisk相关)

楼主#
更多 发布于:2005-03-06 21:32
把原来的main函数改成dialog中的一个按钮触发函数。按钮函数名为oncreate

void CTestDlg::OnCreate()
{
    char*                   FileName;
    char*                   Option;
    char                    DriveLetter;
    POPEN_FILE_INFORMATION  OpenFileInformation;

FileName=\"e:\\\\img\\filedisk.img\";

    OpenFileInformation =
malloc(sizeof(OPEN_FILE_INFORMATION) + strlen(FileName) + 4);

    memset (OpenFileInformation,
0,
sizeof(OPEN_FILE_INFORMATION) + strlen(FileName) + 4);
            
    strcpy(OpenFileInformation->FileName, \"\\\\??\\\\\");//复制\\\\??\\\\到str1  
    strcat(OpenFileInformation->FileName, FileName);//连接字符串2至字符串1后面
    OpenFileInformation->FileNameLength =
    strlen(OpenFileInformation->FileName);
Option=\"1G\";
DriveLetter=\'z\';
if (Option[strlen(Option) - 1] == \'G\')
{OpenFileInformation->FileSize.QuadPart =
_atoi64(Option) * 1024 * 1024 * 1024;
}
else if (Option[strlen(Option) - 1] == \'M\')
    {
OpenFileInformation->FileSize.QuadPart =
            _atoi64(Option) * 1024 * 1024;
    }
    else if (Option[strlen(Option) - 1] == \'K\')
{
        OpenFileInformation->FileSize.QuadPart =
            _atoi64(Option) * 1024;
    }
    else
    {
        OpenFileInformation->FileSize.QuadPart =
            _atoi64(Option);
    }
Mount(0,OpenFileInformation, DriveLetter);
}

由于程序需要,先以mount功能测试是否成功,并且把一些原本main函数中不必要的变量去掉了(如DeviceNumber,Command这些)

但是vc debug提示语法错误都出现在
OpenFileInformation = malloc(sizeof(OPEN_FILE_INFORMATION) + strlen(FileName) + 4);
错误:cannot convert from \'void *\' to \'struct _OPEN_FILE_INFORMATION *\'
strcpy(OpenFileInformation->FileName, \"\\\\??\\\\\");
错误:cannot convert parameter 1 from \'unsigned char [1]\' to \'char *\'
等4个地方,为什么直接copy源代码都会出错……

顺便问问怎样才是正确编辑filedisk.sys文件的方法,用记事本打开全部是乱码

[编辑 -  3/6/05 by  newlife]
snowStart
驱动老牛
驱动老牛
  • 注册日期2004-04-06
  • 最后登录2011-06-02
  • 粉丝0
  • 关注0
  • 积分95分
  • 威望19点
  • 贡献值177点
  • 好评度1点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2005-03-07 13:31
晕!
那就强制转换一下(OPEN_FILE_INFORMATION *)malloc...
学习,关注,交流中... [email=fengyu@163.com]Email:snowstarth@163.com[/email] [url]http://bbs.zndev.com/?a=snowStart[/url]
newlife
驱动牛犊
驱动牛犊
  • 注册日期2004-11-25
  • 最后登录2005-05-29
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2005-03-07 21:27
谢楼上的。

现在我把代码改为
void CTestDlg::OnCreate()
{
    char*                   FileName;
    char*                   Option;
    char                    DriveLetter;

    POPEN_FILE_INFORMATION  OpenFileInformation;

FileName=\"e:\\
img\\filedisk.img\";

    OpenFileInformation =
(OPEN_FILE_INFORMATION *)malloc(sizeof(OPEN_FILE_INFORMATION) + strlen(FileName) + 4);

    memset
(OpenFileInformation,
0,
sizeof(OPEN_FILE_INFORMATION) + strlen(FileName) + 4
);
            
    strcpy((char *)OpenFileInformation->FileName, \"\\\\??\\\\\");//复制\\\\??\\\\到str1  
    strcat((char *)OpenFileInformation->FileName, FileName);//连接字符串2至字符串1后面

    OpenFileInformation->FileNameLength =
    strlen((char *)OpenFileInformation->FileName);

Option=\"1G\";
DriveLetter=\'z\';

if (Option[strlen(Option) - 1] == \'G\')
{
OpenFileInformation->FileSize.QuadPart =
_atoi64(Option) * 1024 * 1024 * 1024;
}
else if (Option[strlen(Option) - 1] == \'M\')
    {
OpenFileInformation->FileSize.QuadPart =
            _atoi64(Option) * 1024 * 1024;
    }
    else if (Option[strlen(Option) - 1] == \'K\')
{
        OpenFileInformation->FileSize.QuadPart =
            _atoi64(Option) * 1024;
    }
    else
    {
        OpenFileInformation->FileSize.QuadPart =
            _atoi64(Option);
    }
Mount(0,OpenFileInformation, DriveLetter);
}
后程序能运行,而且盘符(z)也出来了,但是该分区无法访问,双击显示“无法访问z:\\,设备未就绪”,使用原版filedisk也无法对其进行umont操作,只能通过重启让其消失,问题大概出现在什么地方?

[编辑 -  3/7/05 by  newlife]
tiamo
VIP专家组
VIP专家组
  • 注册日期2002-02-26
  • 最后登录2018-01-09
  • 粉丝17
  • 关注4
  • 积分50分
  • 威望142点
  • 贡献值1点
  • 好评度40点
  • 原创分2分
  • 专家分15分
  • 原创先锋奖
  • 社区居民
地板#
发布于:2005-03-10 20:16
嗯嗯
看到你的帖子了

本来在s1打算从来不发贴只潜的...哈哈

只是没有想到会有人在s1问这种问题

filedisk.sys是一个驱动程序
你安装了么
他运行正常么
你有softice么..有driverstudio么
会调试么....
游客

返回顶部