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

   

%d bloggers like this: