Discussion:
ThumbnailProvider won't call Initialize when implementing IInitializeWithFile
(too old to reply)
chrisk
2007-07-08 11:03:19 UTC
Permalink
Hi

I'm trying to write a simple thumbnail provider for my file type on
Vista. Following instructionst on various web pages and an example
from SDK I wrote a class implementing IThumbnailProvider and
IInitializeWithStream. It works fine and my test thumbnail appears,
but then I realized that I need a filepath to get the right thumbnail,
so instead of implementing IInitializeWithStream I need to go with
IInitializeWithFile.

And here is my problem - it doesn't work. I've put a trace message in
every method and using debugger i fugured than in both cases the
constructor is called, but the Initialize, and GetThumbnail methods
are not, when i use IInitializeWithFile. Since the constructor is
called the registration part must be ok. I took GUID's from SDK's .idl
files so they should be fine too. I'm new to this subject so I don't
really know where to look for error.

Any suggestions would be really helpful.

Chris
Jim Barry
2007-07-09 13:33:00 UTC
Permalink
Post by chrisk
And here is my problem - it doesn't work. I've put a trace message in
every method and using debugger i fugured than in both cases the
constructor is called, but the Initialize, and GetThumbnail methods
are not, when i use IInitializeWithFile.
It's working for me. Maybe you can post some code so that we can see exactly what you're doing.
--
Jim Barry, MVP (Windows SDK)
chrisk
2007-07-09 20:19:31 UTC
Permalink
Since I try to do it the shortiest (and possibly the ugliest) way just
to make it work I'm writing it in c#. Now, I know it's not recommended
to do those things in managed way, but as I said the stream method
seems to work just fine and It's just easier for me to do it this way.
So here's the code:

[ComVisible(true)]
[Guid("b7d14566-0509-4cce-a71f-0a554233bd9b")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IInitializeWithFile
{
void Initialize(string pszFilePath, UInt32 grfMode);
}

[ComVisible(true)]
[Guid("e357fccd-a995-4576-b01f-234630154e96")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IThumbnailProvider
{
void GetThumbnail(uint cx, out IntPtr phbmp, out UInt32 pdwAlpha);
}

[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("CrossbladesThumbnailProvider")]
[Guid("306B61EA-46D0-48c6-B79F-602D020F2BE2")]
public class ThumbnailProvider : IThumbnailProvider,
IInitializeWithFile
{
public ThumbnailProvider()
{
//gets here
}
public void Initialize(string pszFilePath, uint grfMode)
{
//never gets here
}
public void GetThumbnail(uint cx, out IntPtr phbmp, out UInt32
pdwAlpha)
{
//never gets here either
}
}

As I said it works just fine if I use IInitializeWithStream like this:

[ComVisible(true)]
[Guid("b824b49d-22ac-4161-ac8a-9916e8fa3f7f")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IInitializeWithStream
{
void Initialize(IStream stream, UInt32 grfMode);
}

(...)
public class ThumbnailProvider : IThumbnailProvider,
IInitializeWithStream
{
(...)
public void Initialize(IStream stream, uint grfMode)
{
//ok
}
(...)
}
Jim Barry
2007-07-11 14:18:53 UTC
Permalink
Post by chrisk
[ComVisible(true)]
[Guid("b7d14566-0509-4cce-a71f-0a554233bd9b")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IInitializeWithFile
{
void Initialize(string pszFilePath, UInt32 grfMode);
}
I am not a C# expert, but shouldn't it be something like:

void Initialize([MarshalAs(UnmanagedType.LPWStr)]string pszFilePath, UInt32 grfMode);
--
Jim Barry, MVP (Windows SDK)
RT
2012-04-02 09:57:15 UTC
Permalink
HiChris,

I am facing similar problem. did you come over this. If So how did you do that

Regards
RT
Post by chrisk
Hi
I'm trying to write a simple thumbnail provider for my file type on
Vista. Following instructionst on various web pages and an example
from SDK I wrote a class implementing IThumbnailProvider and
IInitializeWithStream. It works fine and my test thumbnail appears,
but then I realized that I need a filepath to get the right thumbnail,
so instead of implementing IInitializeWithStream I need to go with
IInitializeWithFile.
And here is my problem - it doesn't work. I've put a trace message in
every method and using debugger i fugured than in both cases the
constructor is called, but the Initialize, and GetThumbnail methods
are not, when i use IInitializeWithFile. Since the constructor is
called the registration part must be ok. I took GUID's from SDK's .idl
files so they should be fine too. I'm new to this subject so I don't
really know where to look for error.
Any suggestions would be really helpful.
Chris
it is working for me. Maybe you can post some code so that we can see =
exactly what you are doing.
--=20
Jim Barry, MVP (Windows SDK)
Post by chrisk
Since I try to do it the shortiest (and possibly the ugliest) way just
to make it work I'm writing it in c#. Now, I know it's not recommended
to do those things in managed way, but as I said the stream method
seems to work just fine and It's just easier for me to do it this way.
[ComVisible(true)]
[Guid("b7d14566-0509-4cce-a71f-0a554233bd9b")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IInitializeWithFile
{
void Initialize(string pszFilePath, UInt32 grfMode);
}
[ComVisible(true)]
[Guid("e357fccd-a995-4576-b01f-234630154e96")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IThumbnailProvider
{
void GetThumbnail(uint cx, out IntPtr phbmp, out UInt32 pdwAlpha);
}
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("CrossbladesThumbnailProvider")]
[Guid("306B61EA-46D0-48c6-B79F-602D020F2BE2")]
public class ThumbnailProvider : IThumbnailProvider,
IInitializeWithFile
{
public ThumbnailProvider()
{
//gets here
}
public void Initialize(string pszFilePath, uint grfMode)
{
//never gets here
}
public void GetThumbnail(uint cx, out IntPtr phbmp, out UInt32
pdwAlpha)
{
//never gets here either
}
}
[ComVisible(true)]
[Guid("b824b49d-22ac-4161-ac8a-9916e8fa3f7f")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IInitializeWithStream
{
void Initialize(IStream stream, UInt32 grfMode);
}
(...)
public class ThumbnailProvider : IThumbnailProvider,
IInitializeWithStream
{
(...)
public void Initialize(IStream stream, uint grfMode)
{
//ok
}
(...)
}
void Initialize([MarshalAs(UnmanagedType.LPWStr)]string pszFilePath, =
UInt32 grfMode);
--=20
Jim Barry, MVP (Windows SDK)
Loading...