Cyberiafreak

"Fortunate are those who take the first steps.” ― Paulo Coelho

Debugview.exe as rescue tool

DebugView is a developer friendly tool helps you to monitor debug output messages from local or nw system – from managed/unmanaged code. Recently I was debugging managed COM dll created in C# consumed in office application. I wanted a tool to debug end to end, Let say, your Office files VBA macro calls .NET COM dll for processing some complex logic and then returns the value to your macro.

In dev environment, we usually attach VS to the application and debug them, in VBA using debug.print statements. Assume that, you don’t have VS at your production server or customer machine where you wanted to debug them badly. Here is where debugview comes for rescue.

To write, debug statements from managed code, use Diagnostic having Debug.writeline. For VBA, use OutputDebugString. For other languages – use as here.

C#:- System.Diagnostics.Debug.WriteLine("This is from .NET before word instance.");

VBA:- Private Declare Sub OutputDebugString Lib "kernel32" Alias "OutputDebugStringA" (ByVal lpOutputString As String)
Private Sub DebugPrint(dbgOutput As String)
OutputDebugString dbgOutput
End Sub
Sub test()
DebugPrint ("Test message for the debugger")
End Sub

Note: Make sue you run as “Admin”.

debug1

debug

Advertisements

March 22, 2015 Posted by | .NET General, Office | , , , | Leave a comment

How to create your first Office Com Addin

1) Create a C# class library project

2) Add Extensibility reference to the project
 namespace ClassLibrary1
 {
 public class Class1 : Extensibility.IDTExtensibility2

3) Implement the interface method and place a messagebox OnStartupComplete to test
4) From Project properties > Build > "Register for COM interop"
5) From Project properties > Application > Assembly information > "Make assembly COM Visible
6) Compile - VS should automatically build and register the COM to the registry
7) This would create something like this,
 Windows Registry Editor Version 5.00
   [HKEY_CLASSES_ROOT\ClassLibrary1.Class1\CLSID]
 @="{0D39F056-DF63-3860-9E79-B57F6358FD4D}"
8) Now, create the below registry file "a.reg" save and run to create this entry under HCU
For Excel, create under Excel and accordingly for other product
 Windows Registry Editor Version 5.00
 [HKEY_CURRENT_USER\Software\Microsoft\Office\Excel\Addins\ClassLibrary1.Class1]
 "LoadBehavior"=dword:00000003
Copy "{0D39F056-DF63-3860-9E79-B57F6358FD4D}" and search under HKEY_CLASS_ROOT\CLSID
Windows Registry Editor Version 5.00
 [HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{0D39F056-DF63-3860-9E79-B57F6358FD4D}]
 @="ClassLibrary1.Class1"
 [HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{0D39F056-DF63-3860-9E79-B57F6358FD4D}\Implemented Categories]
 [HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{0D39F056-DF63-3860-9E79-B57F6358FD4D}\Implemented Categories\{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29}]
[HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{0D39F056-DF63-3860-9E79-B57F6358FD4D}\InprocServer32] @="mscoree.dll"
 "ThreadingModel"="Both"
 "Class"="ClassLibrary1.Class1"
 "Assembly"="ClassLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
 "RuntimeVersion"="v4.0.30319"
 "CodeBase"="file:///c:/users/maheshk/documents/visual studio 2013/Projects/ClassLibrary1/ClassLibrary1/bin/Debug/ClassLibrary1.dll"
[HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{0D39F056-DF63-3860-9E79-B57F6358FD4D}\InprocServer32\1.0.0.0]
 "Class"="ClassLibrary1.Class1"
 "Assembly"="ClassLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
 "RuntimeVersion"="v4.0.30319"
 "CodeBase"="file:///c:/users/maheshk/documents/visual studio 2013/Projects/ClassLibrary1/ClassLibrary1/bin/Debug/ClassLibrary1.dll"
[HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{0D39F056-DF63-3860-9E79-B57F6358FD4D}\ProgId]
@="ClassLibrary1.Class1"
9) Now launch, Excel should see the message box on load - means this add-in loaded because of load behavior set as "3" - load at start. ( at the step #8 )

10)You can check this, by Excel > File > Options > Addins > Active Application Addin: ClassLibrary1.Class, location: mscoree.dll, COM Add-in

11) Register: 
"%WINDIR%\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe" /codebase ComAddin\bin\Debug\ComAddin.dll
"%WINDIR%\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe" /unregister ComAddin\bin\Debug\ComAddin.dll

Note: You may get access denied if you did not run as VS in Admin mode. 

Refer - http://support.microsoft.com/kb/302901
Download my sample - http://1drv.ms/1GzJP1N 
Download C++ sample - http://1drv.ms/1GzK4tH

November 8, 2014 Posted by | .NET General, Office, Outlook | , | Leave a comment

About DDEInitialize and sometime lockup scenario explained.

I had a chance to work with Excel DDE call lockup Issue,

> The first step in establishing a DDE conversation is that the DDE client will send a WM_DDE_INITIATE message to one or more windows running on the same desktop as the DDE client process. The WM_DDE_INITIATE message is a query to each window receiving the message to determine whether the process that owns the window supports the specified application name and topic. Typically, a DDE client will broadcast the WM_DDE_INITIATE message to all top level windows (both visible and hidden) running on the same desktop, looking for any running process that supports the specified application name and topic.

The implementation of the Excel DDEInitiate function broadcasts the WM_DDE_INITIATE message by calling the SendMessage function, specifying HWND_BROADCAST. The SendMessage call will not return until each top level window has processed the WM_DDE_INITIATE message. The hang that occurs when calling DDEInitiate is the result of one or more threads that own a top level not having an active message pump.

The ListBlockedWindow tool helps to identify each process that contains  threads that do not have an active message pump and own one or more top level windows. The applications identified by the ListBlockedWindow tool should be updated such that each thread that owns a window has an active message pump, even when a given thread owns windows that are not visible. The term “message pump” (or message loop) refers to the calls a thread makes to the GetMessage or PeekMessage functions to retrieve/process any pending window messages for windows owned by the thread. A thread that owns a window receiving a WM_DDE_INITIATE message and does not actively call GetMessage or PeekMessage will cause the thread that is sending the WM_DDE_INITIATE message with SendMessage to block until the message is processed.

Please refer to the following links for additional information about DDE and message processing in Windows.

About Dynamic Data Exchange – http://msdn.microsoft.com/en-us/library/windows/desktop/ms648774(v=vs.85).aspx

Using Messages and Message Queues – http://msdn.microsoft.com/en-us/library/windows/desktop/ms644928(v=vs.85).aspx

SendMessage function – http://msdn.microsoft.com/en-us/library/windows/desktop/ms644950(v=vs.85).aspx

Note: this content is not mine, borrowed from my colleague-DaveAnd

October 25, 2014 Posted by | .NET General, Office | Leave a comment

How to call C#.NET Class Library from Office VBA

1 2 3 4 5 6 7

August 23, 2014 Posted by | .NET General, Office, VBA | Leave a comment

Exchange 2010 does not support WebDAV ( discontinued)

Exchange 2007 was the last version of Exchange to support using WebDAV.

Developer roadmap for Exchange ( search for WebDAV)

http://msdn.microsoft.com/en-us/library/dd877025.aspx

Discontinued Features
http://technet.microsoft.com/en-us/library/aa998911(v=exchg.141).aspx

What may work for you is to use Exchange Web Serveries (EWS), which overall has superior calendaring abilities.  There is a .NET API called the EWS Managed API which wraps EWS calls and should make using EWS a lot easier.

Differences between the EWS Managed API and EWS

http://msdn.microsoft.com/en-us/library/office/dd633678(v=exchg.80).aspx

EWS Managed API reference

http://msdn.microsoft.com/en-us/library/office/jj220535(v=exchg.80).aspx

Microsoft Exchange Web Services Managed API 2.2

http://www.microsoft.com/en-us/download/details.aspx?id=42951

Explore the EWS Managed API 2.0

http://msdn.microsoft.com/en-us/library/office/dd633710(v=exchg.80).aspx

 

June 12, 2014 Posted by | Office, Outlook | Leave a comment

Microsoft Office Configuration Analyzer Tool 1.2

The Office Configuration Analyzer Tool 1.2 (OffCAT ) provides a quick and easy method to analyze most Microsoft Office programs for common configurations that may cause problems. *Download only OffCAT.msi if you want to install OffCAT. Review the ReadMe file to see if the other files are needed.

http://www.microsoft.com/en-us/download/details.aspx?id=36852

Supported Operating System

Windows 7, Windows 8, Windows Vista Service Pack 2, Windows XP Service Pack 3
This download works with the following Microsoft Office products:

• Microsoft Office 2013 (32-bit or 64-bit, Click-to-run or Msi installs)
• Microsoft Office 2010 (32-bit or 64-bit)
• Microsoft Office 2007
OffCAT version 1.2 provides scanning for the following Office programs:

•Microsoft Access
•Microsoft Excel
•Microsoft InfoPath
•Microsoft OneNote
•Microsoft Outlook
•Microsoft PowerPoint
•Microsoft Publisher
•Microsoft Visio
•Microsoft Word
The following minimum version of the Microsoft .NET Framework is required:
• Microsoft .NET Framework Version 2.0
The following Microsoft Office feature is also required:
• .NET Programmability Support

June 11, 2014 Posted by | Office | | Leave a comment

   

%d bloggers like this: