N
necyhk
Unregistered / Unconfirmed
GUEST, unregistred user!
大家好,我在奥林巴斯相机的二次开发遇到一个在C#调用COM接口中的VARIANT类型的函数,
C++申明如下:
HRESULT GetImage (long camNo,long objectHandle,VARIANT * pBuf,long bufSize,long offset );
在C++,delphi中都有VARIANT类型,实现起来很简单,
delphi实现
var
pBuffer:OleVariant;
p: Pointer;
Stream : TMemoryStream;
jpg:Tjpegimage;
iResult : integer;
va: Variant ;
begin
pBuffer:=VarArrayCreate([1,imageSize],varByte);
p := VarArrayLock(pBuffer) ;
iResult := self.MochaX1.GetImage(camNo,objectHandle,pBuffer,imageSize,0);
ShowMessage(IntToStr(iResult));
Stream := TMemoryStream.Create;
Stream.Position := 0;
Stream.Size := VarArrayHighBound (pBuffer, 1) - VarArrayLowBound(pBuffer, 1) + 1;
Stream.Write (p^, Stream.Size);
Stream.Position := 0;
VarArrayUnlock(pBuffer);
Stream.Position := 0;
stream.SaveToFile('d:/1.jpg');
MochaX1.SetCameraControlMode(camNo,0);
end;
可现在要在C#中实现,网上看了很多,都说用C#的Object可做为VARIANT来使用,
byte[] bt = new byte[e.imageSize];
Object[] objArry = new Object[e.imageSize];
for (int i = 0;
i < e.imageSize;
i++)
{
objArry = new Object();
objArry = bt;
}
object obj = objArry;
try
{
int k = this.axMochaX1.GetImage(e.camNo, e.objectHandle, ref obj, e.imageSize, 0);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
用此种方式,调用是成功了,可返回的数据全部是0,按SDK上说明,应jpg图片数据,我想应是类型出错了,请大家帮我看看,COM接口中的
变体类型,在C#中究竟要怎么做???急急急
C++申明如下:
HRESULT GetImage (long camNo,long objectHandle,VARIANT * pBuf,long bufSize,long offset );
在C++,delphi中都有VARIANT类型,实现起来很简单,
delphi实现
var
pBuffer:OleVariant;
p: Pointer;
Stream : TMemoryStream;
jpg:Tjpegimage;
iResult : integer;
va: Variant ;
begin
pBuffer:=VarArrayCreate([1,imageSize],varByte);
p := VarArrayLock(pBuffer) ;
iResult := self.MochaX1.GetImage(camNo,objectHandle,pBuffer,imageSize,0);
ShowMessage(IntToStr(iResult));
Stream := TMemoryStream.Create;
Stream.Position := 0;
Stream.Size := VarArrayHighBound (pBuffer, 1) - VarArrayLowBound(pBuffer, 1) + 1;
Stream.Write (p^, Stream.Size);
Stream.Position := 0;
VarArrayUnlock(pBuffer);
Stream.Position := 0;
stream.SaveToFile('d:/1.jpg');
MochaX1.SetCameraControlMode(camNo,0);
end;
可现在要在C#中实现,网上看了很多,都说用C#的Object可做为VARIANT来使用,
byte[] bt = new byte[e.imageSize];
Object[] objArry = new Object[e.imageSize];
for (int i = 0;
i < e.imageSize;
i++)
{
objArry = new Object();
objArry = bt;
}
object obj = objArry;
try
{
int k = this.axMochaX1.GetImage(e.camNo, e.objectHandle, ref obj, e.imageSize, 0);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
用此种方式,调用是成功了,可返回的数据全部是0,按SDK上说明,应jpg图片数据,我想应是类型出错了,请大家帮我看看,COM接口中的
变体类型,在C#中究竟要怎么做???急急急