Hacking Outlook Express - COM Interop
Written by Mike James   
Thursday, 23 July 2009
Article Index
Hacking Outlook Express - COM Interop
Creating a COM object
Exposing COM
OE Analysis
Mail analysis

 

Exposing COM

Now that everything is initialised we can add a method to the OE class that exposes the other COM functions, for example, GetDirectory. This returns the directory where all of the OE folders are stored and a class method to make use of it is simply defined:

public string getDirectory()
{
StringBuilder path =
new StringBuilder(256);
OEFolders.GetDirectory(path, 256);
return path.ToString();
}

If you now put a button on the project’s form and add the code:

OE oe = new OE();
MessageBox.Show(oe.getDirectory());

you will see the location of the OE root directory displayed in a message box.

Creating, moving and renaming

Finding out where the OE root directory is proof that the project is working but for something more useful we need to continue the definition of the Interface. Add the following function definitions to the Interface, again obtained by translating the details in the header file:

void OpenSpecialFolder(
[In, MarshalAs(UnmanagedType.U4)]
Int32 sfType,
[In, MarshalAs(UnmanagedType.U4)]
Int32 dwReserved,
[Out, MarshalAs(
UnmanagedType.Interface)]
out object ppFolder);
void OpenFolder(
[In, MarshalAs(UnmanagedType.U4)]
Int32 dwFolderId,
[In, MarshalAs(UnmanagedType.U4)]
Int32 dwReserved,
[Out, MarshalAs(
UnmanagedType.Interface)]
out object ppFolder);
void CreateFolder(
[In, MarshalAs(UnmanagedType.U4)]
Int32 dwParentId,
[In, MarshalAs(UnmanagedType.LPStr)]
String pszName,
[In, MarshalAs(UnmanagedType.U4)]
Int32 dwReserved,
[Out, MarshalAs(UnmanagedType.U4)]
out Int32 pdwFolderId);
void RenameFolder(
[In, MarshalAs(UnmanagedType.U4)]
Int32 dwFolderId,
[In, MarshalAs(UnmanagedType.U4)]
Int32 dwReserved,
[In, MarshalAs(UnmanagedType.LPStr)]
string pszNewName);
void MoveFolder(
[In, MarshalAs(UnmanagedType.U4)]
Int32 dwFolderId,
[In, MarshalAs(UnmanagedType.U4)]
Int32 dwParentId,
[In, MarshalAs(UnmanagedType.U4)]
Int32 dwReserved);
void DeleteFolder(
[In, MarshalAs(UnmanagedType.U4)]
Int32 dwFolderId,
[In, MarshalAs(UnmanagedType.U4)]
Int32 dwReserved);

The most useful of these at this stage are CreateFolder, RenameFolder, MoveFolder and DeleteFolder. These can be added as methods to the .NET class as:

public Int32 createFolder(
Int32 parentID,
string newfoldername)
{
Int32 folderID;
OEFolders.CreateFolder(
parentID,
newfoldername,
0,
out folderID);
return folderID;
}
public void renameFolder(
Int32 folderID,
string newfoldername)
{
OEFolders.RenameFolder(
folderID,
0,
newfoldername);
}
public void moveFolder(
Int32 folderID,
Int32 parentID)
{
OEFolders.MoveFolder(
folderID,
parentID,
0);
}
public void deleteFolder(
Int32 folderID)
{
OEFolders.DeleteFolder(folderID, 0);
}

To demonstrate how these work we can now create a new folder called “test” in the root (folder Id 0)

Int32 id=oe.createFolder(0, "test");

Move the folder to folder Id 4:

oe.moveFolder(id, 4);

Rename the folder to “newname”

oe.renameFolder(id, "newname");

Delete the folder:

oe.deleteFolder(id);

As deleting a folder simply moves it to the “Deleted Folder” we can delete it a second time to get rid of it permanently:

oe.deleteFolder(id);

<ASIN:0735624240>

<ASIN:0735618755>

<ASIN:0321440307>



Last Updated ( Wednesday, 16 September 2009 )
 
 

   
RSS feed of all content
I Programmer - full contents
Copyright © 2014 i-programmer.info. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.