VB.Net What Event is Triggered When Double-Clicking to Open Custom File? - vb.net

I have created a custom file type that is recognized by my application, and I would like to know what event is triggered when I open my application by double-clicking a file of this type. I have placed breakpoints at the beginning of handlers for Form.Shown and Form.Load, as well as at the beginning of the form's constructor, but the application never hits the breakpoints.

If you're opening the application by double-clicking on the file in your computer's filesystem the debugger built in to Visual Studio won't be attached to the application's process and so won't break at your breakpoints. You can attach the debugger to a running process, but what you're talking about happens fairly quickly, so you will almost certainly not be able to attach to the process fast enough to set your breakpoints and catch the execution as it passes them.
Ultimately, the events triggered when you open your application via a file association is no different to opening the application by running its executable file.

For using that file :
Just get your file from commandline args and process it on which event you want. My.Application.CommandLineArgs
After this if you want to debug:
You can put that arguments inside Properties-Debug- Start Options -Commandline arguments (argument will be your file)
and put breakpoint on the event where you were processing that file
Happy debuggings

If you're creating your program as a Single Instance Application, then you'll receive the Startup event for your first instance, and the StartupNextInstance event for each subsequent invocation.
Each of these events hangs off of My.Application and provides the command line parameters that were passed to each invocation.
If you're not using a Single Instance Application, the Startup event is still available.

Related

Halt code at dialog (msgbox()) command in IDE

Title quite much says it all.
In VB6, and in VBA/Access it was possible to hit break key, and jump into debug mode when using the msgbox() command.
Is there a way to do this in vb.net (desktop/winforms) applications?
Often, some code will toss up a dialog box, and it is rather nice then to jump into debug mode as a result of that message box having been displayed.
Edit
Ok, hitting pause button in most applications work, but in this application, when I hit pause, then I get this:
Edit two:
Ok, I have discovered the reason for this behavior. I have the application Frame work box un-checked. The reason for this is I did't want to specify the main application form as startup form, and I desired additional control over what occurs if the main startup form (that I don't specify) is closed. Thus, my main application form is launched via application.Run(my form)
It thus seems that due to starting the main form as a new separate application thread (which is the result of using application.Run(), then you can't use ctrl-break, or more common use/hit the pause button in the IDE to halt the code. Hitting pause will thus display that the application is running a main app thread, which indeed is the case since I use applicaiton.Run() to launch the main form from the classic and traditional Sub Main().
Edit 3
A way to fix this, and enable the pause key to work is to un-check in tools->debugging the [ ] Enable Just My Code. This will thus allow debug mode of the other "main" application thread.
Hmm. [CTRL][BREAK] clears the dialog box. However, clicking the pause button in the IDE will do what you want.
Alternatively, select Debug > Break All from the menu.

How to restrict icon handler to be accessed by a particular process?

I have a icon handler for my custom file. How I can restrict icon handler functionality so that it can be called by explorer.exe threads only?
Well, you could use GetModuleFileName(NULL) to find out which EXE your handler is loaded into. You could do that in a COM method (and return, say, E_FAIL if you think are in a wrong process), or in DllMain so that your handler fails to even load.
However, it's not clear why you would want to do this. For example, an icon handler is used by the standard Open File dialog in any application; do you not want your icon to appear there?
If you envision this as some kind of a security measure, then it won't work very well. A determined attacker would write their own shell extension, get loaded into Explorer, and access your handler from there.

Visual Studio error: "Cannot activate background task. Background Task activation failed."

When I try to launch a particular background task using Visual Studio, I currently receive the following error:
I tried pressing the Help button, which took me to How to trigger suspend, resume, and background events in Windows Store apps. The page said to look at a certain section in Event Viewer that didn't contain any entries.
The corresponding Windows Store application is both requesting background task permission and registering the task. The application is enabled for the lock screen. The application's project is referencing the background task project, and its manifest is specifying the correct fully-qualified class name of the background task. The correct type of background task has been specified in the manifest.
I was able to resolve this by changing the task registration/location code to call RequestAccessAsync before registering the background task. (Previously, it had registered the background task before asking for access.)
For some reason, this caused the application to request access again. After running the application and granting it permission, I reverted the code back to the previous state.
Now it works correctly again even though the code is the same as it was originally.
For me, I had a problem where I had updated TaskEntryPoint in my manifest but forgot to update it in my code... Frustrating to have to maintain it both places!
It got out of sync via the process of refactoring some classes into a new library, so don't forget to update after the fact if you do that!
You may be able to use reflection to help with this e.g. typeof(LocationTask).FullName
Restarting Visual Studio (2015) solved this problem for me.
You probably already did this, but sometimes one forgets about the easy things.

VS2012/ Blend 5: Debugging an Exception (only) occurring in design view

I'm developing a Metro-style app (for Windows 8) using C# and XAML. I have set up my viewmodels to be used as design-time datacontexts, like so:
xmlns:vm="using:hub.ViewModels"
d:DataContext="{d:DesignInstance IsDesignTimeCreatable=True, Type=vm:ViewModels
My app appears to work perfectly when run, but in the design views of both VS 2012 and Blend, I occasionally get this (unhelpful) error message:
An Exception was thrown. TargetException: Error in the application.
Stacktrace
at System.ComponentModel.PropertyChangedEventHandler.Invoke(Object sender, PropertyChangedEventArgs e)
InnerException: None
This only happens in the design view - meaning I can't set breakpoints around all my INotifyPropertyChanged() events.
What is the best approach to debugging design-time errors?
If this happens consistently or semi-consistently, you can attach the debugger to the XAML designer:
Start Visual Studio; open your project and open a XAML file, causing the XAML designer to load
Start a second instance of Visual Studio. Open your project but make sure no XAML documents are open.
Ensure that Just My Code is disabled: From the Tools menu, select Options. Select the Debugging category. In the General page, ensure the check box next to Enable Just My Code is unchecked.
From the Debug menu, select Exceptions... and check the Thrown check box next to Common Language Runtime Exceptions. This will enable first chance handling of all CLR exceptions. If you know the specific type of the exception, you can enable first chance handling for just that type.
From the Debug menu, select Attach to Process. In the Attach to: field, click Select... and check the Managed (v4.5, v4.0) entry in the list and click OK.
This is necessary because the debugger may misdetect the process as a native process if it attaches while the process is executing native code. If your project contains native code, you'll want to check the Native check box in the list as well (you can debug both managed and native code at the same time).
In the Available Processes list box, find the xdesproc.exe that corresponds to your project and click Attach.
If there are multiple processes (usually because you have multiple projects open or because the designer is reloading or has recently reloaded), it can be difficult to determine which designer process belongs to which Visual Studio instance. It's often easiest just to attach to all of them. A tool like Process Explorer can help you figure out which designer process belongs to which instance of Visual Studio.
Note: Do not attach the debugger to a designer process (xdesproc) that belongs to the same instance of Visual Studio that you are using for debugging: doing so is likely to cause Visual Studio to hang. You must always use two different instances of Visual Studio.
Do whatever you need to do to repro the bug. When it occurs, the debugger will break at the point where the exception is thrown. The debugger should load the symbols for your assemblies.
I got here while looking for info on how to debug designer time instance problems, though I did not have the same problem as rikkit. But...I'm sharing the solution to a related issue just in case others having the same problem reach here as well:
Make sure you have the "Enable/Disable Project Code" toggle set to "enabled"...in VS/Blend 2015 it's a small icon below the XAML editor
as shown here.
If it's disabled, this could be the reason your design time instance doesn't seem to be working.
Further, if it's disabled and you attempt to debug using a second VS instance, then when you attach to the XDesProc any breakpoints you set in the code-behind will report that they "will not currently be hit. [because] No symbols have been loaded for this document".
You might think that you need to somehow load the symbols, but if you open up the Modules window attempting to do so, you won't even see your module in the listing.
I lost a couple hours on this issue because of this setting being disabled. Hope this helps others not do the same.
I'm not sure about it but I believe you can check for the IsInDesignModeProperty Field. I remeber having to do so on WinForms sometimes.
Also take a look at this link Troubleshooting WPF Designer Load Failures

Showing DialogBox and MessageBox from DLL

I'm buisy on a DirectX10 game engine and i'm having a problem which has nothing to do with DirectX :P The problem is that in the DLL which contains the engine sometimes a DialogBox is called, just like you would do in normal win32. With the only difference that instead of the HINSTANCE i use the HMODULE which i get when loading the DLL.
Everything seems to be working fine, if i step through my code with F10 (Visual C++ 2008) i can even see it going through my DlgMessageProc function and do everything it should do. The only weird thing is that no dialog is shown and that all of a sudden it jumps out of the message loop and just continues with the rest of the code???
Weirly engough I have the same problem when calling MessageBox from inside my DLL, I get no errors, everything seems to be working fine but no window is shown, nor is the code halted (as normal with messageboxes)
The funny thing is that I have some code from a book which uses the same basic architecture as me and if i compile that everything shows just fine??
So my question, is there any hidden option, pragama comment or other thing i should look at if i want to be able to show MessageBoxes and Dialogs from my Dll?
No as i thought, chaning the manifest doesn't help at all. I also created a separate project where i just test the dialog and its proc function and there everything works perfect (links to a .exe instead of dll)
In the visual studio resource editor's property page for the dialog resource there should be an option in which you can specify - "No Fail Create: True".
Usually dialogs fail to create because a common control cannot be created - usually because InitCommonControlsEx has not been called. Setting the No Fail Create flag lets you see dialog and determine which controls are missing.
Other things to check:
Is there a message in the debug window about a first chance exception? Perhaps its 'jumping out' because of an exception that is being caught and silently handled by Win32. Turn on debugging of first chance win32 exceptions in the Dev Studio exceptions dialog to track that down.
Even this wouldn't explain how a MessageBox call would fail to create a message box.
The only times Ive seen MessageBox fail to work were when:
Resource leaks had made the process run out of available user32 handles - have you checked your apps handle counts using task manager?
the system was in the process of being shut down. Have you called PostQuitMessage and then tried to create a dialog/MessageBox?