IStorage and IEnumSTATSTG

D

Darren Mann

Hello,

I've written a wrapper for IStorage and I know the
majority of the code is working fine.

The only issue is with EnumElements. When its called the
function itself throws a COM Exception with the message
Invalid Pointer error.

My only guesses are that somehow my Interface declaration
of IEnumSTATSTG is incorrect or that the use of IntPtr is
incorrect for the void * used in EnumElements.

Is there another way to declare void * other than IntPtr.

If anybody can give me some help it would be greatly
appreciated.

CodeSnippet below

My IStorage is declared as

[ComImport]
InterfaceType(ComInterfaceType.InterfaceIsUnknown),
Guid("0000000b-0000-0000-C000-000000000046)]
public interface UCOMIStorage
{
...

int EnumElements(
int reserved1,
IntPtr reserved2,
int reserved3,
out UCOMIEnumSTATSTG
);

...
}

My IEnumSTATSTG is declared as

[ComImport,
InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
Guid("0000000d-0000-0000-C000-000000000046)]
public interface UCOMIEnumSTATSTG
{
...
}

The call to EnumElements called from a successfully opened
IStorage file is

UCOMIEnumSTATSTG IEnum;

int hRC = IStorageFile.EnumElements(0,IntPtr.Zero,0, out
IEnum);
 
M

Mattias Sjögren

Darren,
int EnumElements(
int reserved1,
IntPtr reserved2,
int reserved3,
out UCOMIEnumSTATSTG
);

You should either apply the PreserveSig attribute to the method (if
you want to check the HRESULT yourself) or change the return type to
void. You could also, if you find it more convenient, change the
signature to

UCOMIEnumSTATSTG EnumElements(
int reserved1,
IntPtr reserved2,
int reserved3
);



Mattias
 
G

Guest

Hello Mattia

Tried all three options and still no joy, I still get Invalid Pointer erro

[PreserveSig
int EnumElements(int reserved1, IntPtr reserved2, int reserved3, out UCOMIEnumSTATSTG)

void EnumElements(int reserved1, IntPtr reserved2, int reserved3, out UCOMIEnumSTATSTG)

UCOMIEnumSTATSTG EnumElements(int reserved1, IntPtr reserved2, int reserved3)

Any more ideas? Has it got to do with IntPtr


Cheer
Darre


----- Mattias Sjögren wrote: ----

Darren
int EnumElements
int reserved1
IntPtr reserved2
int reserved3
out UCOMIEnumSTATST
)

You should either apply the PreserveSig attribute to the method (i
you want to check the HRESULT yourself) or change the return type t
void. You could also, if you find it more convenient, change th
signature t

UCOMIEnumSTATSTG EnumElements
int reserved1
IntPtr reserved2
int reserved
)



Mattia
 
M

Mattias Sjögren

Darren,
Tried all three options and still no joy, I still get Invalid Pointer error

Can you post the entire interface declaration? The only other possible
cause I can think of is if you're missing some method or have placed
them in the wrong order.



Mattias
 
G

Guest

Mattias,

No need as you provided the solution already

"placed them in the wrong order"

Obviously missed this important bit when reading MSDN.

Thankyou for all your help.

Cheers
Darren Mann
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top