Populate picture box from eID vb.net - vb.net

Hi i got form that reads eID card, smart cards
text data reads correctly
picturebox name is picLK
but last statement is a picture
in VB6 and VBA I used
me.pctLK.Picture = ReaderEngine.portrait
ReaderEngine is procedure that reads data from card
when I use command in vb.net I get an error
me.pctLK = ReaderEngine.portrait
reader is reading card, but I got this message
An unhandled exception of type 'System.InvalidCastException' occurred in Project1.exe
Additional information: Unable to cast COM object of type 'stdole.StdPictureClass' to class type 'System.Windows.Forms.PictureBox'. 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.
I am new to VB .net
Is there any suggestions?

VB.NET has a helper function in the Microsoft.VisualBasic.Compatibility.VB6.Support module, named IPictureDispToImage, which accepts an StdPictureClass object (which implements IPictureDisp) and returns a .NET System.Drawing.Image object which you can assign to the PictureBox.Image property. Be sure you appropriately dispose of the Image when you're finished with it:
Dim comImage As StdOle.StdPictureClass = ReaderEngine.portrait
If Me.picLK.Image Is Not Nothing Then
Me.picLK.Image.Dispose()
Me.picLK.Image = Nothing
End If
Dim newImage As System.Drawing.Image = Support.IPictureDispToImage( comImage )
Me.picLK.Image = newImage

Related

How to access array elements of SAFEARRAY from MS JScript?

A COM object lives in a DLL. Its IDL looks roughly like this:
[
object,
uuid(51EB4046-221E-45EF-BD63-0D31B163647C),
oleautomation,
dual,
pointer_default(unique)
]
interface IOne2OneNode : IDispatch
{
// ...
[propget, id(2), helpstring("property Vector")] HRESULT Vector([out, retval] VARIANT *pVal);
};
The DLL fills in *pVal with a SAFEARRAY of VT_R8 (using COleSafeArray).
I want to access the array elements from a JScript script that is executed with cscript.exe.
I tried node.Vector[1], but it reports
TestIDispatch.wsf(115, 2) runtime error in Microsoft JScript: 'node.Vector' is Null or not an object
(modulo German to English translation errors).
Also, typeof node.Vector reports unknown.
After reading this answer, I tried
var vec = new VBArray(node.Vector).toArray();
but it reports runtime error in Microsoft JScript: VBArray expected.
How can I access the array elements from JScript?
JScript can only process SAFEARRAYs with element type VT_VARIANT. Any other element type is incompatible.
It is correct to convert the returned array using
var vec = new VBArray(node.Vector).toArray();
but the COM server must create an array of VARIANTs, i.e., type code VT_VARIANT; VT_R8 will end up in a type mismatch error.
Found in the responses to this post.

How to access nsIHTMLEditor interface in GeckoFX?

I am trying to make a WYSIWYG HTML-editor by embedding GeckoFX in a Windows Forms application in VB.NET.
The code goes like this:
Dim Gbrowser As New GeckoWebBrowser
Gbrowser.Navigate("about:blank")
...
Gbrowser.Navigate("javascript:void(document.body.contentEditable='true')")
How can I activate and access the nsIHTMLEditor interface from within my application?
Thank you.
UPDATE
This code does not work:
Dim hEditor As nsIHTMLEditor
hEditor = Xpcom.GetService(Of nsIHTMLEditor)("#mozilla.org/editor/htmleditor;1")
hEditor = Xpcom.QueryInterface(Of nsIHTMLEditor)(hEditor)
hEditor.DecreaseFontSize()
Error in the last line: HRESULT E_FAIL has been returned from a call to a COM component.
nsIHTMLEditor is likely a per browser instance rather than a global instance (like things returned by Xpcom.GetService)
One can get a nsIEditor like this by (by supplying a Window instance)
var editingSession = Xpcom.CreateInstance<nsIEditingSession>("#mozilla.org/editor/editingsession;1");
nsIEditor editor = editingSession.GetEditorForWindow((nsIDOMWindow)Window.DomWindow);
Marshal.ReleaseComObject(editingSession);
(or you can just call the nsIEditor GeckoWebBrowser.Editor property.)
You may be able to cast this nsIEditor to a nsIHtmlEditor (although I have yet to try it)
GeckoWebBrowser browser = .....;
// Untested code
nsIHTMLEditor htmlEditor = (nsIHTMLEditor)browser.Editor;
Update:
The VB code from #GreenBear
Dim gEditor As nsIHTMLEditor:
gEditor = Gbrowser.Editor:
gEditor.DecreaseFontSize()

Cannot create ActiveX component.Error while using GetObject in autocad 2011

I am using below code to use autocad object.
Dim acadapp As AcadApplication
acadapp = GetObject(, "AutoCAD.Application")
'''and using below code to create object -------------
acadapp = CreateObject("AutoCAD.Application")
Getting error "Cannot create ActiveX component".
I tried using 18,19 and various combination as below :
acadapp = GetObject(, "AutoCAD.Application.18")
But nothing work.
Please help.
#Locke : Thanks for reply.I tried your soltion as below :
Dim acadType As Type
Try
acadapp =
System.Runtime.InteropServices.Marshal.GetActiveObject("AutoCAD.Application.18.1")
''Above code din't worked so tried below code also
' acadapp = DirectCast(Marshal.GetActiveObject("AutoCAD.Application.18.1"),
'AcadApplication)
Catch ex As Exception
acadType = Type.GetTypeFromProgID("AutoCAD.Application")
acadapp = DirectCast(Activator.CreateInstance(acadType, True), AcadApplication)
End Try
Showing Exception :
Unable to cast COM object of type 'System.__ComObject' to interface type 'AutoCAD.AcadApplication'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{8E75D910-3D21-11D2-85C4-080009A0C626}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
Here's what I typically use when dealing with AutoCAD interop. It checks for a running instance, and creates a new one if necessary:
private static AcadApplication GetAcadApp(string progId)
{
// Create the return application
AcadApplication returnApp = null;
try
{
// Try getting a running instance
returnApp = (AcadApplication)Marshal.GetActiveObject(progId);
}
catch (COMException)
{
try
{
// Try creating a new instance
Type acadType = Type.GetTypeFromProgID(progId);
returnApp = (AcadApplication)Activator.CreateInstance(acadType, true);
}
catch (COMException)
{
// Report failure
MessageBox.Show(string.Format("Cannot create object of type \"{0}\"", progId));
}
}
// Return the application
return returnApp;
}
An AcadApplication COM object can be set like this:
// Get/create an AutoCAD instance
var acadApp = getAcadApp("AutoCAD.Application.18");
Regardless of C# or VB.NET, using Marshal.GetActiveObject and Activator.CreateInstance are probably the better ways to approach this.
According to the exception, the problem is not the GetActiveObject() call, but that the returned object doesn't support the interface you're looking for. Most likely reason is that your code references a different version of AcadApplication than the one you're getting back from GetActiveObject(). Change your project to reference the COM library version for the returned AutoCAD instance, and it should work fine.

How to use Adobe Indesign API in VB.Net

I have got a sample add in for excel:
I create a object InDesign.Application
Dim myInDesign As InDesign.Application
Dim myDoc As InDesign.Document
Dim myPage As InDesign.Page
myInDesign = CType(Activator.CreateInstance(Type.GetTypeFromProgID("InDesign.Application"), True), InDesign.Application)
myDoc = myInDesign.Documents.Add
myDoc = myInDesign.ActiveDocument
InDesign opens, But the add-in shows error at:
`myInDesign = CType(Activator.CreateInstance(Type.GetTypeFromProgID("InDesign.Application"), True), InDesign.Application)`
Content of Error:
Unable to cast COM object of type 'System.__ComObject' to interface type 'InDesign.Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{ABD4CBB2-0CFE-11D1-801D-0060B03C02E4}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
Why? Can you help me?
Have you added the reference to the InDesign Type Library using vb.net's com interface?
Open the references panel in Visual Studio and choose the "COM" tab, and look for InDesign in your list. It will default to Copy Local = False.
Now you can use the COM functions just like you were writing vbs.

VB.NET Deserialize JSON to anonymous object using newtonsoft returned error

I would like to deserialize the returned JSON from a service call in VB.NET to an anonymous type but I was having error. It works in C# using dynamic type but i dont know how to do it in VB.
Here is my JSON returned from a web service call:
{"format":"png","height":564,"width":864}
Here is my VB code json above assigned to param text:
Dim testObj = Newtonsoft.Json.JsonConvert.DeserializeObject(text)
But when i tried to access testObj.format, an exception was thrown with message
{"Public member 'format' on type 'JObject' not found."}
I already have added Option Strict Off. I dont want to use an Object/Class to deserialize the JSON. If its in C# assigning this to dynamic type will be working fine.
Can anyone please help? I am not expert in VB but I need to have this running on VB. TIA
Dim js As New System.Web.Script.Serialization.JavaScriptSerializer
Dim testObj = js.Deserialize(source, New Object().GetType())
Then you can access the key(attribute name)/values via:
value=testobj(key)
One more thing, you can access your Newtonsoft key(attribute name)/values through:
value=testObj.item(key)
Dim js As New System.Web.Script.Serialization.JavaScriptSerializer
Dim DeSerialObjEventData = New With {.Prop1 = String.Empty, .Prop2 = String.Empty, .Prop3 = String.Empty}...
Dim testObj = js.DeserializeAnnonomusType(source, DeSerialObjEventData)