使用C#从.NET中的COM转换为二进制[] [英] Object to binary[] from COM in .NET using C#

查看:76
本文介绍了使用C#从.NET中的COM转换为二进制[]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候:

事实证明,使用.NET C#中的COM对象并不是直接在

all。

现在,我已成功使用反射来实例化对象,并且

通过Type.InvokeMember调用方法和属性,但是......


一个属性的值我检索通过:


TImagingObject.InvokeMember(" JPGData",BindingFlags.GetProperty,null,

certificateImage,null);


返回一个Object。


现在如何从这个返回的Object中获取一个byte []以将其传递给

Response。写?!

当然,我不能投入数组,而且我找不到正确的方法来获取二进制数据并实例化一个有它的数组。


真诚的,

A. Gharbeia

Greetings:
It turned out that using COM objects from .NET C# isn''t straight forward at
all.
Now, I have successfully used reflection to instantiate the object, and
invoked the methods and properties through Type.InvokeMember, but...

One property whose value I retrieve through :

TImagingObject.InvokeMember("JPGData", BindingFlags.GetProperty, null,
certificateImage, null);

returns an Object.

Now how can I obtain a byte[] out of this returned Object to pass it to
Response.Write?!
I can''t cast into an array, of course, and I can''t find the right methods to
access the binary data and instantiate an array with it.

Sincerely,
A. Gharbeia

推荐答案

现在如何从这个返回中获取一个byte [] ned Object将它传递给
Response.Write?!
我当然不能投入阵列,
Now how can I obtain a byte[] out of this returned Object to pass it to
Response.Write?!
I can''t cast into an array, of course,




为什么不呢?什么是返回对象的实际类型

(obj.GetType()。ToString())?


Mattias


-

Mattias Sj?gren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com

请回复到新闻组。



Why not? What''s the actual type of the returned object
(obj.GetType().ToString())?

Mattias

--
Mattias Sj?gren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


感谢您的回复,Mattias。


直接使用.GetType()。ToString() System.Type.InvokeMember()返回的引用(即没有先将其赋值给对象),返回System.Byte [*]。


但是,也直接将此引用传递给" Response.BinaryWrite()" (即通过将整个InvokeMember调用放在括号内),得到:


编译器错误消息:CS1502:''System.Web.HttpResponse.BinaryWrite(byte)的最佳重载方法匹配[])''有一些无效的参数


我也尝试分配对Object对象的引用并使用System.Convert.ChangeType(object,invocation.GetType())来转换对象到调用返回的类型并再次执行InvokeMember(),这次将返回的引用分配给object。我得到了同样的错误!!

" Mattias Sj?gren" <毫安******************** @ mvps.org>在留言新闻中写道:%2 **************** @ TK2MSFTNGP11.phx.gbl ...
Thank you for your response, Mattias.

Using .GetType().ToString() directly on the reference returned by System.Type.InvokeMember() (i.e. without first assigning it to an object), returns System.Byte[*].

However, passing this reference also directly to "Response.BinaryWrite()" (i.e. by placing the whole InvokeMember call within the parentheses), yields:

Compiler Error Message: CS1502: The best overloaded method match for ''System.Web.HttpResponse.BinaryWrite(byte[])'' has some invalid arguments

I also tried assigning the reference to an Object object and using System.Convert.ChangeType(object, invocation.GetType()) to convert object to the type returned by the invocation and do InvokeMember() once more, this time assigning the returned reference to object. And I got the same error!!
"Mattias Sj?gren" <ma********************@mvps.org> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl...
现在怎么样我可以从这个返回的Object中获取一个byte []来将它传递给
Response.Write?!
我当然不能将其转换为数组,
Now how can I obtain a byte[] out of this returned Object to pass it to
Response.Write?!
I can''t cast into an array, of course,



为什么不呢?什么是返回对象的实际类型
(obj.GetType()。ToString())?



Mattias

-
Mattias Sj?gren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
请仅回复新闻组。



Why not? What''s the actual type of the returned object
(obj.GetType().ToString())?



Mattias

--
Mattias Sj?gren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.



还有一件事:

在JScript.NET中完成所有工作更容易,更直接,

因为使用Type.InvokeMember调用COM方法并不成功。

然而,尝试使用

Response.BinaryWrite输出结果到HTTP流类似的错误:


System.InvalidCastException:指定的演员表是无效的。


A. Gharbeia


A。 Gharbeia" <啊*** @ heia.org>在消息中写道

news:uC ************** @ tk2msftngp13.phx.gbl ...

感谢您的回复,Mattias。


直接使用.GetType()。ToString()返回由

System.Type.InvokeMember()返回的引用(即没有先分配它是一个对象),

返回System.Byte [*]。


但是,也可以将此引用直接传递给Response.BinaryWrite() ;

(即将整个InvokeMember调用放在括号内),

产生:


编译器错误消息:CS1502:最好的重载方法匹配

''System.Web.HttpResponse.BinaryWrite(byte [])''有一些无效的参数


我也尝试过分配引用一个Object对象并使用

System.Convert.ChangeType(object,invocation.GetType())将对象转换为

调用返回的类型并执行InvokeMember()再次,这个

时间分配r eturned reference to object。我得到了同样的错误!!

" Mattias Sj?gren" <毫安******************** @ mvps.org>在消息中写道

news:%2 **************** @ TK2MSFTNGP11.phx.gbl ...
One more thing:
Doing the whole thing in JScript.NET is much easier and straighforward,
since calling the COM methods doesn''t neccessate using Type.InvokeMember.
However, attempting to output the result to the HTTP stream using
Response.BinaryWrite yields a similar error:

System.InvalidCastException: Specified cast is not valid.

A. Gharbeia

"A. Gharbeia" <ah***@heia.org> wrote in message
news:uC**************@tk2msftngp13.phx.gbl...
Thank you for your response, Mattias.

Using .GetType().ToString() directly on the reference returned by
System.Type.InvokeMember() (i.e. without first assigning it to an object),
returns System.Byte[*].

However, passing this reference also directly to "Response.BinaryWrite()"
(i.e. by placing the whole InvokeMember call within the parentheses),
yields:

Compiler Error Message: CS1502: The best overloaded method match for
''System.Web.HttpResponse.BinaryWrite(byte[])'' has some invalid arguments

I also tried assigning the reference to an Object object and using
System.Convert.ChangeType(object, invocation.GetType()) to convert object to
the type returned by the invocation and do InvokeMember() once more, this
time assigning the returned reference to object. And I got the same error!!
"Mattias Sj?gren" <ma********************@mvps.org> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
现在我如何从这个返回的Object中获取一个byte []以将它传递给
Response.Write?!
我当然不能将其转换为数组
Now how can I obtain a byte[] out of this returned Object to pass it to
Response.Write?!
I can''t cast into an array, of course,



为什么不呢?什么是返回对象的实际类型
(obj.GetType()。ToString())?

Mattias

-
Mattias Sj?gren [MVP] mattias @ mvps.org
http:// www .msjogren.net / dotnet / | http://www.dotnetinterop.com
请仅回复新闻组。



Why not? What''s the actual type of the returned object
(obj.GetType().ToString())?

Mattias

--
Mattias Sj?gren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.



这篇关于使用C#从.NET中的COM转换为二进制[]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆