I have registered COM Class and interface written in .NET 2.0 . Now i am looking for a way to pass Bitmap object from WindowsForms .Net 4.5 application into COM component.
When i try to do this code:
Type type = Type.GetTypeFromCLSID(clsid);
source = (IBaseFilter) Activator.CreateInstance(type);
public void SetBitmap(Bitmap input)
{
IImageSourceFilter advSource = (IImageSourceFilter)source;
advSource.SetBitmapObj(input);
}
I get next exception
System.InvalidCastException
HResult=0x80004002
Message=Unable to cast COM object of type 'System.__ComObject' to class type 'System.Drawing.Bitmap'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.
Source=DShow
StackTrace:
at RTSPTestAPP.Camera.BMPtoCam.IImageSourceFilter.SetBitmapObj(Object inp)
at RTSPTestAPP.Camera.BMPtoCam.SetBitmap(Bitmap input) in C:\Users\...\BMPtoCam.cs:line 43
Passing it as byte array is not efficient and locates a lot CPU resources (and i am sending alot bitmaps from decoded videostream).
Found a way: i just develop COM component with same .net as program which will use it. Then on Type type = Type.GetTypeFromCLSID(clsid);
i'll get not raw type (System.__ComObject), instead i`ll get correct interface, with correct methods. And i just pass bitmap as argument. Its important too add reference to this assembly too.
User contributions licensed under CC BY-SA 3.0