章
章慧
Unregistered / Unconfirmed
GUEST, unregistred user!
我用AutomationObject做了一个Dll想让它访问本地文件,可是IE说Invalid variant operation,怎么弄啊,请大家帮忙看一看(300分)<br />本地文件1.htm 调用我的Object
<script language=vbscript>
set VDS=CreateObject("VDSDriver.VDSDiskDriver")
call VDS.GetInfo(info)
MsgBox info // <-- 这儿是对的,显示正确,下面全部不对
call VDS.Hajimari
name="d:/111.txt"
key="RJ5LY-BOY2E-IAWCP-2FPT5-91N3G"
p=3
call VDS.CreateVDSDisk(name,p,Status) // ie说这行call 这里Invalid variant operation
MsgBox "create " &
Status
call VDS.OpenDisk(name, key, Status)
MsgBox "open " &
Status
call VDS.CreateFile("2.Doc")
MsgBox "create file " &
Status
call VDS.WriteBuffer("2.Doc","warida! daisego!",16,1,Status)
MsgBox "write " &
Status
InfoLenth = 16
call VDS.ReadBuffer("2.Doc",MyInfo,InfoLenth,1)
MsgBox "read " &
MyInfo
call VDS.Dir(MyInfo)
MsgBox "dir " &
MyInfo
call VDS.CloseDisk
call VDS.Shuuryou
call VDS.Free
</script>
我的Object如下,没什么复杂的dd啊,怎么会错的啊,-_-
Unit Process;
{$WARN SYMBOL_PLATFORM OFF}
Interface
Uses
ComObj, ActiveX, VDSDriver_TLB, StdVcl, Dialogs, Registry, Windows, Classes, Messages,
SysUtils, Variants, Controls, StdCtrls, VDS, StrUtils;
Type
TVDSDiskDriver = Class(TAutoObject, IVDSDiskDriver)
Protected
Procedure GetInfo(Out Info: OleVariant)
SafeCall;
Procedure OpenDisk(DiskFilename, Key: OleVariant
Out Status: OleVariant);
Safecall;
Procedure CloseDisk
Safecall;
Procedure Dir(Out Status: OleVariant)
Safecall;
Procedure Hajimari
Safecall;
Procedure Shuuryou
Safecall;
Procedure Lenth(Filename: OleVariant
Out Lenth: OleVariant)
Safecall;
Procedure CreateFile(Filename: OleVariant
Out Status: OleVariant);
Safecall;
Procedure DeleteFile(Filename: OleVariant
Out Status: OleVariant);
Safecall;
Procedure ReadBuffer(Filename: OleVariant
Out Buffer: OleVariant;
Var BufferLenth: OleVariant
StartPos: OleVariant)
Safecall;
Procedure WriteBuffer(Filename, Buffer, BufferLenth, StartPos: OleVariant;
Out Status: OleVariant)
Safecall;
Procedure CreateVDSDisk(Filename, MaxSector: OleVariant;
Out Status: OleVariant)
Safecall;
{ Protected declarations }
End;
Implementation
Uses
ComServ;
Const
Class_VDSDriver: TGUID = '{BEC1F9ED-E632-411E-BAD8-D3192F1AD188}';
Type
TVDSFactory = Class(TAutoObjectFactory)
Public
Procedure UpdateRegistry(Register: Boolean)
Override;
End;
Var
VDSystem: TVDSFile;
Function Nums(a:Byte):Char;
Var
b:Byte;
Begin
b:=a Mod 36;
Inc(b,48);
If b>57 Then Inc(b,7);
Nums:=Chr(b);
End;
Function EngenderNo(Orders:String):String;
Label
1,2;
Var
s:String;
a,b:Integer;
c:LongWord;
Begin
If Orders='' Then
Begin
EngenderNo:='<Invalid Computername>';
Exit;
End;
a:=Length(Orders);
c:=0;
For b:=1 to a Do Inc(c,Ord(Orders));
c:=c Mod 256;
s:='';1:
For b:=1 to a Do
Begin
s:=s+Nums(c);
Inc(c,Ord(Orders));
c:=c Mod 256;
If Length(s)=25 Then Goto 2;
End;
If Length(s)<25 Then Goto 1;2:
Orders:='';
For a:=0 to 4 Do
Begin
For b:=1 to 5 Do
Begin
Orders:=Orders+s[a*5+b];
End;
If a<4 Then Orders:=Orders+'-';
End;
EngenderNo:=Orders;
End;
Procedure TVDSFactory.UpdateRegistry(Register: Boolean);
Var
ClassID: String;
Begin
If Register Then
Begin
Inherited UpdateRegistry(Register);
ClassID := GUIDToString(Class_VDSDriver);
With TRegistry.Create do
Try
RootKey := HKEY_CLASSES_ROOT;
OpenKey('CLSID/'+ClassID+'/Implemented Categories/{7DD95801-9882-11CF-9FA9-00AA006C42C4}', True);
Finally
Free;
End;
With TRegistry.Create do
Try
RootKey := HKEY_CLASSES_ROOT;
OpenKey('CLSID/'+ClassID+'/Implemented Categories/{7DD95802-9882-11CF-9FA9-00AA006C42C4}', True);
Finally
Free;
End;
End
Else
Begin
Inherited UpdateRegistry(Register);
End;
End;
Procedure TVDSDiskDriver.GetInfo(Out Info: OleVariant);
Begin
Info:='VDS ( Virtual Disk Driver Test Version Alpha ) Floatsoft Network Software Corp.';
End;
Procedure TVDSDiskDriver.OpenDisk(DiskFilename, Key: OleVariant;
Out Status: OleVariant);
Var
s:String;
Begin
s:=EngenderNo(DiskFilename);
If s=Key Then
If VDSystem.OpenDisk(DiskFilename) Then
Begin
Status:='OK';
End
Else
Status:='FAIL'
Else
Status:='INVALID KEY';
End;
Procedure TVDSDiskDriver.CloseDisk;
Begin
VDSystem.CloseDisk;
End;
Procedure TVDSDiskDriver.Dir(Out Status: OleVariant);
Var
FileLists: FileList;
i: Integer;
s: WideString;
Begin
FileLists:=VDSystem.Dir;
s:='';
For i:=1 to FileLists.Length Do
s:=s+FileLists.Name+'|';
Status:=s;
End;
Procedure TVDSDiskDriver.Hajimari;
Begin
VDSystem:=TVDSFile.Create(Nil);
End;
Procedure TVDSDiskDriver.Shuuryou;
Begin
VDSystem.Free;
End;
Procedure TVDSDiskDriver.Lenth(Filename: OleVariant;
Out Lenth: OleVariant);
Begin
Lenth:=VDSystem.Lenth(Filename);
End;
Procedure TVDSDiskDriver.CreateFile(Filename: OleVariant;
Out Status: OleVariant);
Begin
If VDSystem.CreateFile(Filename) Then
Status:='OK'
Else
Status:='FAILED';
End;
Procedure TVDSDiskDriver.DeleteFile(Filename: OleVariant;
Out Status: OleVariant);
Begin
If VDSystem.DeleteFile(Filename) Then
Status:='OK'
Else
Status:='FAILED';
End;
Procedure TVDSDiskDriver.ReadBuffer(Filename: OleVariant;
Out Buffer: OleVariant
Var BufferLenth: OleVariant;
StartPos: OleVariant);
Var
Temp:FileContent;
i:Integer;
s:String;
Begin
Temp:=VDSystem.ReadBuffer(Filename,StartPos,BufferLenth);
s:='';
BufferLenth:=Temp.Length;
For i:=1 to Temp.Length Do
Begin
s:=s+Chr(Temp.Data[i-1]);
End;
Buffer:=s
End;
Procedure TVDSDiskDriver.WriteBuffer(Filename, Buffer, BufferLenth,
StartPos: OleVariant
Out Status: OleVariant);
Var
Temp:FileContent;
i:Integer;
s:String;
Begin
s:=Buffer;
Temp.Length:=BufferLenth;
For i:=1 to BufferLenth Do
Begin
Temp.Data[i-1]:=Ord(s);
End;
If VDSystem.WriteBuffer(Filename,StartPos,Temp) Then
Status:='OK'
Else
Status:='FAILED';
End;
Procedure TVDSDiskDriver.CreateVDSDisk(Filename, MaxSector: OleVariant;
Out Status: OleVariant);
Begin
If VDSystem.CreateVDSDisk(Filename,MaxSector) Then
Status:='OK'
Else
Status:='FAILED';
End;
Initialization
TVDSFactory.Create(ComServer, TVDSDiskDriver, Class_VDSDiskDriver,
ciMultiInstance, tmApartment);
End.
十万火急啊,谢谢大家了
<script language=vbscript>
set VDS=CreateObject("VDSDriver.VDSDiskDriver")
call VDS.GetInfo(info)
MsgBox info // <-- 这儿是对的,显示正确,下面全部不对
call VDS.Hajimari
name="d:/111.txt"
key="RJ5LY-BOY2E-IAWCP-2FPT5-91N3G"
p=3
call VDS.CreateVDSDisk(name,p,Status) // ie说这行call 这里Invalid variant operation
MsgBox "create " &
Status
call VDS.OpenDisk(name, key, Status)
MsgBox "open " &
Status
call VDS.CreateFile("2.Doc")
MsgBox "create file " &
Status
call VDS.WriteBuffer("2.Doc","warida! daisego!",16,1,Status)
MsgBox "write " &
Status
InfoLenth = 16
call VDS.ReadBuffer("2.Doc",MyInfo,InfoLenth,1)
MsgBox "read " &
MyInfo
call VDS.Dir(MyInfo)
MsgBox "dir " &
MyInfo
call VDS.CloseDisk
call VDS.Shuuryou
call VDS.Free
</script>
我的Object如下,没什么复杂的dd啊,怎么会错的啊,-_-
Unit Process;
{$WARN SYMBOL_PLATFORM OFF}
Interface
Uses
ComObj, ActiveX, VDSDriver_TLB, StdVcl, Dialogs, Registry, Windows, Classes, Messages,
SysUtils, Variants, Controls, StdCtrls, VDS, StrUtils;
Type
TVDSDiskDriver = Class(TAutoObject, IVDSDiskDriver)
Protected
Procedure GetInfo(Out Info: OleVariant)
SafeCall;
Procedure OpenDisk(DiskFilename, Key: OleVariant
Out Status: OleVariant);
Safecall;
Procedure CloseDisk
Safecall;
Procedure Dir(Out Status: OleVariant)
Safecall;
Procedure Hajimari
Safecall;
Procedure Shuuryou
Safecall;
Procedure Lenth(Filename: OleVariant
Out Lenth: OleVariant)
Safecall;
Procedure CreateFile(Filename: OleVariant
Out Status: OleVariant);
Safecall;
Procedure DeleteFile(Filename: OleVariant
Out Status: OleVariant);
Safecall;
Procedure ReadBuffer(Filename: OleVariant
Out Buffer: OleVariant;
Var BufferLenth: OleVariant
StartPos: OleVariant)
Safecall;
Procedure WriteBuffer(Filename, Buffer, BufferLenth, StartPos: OleVariant;
Out Status: OleVariant)
Safecall;
Procedure CreateVDSDisk(Filename, MaxSector: OleVariant;
Out Status: OleVariant)
Safecall;
{ Protected declarations }
End;
Implementation
Uses
ComServ;
Const
Class_VDSDriver: TGUID = '{BEC1F9ED-E632-411E-BAD8-D3192F1AD188}';
Type
TVDSFactory = Class(TAutoObjectFactory)
Public
Procedure UpdateRegistry(Register: Boolean)
Override;
End;
Var
VDSystem: TVDSFile;
Function Nums(a:Byte):Char;
Var
b:Byte;
Begin
b:=a Mod 36;
Inc(b,48);
If b>57 Then Inc(b,7);
Nums:=Chr(b);
End;
Function EngenderNo(Orders:String):String;
Label
1,2;
Var
s:String;
a,b:Integer;
c:LongWord;
Begin
If Orders='' Then
Begin
EngenderNo:='<Invalid Computername>';
Exit;
End;
a:=Length(Orders);
c:=0;
For b:=1 to a Do Inc(c,Ord(Orders));
c:=c Mod 256;
s:='';1:
For b:=1 to a Do
Begin
s:=s+Nums(c);
Inc(c,Ord(Orders));
c:=c Mod 256;
If Length(s)=25 Then Goto 2;
End;
If Length(s)<25 Then Goto 1;2:
Orders:='';
For a:=0 to 4 Do
Begin
For b:=1 to 5 Do
Begin
Orders:=Orders+s[a*5+b];
End;
If a<4 Then Orders:=Orders+'-';
End;
EngenderNo:=Orders;
End;
Procedure TVDSFactory.UpdateRegistry(Register: Boolean);
Var
ClassID: String;
Begin
If Register Then
Begin
Inherited UpdateRegistry(Register);
ClassID := GUIDToString(Class_VDSDriver);
With TRegistry.Create do
Try
RootKey := HKEY_CLASSES_ROOT;
OpenKey('CLSID/'+ClassID+'/Implemented Categories/{7DD95801-9882-11CF-9FA9-00AA006C42C4}', True);
Finally
Free;
End;
With TRegistry.Create do
Try
RootKey := HKEY_CLASSES_ROOT;
OpenKey('CLSID/'+ClassID+'/Implemented Categories/{7DD95802-9882-11CF-9FA9-00AA006C42C4}', True);
Finally
Free;
End;
End
Else
Begin
Inherited UpdateRegistry(Register);
End;
End;
Procedure TVDSDiskDriver.GetInfo(Out Info: OleVariant);
Begin
Info:='VDS ( Virtual Disk Driver Test Version Alpha ) Floatsoft Network Software Corp.';
End;
Procedure TVDSDiskDriver.OpenDisk(DiskFilename, Key: OleVariant;
Out Status: OleVariant);
Var
s:String;
Begin
s:=EngenderNo(DiskFilename);
If s=Key Then
If VDSystem.OpenDisk(DiskFilename) Then
Begin
Status:='OK';
End
Else
Status:='FAIL'
Else
Status:='INVALID KEY';
End;
Procedure TVDSDiskDriver.CloseDisk;
Begin
VDSystem.CloseDisk;
End;
Procedure TVDSDiskDriver.Dir(Out Status: OleVariant);
Var
FileLists: FileList;
i: Integer;
s: WideString;
Begin
FileLists:=VDSystem.Dir;
s:='';
For i:=1 to FileLists.Length Do
s:=s+FileLists.Name+'|';
Status:=s;
End;
Procedure TVDSDiskDriver.Hajimari;
Begin
VDSystem:=TVDSFile.Create(Nil);
End;
Procedure TVDSDiskDriver.Shuuryou;
Begin
VDSystem.Free;
End;
Procedure TVDSDiskDriver.Lenth(Filename: OleVariant;
Out Lenth: OleVariant);
Begin
Lenth:=VDSystem.Lenth(Filename);
End;
Procedure TVDSDiskDriver.CreateFile(Filename: OleVariant;
Out Status: OleVariant);
Begin
If VDSystem.CreateFile(Filename) Then
Status:='OK'
Else
Status:='FAILED';
End;
Procedure TVDSDiskDriver.DeleteFile(Filename: OleVariant;
Out Status: OleVariant);
Begin
If VDSystem.DeleteFile(Filename) Then
Status:='OK'
Else
Status:='FAILED';
End;
Procedure TVDSDiskDriver.ReadBuffer(Filename: OleVariant;
Out Buffer: OleVariant
Var BufferLenth: OleVariant;
StartPos: OleVariant);
Var
Temp:FileContent;
i:Integer;
s:String;
Begin
Temp:=VDSystem.ReadBuffer(Filename,StartPos,BufferLenth);
s:='';
BufferLenth:=Temp.Length;
For i:=1 to Temp.Length Do
Begin
s:=s+Chr(Temp.Data[i-1]);
End;
Buffer:=s
End;
Procedure TVDSDiskDriver.WriteBuffer(Filename, Buffer, BufferLenth,
StartPos: OleVariant
Out Status: OleVariant);
Var
Temp:FileContent;
i:Integer;
s:String;
Begin
s:=Buffer;
Temp.Length:=BufferLenth;
For i:=1 to BufferLenth Do
Begin
Temp.Data[i-1]:=Ord(s);
End;
If VDSystem.WriteBuffer(Filename,StartPos,Temp) Then
Status:='OK'
Else
Status:='FAILED';
End;
Procedure TVDSDiskDriver.CreateVDSDisk(Filename, MaxSector: OleVariant;
Out Status: OleVariant);
Begin
If VDSystem.CreateVDSDisk(Filename,MaxSector) Then
Status:='OK'
Else
Status:='FAILED';
End;
Initialization
TVDSFactory.Create(ComServer, TVDSDiskDriver, Class_VDSDiskDriver,
ciMultiInstance, tmApartment);
End.
十万火急啊,谢谢大家了