软件注册站
热情软件屋

 
如何向VxD传递数组
编号: QA001423    
建立日期: 1999年7月29日 最后修改日期: 1999年7月29日
所属类别: C/C++ - DDK与硬件设备

Delphi - DDK与硬件设备
   
    所用的操作系统:Win95
    所用的编程工具:Delphi4,VtoolsD203,VC50
    我用delphi编写 应用程序,在其中创建了一个事件,开辟了一段缓存区,然后通过DeviceIoControl将事件句柄和缓存区首址传递给VxD, 在VxD中通过OnW32DeviceIoControl来接受,以备后用。
    Delphi中代码如下:(编译通过)
    procedure TMainForm.BtnStartClick(Sender: TObject);
    
var
    

    
Inbuf : array[0..2] of Pointer;
    
cbBytesReturned :Cardinal;
    
RetInfo : Integer;
    
begin
    
//pOpenVxDHandle := GetAddressOfOpenVxDHandle;
    
phEvent0^ := OpenVxDHandle(phEvent3^);
    
hVxD:= CreateFile('\\\\.\\Real_tme.vxd',0,0,nil,
    
CREATE_NEW,FILE_FLAG_DELETE_ON_CLOSE,NULL);
    
if(hVxD = INVALID_HANDLE_VALUE) then
    
showmessage('cannot load VxD');
    
Inbuf[0] := phEvent0;
    
Inbuf[1] := pMovemem;
    
DeviceIoControl(hVxD,100,@Inbuf,sizeof(Inbuf),
    
@RetInfo,sizeof(RetInfo),cbBytesReturned,nil);
    
end;
    VxD中代码如下:
    
DWORD Real_tmeDevice::OnW32DeviceIoControl(PIOCTLPARAMS pDIOCParams)
    
{
    
HANDLE* phEventToNotifyApp;
    
switch (pDIOCParams->dioc_IOCtlCode)
    
{
    
case DIOC_OPEN: // CreateFile
    
case DIOC_CLOSEHANDLE: // file closed
    
return 0;
    

    
case 100:
    
//receive and store the address of memory,the ring0Event handle
    
pBuffer = pDIOCParams->dioc_InBuf[1];// error C2036: 'void *' : unknown size
    
// error C2440: '=' : cannot convert from 'void' to 'void *'
    
// Expressions of type void cannot be converted to other types
    
phEventToNotifyApp = pDIOCParams->dioc_InBuf[0];// error C2036: 'void *' : unknown size
    
// error C2440: '=' : cannot convert from 'void' to 'void ** '
    
// Expressions of type void cannot be converted to other types
    

    
hEventToNotifyApp = *phEventToNotifyApp;
    
return 0;
    
}
    问题是:1,当把dioc_InBuf[0],dioc_InBuf[1]都改为dioc_InBuf时,errorC2036就没有了,因此,我觉得是PIOCTLPARAMS结构默认dioc_InBuf不是数组,可是我想向VxD传递两个数,如何解决呢?或者有别的什么方法吗?
    2,'void *'不能转换为别的类型,那么,我把pBuffer和phEventToNotifyApp定义为void*,是否可以呢?(李伟)
   
    问题出在VxD中。C语言中数组和指针一般等价,但void *例外,因为这个类型无法确定指针的尺寸。你可以这样:
    HANDLE * p = (HANDLE *)pDIOCParams->dioc_InBuf;
    
pBuffer = p[1];
    
phEventToNotifyApp = p[1];
    
    相关书籍:
    
《WINDOWS设备驱动程序技术内幕 》
    《实用技术:WINDOWS NT与WINDOWS 2000设备驱动及开发》
    《Windows 设备驱动程序(VXD 与 WDM)开发实务 含盘》
    《虚拟设备驱动程序开发起步与进阶》
    《WIN 9X虚拟设备驱动程序编程指南》

    

此问题由李海回答。

附加关键字:编程, 源程序, programming, source code, C/C++, MFC, C++ Builder, Borland C++, Turbo C, C, BCB, Delphi, VCL, Borland, DDK与硬件设备, hardware, ddk, vtoolsd, driver studio, winrt

   
 
把这个问题推荐给朋友
   
 
   
您的意见类别
您的名字
您的电子邮件
您的建议(请尽可能详细)
 
 

版权所有 1997-2008 热情软件屋
如果您有任何建议和意见, 请给我发个电子邮件 askpro@china-askpro.com
Web Designed by ZebraStudio