Friday, 19 February 2016

Removing unwanted .NET Framework from your Visual C++ Win32 project


If you are using Visual Studio (2010, for some reason) for Visual C++ Win32 project and if you want to remove the .NET Framework dependency (because VS won't let you opt-out from the start when you are creating a new project) all you have to do is to follow these steps.

1. Manually add these lines into your project file.


             <PropertyGroup> 
                 <AddAdditionalExplicitAssemblyReferences>false</AddAdditionalExplicitAssemblyReferences>
              </PropertyGroup>

    And make sure it is above the line - <ItemGroup Label="ProjectConfigurations">.

    As per this KB article from Microsoft - https://support.microsoft.com/en-us/kb/2735477

2. According to the KB article  "Also, in the setup project, open the Launch Condition editor and remove the “Microsoft .NET” launch condition. " but I can't find the Launch Condition editor, I'm guessing because of my VS 2010 Environment Settings, anyway if you can't see it either then just do this.

Open your project properties screen and go to the C/C++ General settings under the Configuration Properties section and make sure your Common Language RunTime Support field was set to "No Common Language RunTime Support".




















3. Under your "Installer" project properties open up the "Prerequisites" screen and untick any .NET Framework stuff.




4. Now rebuild your "Installer" project (the installer project you've created for your project) and you shouldn't be seeing any more of the .NET Framework stuff under the "Detected Dependencies".




      You shouldn't be seeing anymore of any ".NET" word on your "Installer" project build output logs. Otherwise you may have to remove and delete the installer project and create a new one again.



***NOTE: I am not sure if this is the case for the newer version of VS (hope it will be much more straight forward) I will try this at home with my later version of VS.

Wednesday, 10 February 2016

Enumerating entries from Global Address List for Microsoft Outlook Interop

I used to use this code below to access the Global Address List of all Microsoft Outlook list of email addresses.

          Outlook.AddressList gal = outlookApp.Session.GetGlobalAddressList();

where "outLookApp" is

          Microsoft.Office.Interop.Outlook.Application outlookApp = new Microsoft.Office.Interop.Outlook.Application();

however one day that code doesn't work anymore for some reason and I looked around and have used these codes instead:

          Outlook.AddressLists addrLists = outlookApp.Session.AddressLists;
          Outlook.AddressList gal = addrLists["Global Address List"];

which did the trick!

I'll have to do some checking what's the difference and what have changed. Next time....




Friday, 5 February 2016

Windows Service application unable to send print job

I've been trying to send print job into a remote printer via a Windows Service application in a few different ways: 

  • .Net PrintDocument class
  • a third party library (on-demand printing)
  • ghost script + ghostview
however I was not successful. I found out that Windows Service doesn't allow you or doesn't easily allow you to send or create a print job at all for security reasons or for any reasons. See posts:

https://msdn.microsoft.com/en-us/library/windows/desktop/ms683502.aspx

http://stackoverflow.com/questions/15834064/printing-from-windows-service-on-windows-8-fails

Well another day past and some lost hairs (due to hair pulling) I found a web post about a utility class that creates a "Raw" print job and I thought it may work because Windows won't treat it as calling or executing another windows app or windows process which the Windows Service doesn't like to do. So I give it a go and it works! See the section of the page where it says "2. Mit VB.Net RAW-Daten an den Drucker senden" which translate to "Send With VB.Net RAW data to the printer". (Note: The website is in german language. Thank you Germany!)

http://www.vbarchiv.net/tipps/tipp_2375-kassenbon-drucker-mit-vbnet-oder-c-per-esc-pos-befehle-ansprechen.html