What are DShellFolderViewEvents and DShellFolderViewEvents_Event? - vb.net

The names make it sound like some sort of event handler.
Both were identified as an interface from Shell32 using the code below:
I can't find either of these in the MSDN libraries. Google returned some pages with code where they appeared, but I didn't see anything that really described the interface.
Public Sub ListTypes()
Dim NS As String = "Shell32"
For Each t As Type In Assembly.GetExecutingAssembly().GetTypes()
If (t.IsClass Or t.IsInterface) And t.Namespace = NS Then
Debug.Print(t.Name)
End If
Next
End Sub

Based on the definition in ShlDisp.h it appears to simply be a thin wrapper around IDispatch with a different GUID.
MIDL_INTERFACE("62112AA2-EBE4-11cf-A5FB-0020AFE7292D")
DShellFolderViewEvents : public IDispatch
{
};
It seems to be used in obtaining event notification from the shell - Raymond Chen's blog has some example code.

Related

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()

Pass parameter values from JQuery to VB.Net Function

I have here a vb.net function which accepts 2 parameters and the values that will be passed here will be coming from my jquery code. Is it possible to pass the values from jquery to vb.net? I've already read some solutions but they point out that the vb.net method should be a webmethod. In my case, the vb function is not a web method so that strikes that out. Below are some snippets of my code. Hope you could help me on this.
JQuery code
$('#TextBox_PRVNo').keypress(function (event) {
if (event.keyCode == '13') {
//basically, pass values from textbox 1 and textbox 2 to VoucherNotClaimed() method
}
});
VB.Net code
Private Function VoucherNotClaimed(ByVal strVoucherType, ByVal strPRVNo) As Boolean
' TODO: Search in database
Return True
End Function
You don't need a web service to decorate your methods with the WebMethod attribute. If you do it on a regular page, you create a so-called page method. In a nutshell:
Create a public static method in your page, decorated with the WebMethod attribute:
<WebMethod()> _
Public Shared Function VoucherNotClaimed(ByVal strVoucherType, ByVal strPRVNo) As Boolean
' TODO: Search in database
Return True
End Function
Add a ScriptManager to your ASPX page and set its EnablePageMethods property to True. Also, make sure your web.config is set up properly.
Call your method with JavaScript:
var claimed = PageMethods.VoucherNotClaimed(voucherType, prvNo);
You can find a more detailed explanation in the following MSDN article:
Exposing Web Services to Client Script (Section Calling Static Methods in an ASP.NET Web Page)
Note that this is the classic way to do it. With JQuery, it is also possible to call the page method without a ScriptManager; a quick Google search for page method jquery yields a huge amount of blog entries going into every possible detail.

Instantiating a function

This question is about a different instance that im trying to instantiate...
I have to get the "Read" function from my Cardreader class and return a string to it on the form1.vb .... Now i did what i can remeber but for some reason i'm having a problem with the brackets.... What can i do to fix this?
Form1.vb
ThisATM.getCardReader.Readr("TEST TEXT IS FUN")
CardReader.vb
Public Function Readr(ByVal card As KeyCard) As String
Return Read
End Function
Link for the image of the card reader function. I thought this link of the image of the code would be easier to understand.
The Readr function takes an KeyCard as parameter, not an string. So it seems like you have to create an instance to an KeyCard and use that as a parameter instead. In the code in the image you provided you are creating a keycard object, it seems like you should use that object in the Readr function like this:
Dim ThisKeyCard as new KeyCard("1234","5678","Mikki Monster")
Dim returnString as string=ThisATM.getCardReader.Readr(ThisKeyCard)

Context issue in IHttpHandler

Sorry, this can be a basic question for advanced VB.NET programmers but I am a beginner in VB.NET so I need your advice.
I have a web application and the login is required for some specific pages. To check if the user is logged in, the old programmer used this technique:
Dim sv As New WL.SessionVariables(Me.Context)
If Not (sv.IsLoggedIn) Then
Response.Redirect(WL.SiteMap.GetLoginURL())
End If
Well, I have to use this Logged In checking in a handler done by me and I tried this:
Public Class CustomHandler
Implements System.Web.IHttpHandler, IReadOnlySessionState
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim sv As New WL.SessionVariables(context)
If Not (sv.IsLoggedIn) Then
context.Response.Write("No access unless you're the CEO!!!" & sv.IsLoggedIn)
ElseIf sv.IsLoggedIn Then
DownloadFile(context)
Else
End If
End Sub
//other code
End Class
Well, the "is logged in" checking is always false (even after I login) and I think it's an issue with the context. So all the other pages works fine with logging checking but this handler have this specific issue.
Can you guys give a helping hand?
UPDATE:
The logged in is done trough this method:
Public Sub SetCreditialCookie(ByVal accountID As Integer)
Me.AccountID = accountID
m_context.Session.Item("loggedInAccount") = accountID
m_context.Response.Cookies.Add(New System.Web.HttpCookie("account_id", CStr(m_context.Session.Item("account_id"))))
m_context.Response.Cookies("account_id").Expires = DateTime.Now.AddDays(5)
End Sub
and to check it it's logged in, this method is called:
Public Function IsLoggedIn() As Boolean
If Not m_context.Session.Item("loggedInAccount") Is Nothing And Me.AccountID = m_context.Session.Item("loggedInAccount") Then
Return True
Else
Return False
End If
End Function
UPDATE 2:
- debugging the code shown that there were multiple kind of logins and I was checking the wrong one with the session.
Due to the use of IReadOnlySessionState, is it possible that the SessionVariables class attempts in some way to modify the Session, which in turn causes an error (possibly handled and not visible to you).
If this is the case it could mean that the IsLoggedIn property is not correctly initialised, or does not function as expected?
Do you have access to the code for the class. If so, try debugging it to see what is happening.

Accessing COM add-in code from VBA

I have created a COM add-in for Excel 2003 using Visual Studio 2005 Tools for Office. The add-in code looks like this:
[Guid("EAC0992E-AC39-4126-B851-A57BA3FA80B8")]
[ComVisible(true)]
[ProgId("NLog4VBA.Logger")]
[ClassInterface(ClassInterfaceType.AutoDual)]
public class Logger
{
public double Debug(string context, string message)
{
Trace.WriteLine(message);
return message.Length;
}
[ComRegisterFunctionAttribute]
public static void RegisterFunction(Type type)
{
Registry.ClassesRoot.CreateSubKey(GetSubKeyName(type, "Programmable"));
RegistryKey key = Registry.ClassesRoot.OpenSubKey(GetSubKeyName(type, "InprocServer32"), true);
key.SetValue("", System.Environment.SystemDirectory + #"\mscoree.dll", RegistryValueKind.String);
}
[ComUnregisterFunctionAttribute]
public static void UnregisterFunction(Type type)
{
Registry.ClassesRoot.DeleteSubKey(GetSubKeyName(type, "Programmable"), false);
}
private static string GetSubKeyName(Type type, string subKeyName)
{
System.Text.StringBuilder s = new System.Text.StringBuilder();
s.Append(#"CLSID\{");
s.Append(type.GUID.ToString().ToUpper());
s.Append(#"}\");
s.Append(subKeyName);
return s.ToString();
}
}
I've set the project to register for COM interop, and I've registered the DLL with:
regasm.exe /tlb NLog4VBA.dll
When I open Excel, I go to Tools -> Add-Ins, click Automation, and add NLog4VBA.Logger. I can then go to Insert -> Function, pick NLogVBA.Logger from the list of categories, and choose Debug.
The end result is a cell with contents like:
=Debug("My Context","My Message")
... and a displayed value of:
10
This is all as it should be. In my VBA code, I can go to Tools -> References and add NLog4VBA. I then add the following code to a button on my sheet:
Private Sub CommandButton1_Click()
Application.COMAddIns("NLog4VBA.Logger").Object.Debug "My Context", "My Message"
End Sub
This fails, because COMAddIns("NLog4VBA.Logger") fails with:
Run-time error '9': Subscript out of range
Could someone please tell me what I need to do to make the Debug() method accessible to my VBA code (which is more useful to me than being able to call the method from within a cell)?
I'm sure I'm missing something simple here.
Edited 2010/09/07: I've updated the code snippet to include the [ProgId] attribute as suggested below by Jim; the problem persists. I can see the object in registry:
[HKEY_CLASSES_ROOT\CLSID\{EAC0992E-AC39-4126-B851-A57BA3FA80B8}]
#="NLog4VBA.Logger"
[HKEY_CLASSES_ROOT\CLSID\{EAC0992E-AC39-4126-B851-A57BA3FA80B8}\Implemented Categories]
[HKEY_CLASSES_ROOT\CLSID\{EAC0992E-AC39-4126-B851-A57BA3FA80B8}\Implemented Categories\{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29}]
[HKEY_CLASSES_ROOT\CLSID\{EAC0992E-AC39-4126-B851-A57BA3FA80B8}\InprocServer32]
#="C:\\WINDOWS\\system32\\mscoree.dll"
"ThreadingModel"="Both"
"Class"="NLog4VBA.Logger"
"Assembly"="NLog4VBA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
"RuntimeVersion"="v2.0.50727"
"CodeBase"="file:///C:/projects/nlog4vba/NLog4VBA/bin/Debug/NLog4VBA.dll"
[HKEY_CLASSES_ROOT\CLSID\{EAC0992E-AC39-4126-B851-A57BA3FA80B8}\InprocServer32\1.0.0.0]
"Class"="NLog4VBA.Logger"
"Assembly"="NLog4VBA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
"RuntimeVersion"="v2.0.50727"
"CodeBase"="file:///C:/projects/nlog4vba/NLog4VBA/bin/Debug/NLog4VBA.dll"
[HKEY_CLASSES_ROOT\CLSID\{EAC0992E-AC39-4126-B851-A57BA3FA80B8}\ProgId]
#="NLog4VBA.Logger"
[HKEY_CLASSES_ROOT\CLSID\{EAC0992E-AC39-4126-B851-A57BA3FA80B8}\Programmable]
Also, the ProgID is visible in the Add-Ins dialog:
I still have no idea why this isn't working :-(
The COMAddIns collection is either indexed via a numerical index, or via a string that is the ProgId of the desired component. Make sure that your ProgId is actually "NLog4VBA.Logger" (via the ProgId attribute in .NET) and verify that the object is registered with this id (which you can easily check in the registry, searching for your assigned GUID).
It turns out that my VBA code was quite wrong; here is the answer courtesy Jan Karel Pieterse:
I think you would need to do something
like this:
Private Sub CommandButton1_Click()
'Declare an object variable using the referenced lib.
'if all is well, intellisense will tell you what the proper object name is:
Dim objLogger as NLog4VBA
'Create an instance of the object
Set objLogger = New NLog4VBA
'Now use the object
objLogger.Object.Debug "My Context", "My Message"
End Sub