Can you intercept or overwrite an IPreviewHandler of docx files? - winapi

In my previous investigation I discovered that even though windows file explorer launches word.exe in an embedded state the Documents collection remains empty.
Excel and word opened in Windows Explorer preview panel have Workbooks.Count and Documents.Count equal to 0
A bit further research when I made the embedded applications visible they would load with out a document inside of it:
public static class WordAppExt
{
public static Word.Document GetActiveDoc(this Word.Application App)
{
try
{
App.Visible = true;
if (App.Documents.Count > 0)
{
return App.ActiveDocument;
}
else
{
return null;
}
}
catch (Exception)
{
return null;
}
}
}
SO I came to the conclusion that explorer only needs to launch word, but it does not have the documents hosted inside of word. which means windows explorer is likely a IOleContainer. If true this means any object embedded in the preview pane can be accessed via EnumObjects.
Unfortunately my code runs in a VSTO addin, I don't have access to the explorer com objects so I can't do a QI for IOleContainer. But I have a theory that there maybe another way of accessing the Document COM object, through the PreviewHandler. I think that the reason Word, Powerpoint, and Excel get launched is either to register or initialization of the previewHandler?
So HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\PreviewHandlers has a list of guids associated with IPreviewHandler for different file types.
There are plenty of articles about how to create your own previewHandler for new file types:
Building Preview Handlers
How to Register a Preview Handler
PreviewHandler.cs
Hosting Preview Handlers in Windows Forms Applications
Preview Handlers Revisited
http://www.codeproject.com/Articles/19744/Using-Preview-Handlers-in-Windows-Vista
https://code.msdn.microsoft.com/CppShellExtPreviewHandler-58db53b8
But I want to replace Words Preview Handler with my own. If I can't replace it I'd be more than happy to intercept the existing Preview Handler.

Related

Aspose - The invoked member is not supported in a dynamic assembly. in mscrm

My case : I am running a job combining dynamics crm that uses aspose to create pdf files, everything was working fine suddenly I got the error - The invoked member is not supported in a dynamic assembly. At the current moment In my dev environment everything works fine only In my qa environment I get that exception. I checked the path I use it is correct. I tried to put the licence near the dll file in a specific file etc'... still I get this msg, what is the solution in my case ?
my function:
public void EnsureAsposeLicenseIsSet()
{
if (!AsposeLicenseWasSet)
{
lock ("EnsureAsposeLicenseIsSet")
{
if (!AsposeLicenseWasSet)
{
License wordLicense = new License();
wordLicense.SetLicense(GetConfigByKey("Asposelicence"));
AsposeLicenseWasSet = true;
}
}
}
}
Include the Aspose license file as an Embedded resource instead, and it will work.

Outlook VSTO form does not display in release version (installed)

Thanks for looking.
I am working on an Outlook plugin that includes a pop-up Form that loads a browser inside of it to allow the user to log in via a 3rd party auth service.
This works great when running from a debug session: I see the custom tab in the ribbon, click the "login" button, and the form pops up as a modal using .ShowDialog().
I am using Outlook 2016.
Problem
When I publish this VSTO and then install it on my machine, the plugin loads and I can see the "login" button in the custom ribbon tab, but clicking it does nothing. I have checked to be sure that the dialog isn't simply popping under the main form. If it's there--I can't find it.
Back to debug session--everything works great. I suspect a permissions issue, but I don't get any prompts or errors from Outlook.
Last, I don't know if it's related, but I sent the VSTO installer to a colleague and they get the following error when attempting to install:
System.Security.SecurityException: Customized functionality in this
application will not work because the certificate used to sign the
deployment manifest for {APP NAME REMOVED} or its location is not
trusted. Contact your administrator for further assistance.
Any help is greatly appreciated.
Most probably your form is shown behind the Outlook window. You need to specify the parent window handle if you want to see the form all the time on top of Outlook windows. The Show and ShowDialog methods of the System.Windows.Forms.Form class allows to specify the parent window handle by passing an instance of the IWin32Window interface as a parameter.
First, you need a class which implements that interface:
public class WindowWrapper : System.Windows.Forms.IWin32Window
{
public WindowWrapper(IntPtr handle)
{
_hwnd = handle;
}
public IntPtr Handle
{
get
{
return _hwnd;
}
}
private IntPtr _hwnd;
}
In Outlook you can cast an instance of the Explorer or Inspector class to the IOleWindow interface and get the window handle which can be used for the IWin32Window implementation.

Possible to pre-activate Xposed module without manually activating them via GUI?

Is it possible to activate Xposed-modules automatically rather than checking them to be active in the Xposed GUI? Is the enabled status of the modules stored somewhere easily accessible (on a rooted device)...?
You can achieve this by modifying the conf/modules.list file in the Xposed Installer data directory, simply add the path of your APK file to the list.
You should also modify the shared_prefs/enabled_modules.xml file, so that your change is reflected within Xposed Installer (otherwise, the module will be enabled but will show as disabled within Xposed Installer).
The device needs to be rebooted after the change.
Note that this requires root access, since the file is located in the internal data directory of another app. I strongly recommend just going the normal way and opening the Xposed Installer app, and let the user enable the module themselves:
public static boolean startXposedActivity(Context context) {
Intent intent = new Intent("de.robv.android.xposed.installer.OPEN_SECTION");
intent.putExtra("section", "modules");
try {
context.startActivity(intent);
return true;
} catch (ActivityNotFoundException e) {
return false;
}
}

Why is MdiActiveDocument null in the beginning in AutoCAD 2015+?

I am working in AutoCAD 2014 using Visual Studio 2013.
With my code I access the MdiActiveDocument's database from the DocumentManager .
Using the database I start a transaction and use the GetObject method of the transaction to retrieve Entity objects.
Database acCurDb = Application.DocumentManager.MdiActiveDocument.Database;
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
var obj = acTrans.GetObject(id, OpenMode.ForRead);
if (obj is Entity)
{
// do stuff
}
acTrans.Commit();
}
This works fine while I am in development and start AutoCAD from inside of Visual Studio. In development I set the "Start external program" switch in the Debug tab of the application properties so it starts AutoCAD for me and everything works great.
The issue I am having is that in production when the app is loaded by AutoCAD via registry settings (I use demand loading) the MdiActiveDocument is null so the code crashes. I have discovered there is a document in the Application.DocumentManager but when I assign the database from that document to acCurDb the TransactionManager throws an error with I try to use the StartTransaction method.
if (Application.DocumentManager.Count > 0)
{
foreach(Document doc in Application.DocumentManager)
{
acCurDb = doc.Database;
break;
}
}
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
}
Can someone help me understand why the MdiActiveDocument is null and/or direct me to the proper way to get a Transaction object in AutoCAD?
Beginning in 2015, AutoCAD may have a null active document on startup depending on user system variables. It's just another check you have to add before running your routine.
As mentioned by #david-wolfe, AutoCAD 2015 may start with no active document (just a dashboard). In this case the MdiActiveDocument can be null.
Now you're on AutoCAD 2014, so a different scenario may happen: if your app is loading with AutoCAD, you code may run before anything is really ready. How are you running the code? Is it a CommandMethod? If is a command, the user can only run it from a command, so it will be a active document. But if you run it from other method (like direct call from the Ribbon or from a palette), it may be null.

Send email attachment to a local folder

I am trying to send an email from a client PC (i.e. Windows) with an attachment and have the attachment saved to a local folder on the same client PC. I have looked at a couple of alternatives, such as MailDrop (email to dropbox) and Outlook 2003 Interop library - but want to make sure I am implementing this the best way.
Does anyone have any different ideas on a simple/elegant solution?
As long as you know Outlook will be installed on all the clients the Outlook solution works very well. You can create a file and save it, then in your outlook interop you just attach and send. You didn't specify what tools you are using but here's the basic email creation method I use for Outlook in C# (Where OutlookSetup.OutlookApp is just a static method that returns the currently open instance of the Outlook application or creates a new one if Outlook isn't open). Otherwise there are several examples here on SO of using SmtpClient to achieve similar ends.
public EmailMessage(EmailInfo emailInfo, string filenameToAttach=null)
{
Message = OutlookSetup.OutlookApp.CreateItem(OL.OlItemType.olMailItem);
Message.To = emailInfo.To;
Message.CC = emailInfo.Cc ?? "";
Message.Subject = emailInfo.Subject;
if (filenameToAttach != null)
{
Message.Attachments.Add(filenameToAttach);
}
}

Resources