using
System;
using
System.Drawing;
using
System.Runtime.InteropServices;
using
ExtractImageInterop;
namespace
WellFormed
{
///
<summary>
/// Summary description
for ThumbExt.
///
</summary>
[ClassInterface(ClassInterfaceType.None),
Guid("E134E0A2-5682-41d4-AF22-6F516844C094")]
public class
ThumbExt : IExtractImage, IPersistFile
{
public
ThumbExt()
{
//
//
TODO: Add constructor logic here
//
}
#region
IExtractImage Members
public
void Extract(System.IntPtr phBmpThumbnail)
{
}
public
void GetLocation(string
pszPathBuffer, uint cch,
ref uint
pdwPriority, ref tagSIZE prgSize,
uint dwRecClrDepth, ref
uint pdwFlags)
{
}
#endregion
#region
IPersistFile Members
public
void SaveCompleted(string
pszFileName)
{
}
public
void GetCurFile(out
string ppszFileName)
{
}
public
void GetClassID(out
Guid pClassID)
{
}
public
void Load(string
pszFileName, uint dwMode)
{
}
public
void IsDirty()
{
}
public
void Save(string
pszFileName, int fRemember)
{
}
#endregion
}
}
In stage 1 we have a project that imports the interop DLL, has a GUID, has
the stubs of the interface implementations and has been configured by right
clicking on the project, selecting Properties and enabling the option to
"Register for COM interop" as seen in the following image.

Stage 2. The full implementation
using
System;
using
System.Drawing;
using
System.Runtime.InteropServices;
using
ExtractImageInterop;
namespace
WellFormed
{
///
<summary>
/// Summary description
for ThumbExt.
///
</summary>
[ClassInterface(ClassInterfaceType.None),
Guid("E134E0A2-5682-41d4-AF22-6F516844C094")]
public class
ThumbExt : IExtractImage, IPersistFile
{
string
filename;
Size
_size;
public
ThumbExt()
{
//
//
TODO: Add constructor logic here
//
}
#region
IExtractImage Members
public
void Extract(System.IntPtr phBmpThumbnail)
{
ColorShape
cs=ColorShape.Load(filename);
Bitmap
bm=new Bitmap(_size.Width,_size.Height);
Graphics g=Graphics.FromImage(bm);
cs.Draw(g,new
Rectangle(0,0,bm.Width,bm.Height));
Marshal.WriteIntPtr(phBmpThumbnail,bm.GetHbitmap(Color.White));
bm.Dispose();
}
public
void GetLocation(string
pszPathBuffer, uint cch,
ref uint
pdwPriority, ref tagSIZE prgSize,
uint dwRecClrDepth, ref
uint pdwFlags)
{
_size=new
Size(prgSize.cx,prgSize.cy);
pdwPriority=0x10000000u;
//normal priority
}
#endregion
#region
IPersistFile Members
public
void SaveCompleted(string
pszFileName)
{
throw
new NotImplementedException();
}
public
void GetCurFile(out
string ppszFileName)
{
throw
new NotImplementedException();
}
public
void GetClassID(out
Guid pClassID)
{
throw
new NotImplementedException();
}
public
void Load(string
pszFileName, uint dwMode)
{
this.filename=pszFileName;
}
public
void IsDirty()
{
throw
new NotImplementedException();
}
public
void Save(string
pszFileName, int fRemember)
{
throw
new NotImplementedException();
}
#endregion
}
}
Imports
System
Imports
System.Drawing
Imports
System.Runtime.InteropServices
Imports
ExtractImageInterop
Imports
GraphicsDLLVB
Namespace
WellFormed
'' <summary>
'' Summary description for ThumbExt.
'' </summary>
<ClassInterface(ClassInterfaceType.None),
_
Guid("E134E0A2-5682-41d4-AF22-6F516844C095")>
_
Public Class
ThumbExt
Implements
IExtractImage, IPersistFile
Private
filename As String
Private
_size As Size
Public
Sub New()
End
Sub
#Region
"IExtractImage Members"
Public
Sub Extract(ByVal
phBmpThumbnail As System.IntPtr)
Implements IExtractImage.Extract
End
Sub
Public
Sub GetLocation(ByVal
pszPathBuffer As String,
ByVal cch As
System.UInt32, ByRef pdwPriority
As System.UInt32, ByRef
prgSize As tagSIZE,
ByVal dwRecClrDepth As System.UInt32,
ByRef pdwFlags As
System.UInt32) Implements
IExtractImage.GetLocation
End
Sub
#End
Region
#Region
"IPersistFile Members"
Public
Sub SaveCompleted(ByVal
pszFileName As String)
Implements
ExtractImageInterop.IPersistFile.SaveCompleted
End
Sub
Public
Sub GetCurFile(ByRef
ppszFileName As String)
Implements
ExtractImageInterop.IPersistFile.GetCurFile
End
Sub
Public
Sub GetClassID(ByRef
pClassID As System.Guid)
Implements
ExtractImageInterop.IPersistFile.GetClassID
End
Sub
Public
Sub Load(ByVal
pszFileName As String,
ByVal dwMode As
UInt32) Implements
ExtractImageInterop.IPersistFile.Load
End
Sub
Public
Sub IsDirty()
Implements IPersistFile.IsDirty
End
Sub
Public
Sub Save(ByVal
pszFileName As String,
ByVal fRemember As
Integer) Implements
ExtractImageInterop.IPersistFile.Save
End
Sub
#End
Region
#Region
"IPersist implementation"
Public
Sub GetClassID1(ByRef
pClassID As System.Guid)
Implements
ExtractImageInterop.IPersist.GetClassID
End
Sub
#End
Region
End Class
end
namespace
In stage 1 we have a project that imports the interop DLL, has a GUID, has
the stubs of the interface implementations and has been configured by right
clicking on the project, selecting Properties and enabling the option to
"Register for COM interop" as seen in the following image.

Stage 2. The full implementation
Imports
System
Imports
System.Drawing
Imports
System.Runtime.InteropServices
Imports
ExtractImageInterop
Imports
GraphicsDLLVB
Namespace
WellFormed
'' <summary>
'' Summary description for ThumbExt.
'' </summary>
<ClassInterface(ClassInterfaceType.None),
_
Guid("E134E0A2-5682-41d4-AF22-6F516844C095")>
_
Public Class
ThumbExt
Implements
IExtractImage, IPersistFile
Private
filename As String
Private
_size As Size
Public
Sub New()
End
Sub
#Region
"IExtractImage Members"
Public
Sub Extract(ByVal
phBmpThumbnail As System.IntPtr)
Implements IExtractImage.Extract
Dim
cs As ColorShape = ColorShape.Load(filename)
Dim
bm As New
Bitmap(_size.Width, _size.Height)
Dim
g As Graphics = Graphics.FromImage(bm)
cs.Draw(g,
New Rectangle(0, 0, bm.Width, bm.Height))
Marshal.WriteIntPtr(phBmpThumbnail,
bm.GetHbitmap(Color.White))
bm.Dispose()
End
Sub
Public
Sub GetLocation(ByVal
pszPathBuffer As String,
ByVal cch As
System.UInt32, ByRef pdwPriority
As System.UInt32, ByRef
prgSize As tagSIZE,
ByVal dwRecClrDepth As System.UInt32,
ByRef pdwFlags As
System.UInt32) Implements
IExtractImage.GetLocation
_size =
New Size(prgSize.cx, prgSize.cy)
pdwPriority
= Convert.ToUInt32(&H10000000) 'normal priority
End
Sub
#End
Region
#Region
"IPersistFile Members"
Public
Sub SaveCompleted(ByVal
pszFileName As String)
Implements
ExtractImageInterop.IPersistFile.SaveCompleted
Throw
New NotImplementedException
End
Sub
Public
Sub GetCurFile(ByRef
ppszFileName As String)
Implements
ExtractImageInterop.IPersistFile.GetCurFile
Throw
New NotImplementedException
End
Sub
Public
Sub GetClassID(ByRef
pClassID As System.Guid)
Implements
ExtractImageInterop.IPersistFile.GetClassID
Throw
New NotImplementedException
End
Sub
Public
Sub Load(ByVal
pszFileName As String,
ByVal dwMode As
UInt32) Implements
ExtractImageInterop.IPersistFile.Load
Me.filename
= pszFileName
End
Sub
Public
Sub IsDirty()
Implements IPersistFile.IsDirty
Throw
New NotImplementedException
End
Sub
Public
Sub Save(ByVal
pszFileName As String,
ByVal fRemember As
Integer) Implements
ExtractImageInterop.IPersistFile.Save
Throw
New NotImplementedException
End
Sub
#End
Region
#Region
"IPersist implementation"
Public
Sub GetClassID1(ByRef
pClassID As System.Guid)
Implements
ExtractImageInterop.IPersist.GetClassID
Throw
New NotImplementedException
End
Sub
#End
Region
End Class
end
namespace