GetAttachmentTable and DLLIMPORT

S

Shawrie

Hi

i wonder if someone can help me. Im trying to use the GetAttachmentTable
routine in MAPI.

[DllImport("MAPIlib.dll", EntryPoint = "IMessageGetAttachmentTable")]
private static extern HRESULT pIMessageGetAttachmentTable(IntPtr
msg, ref IntPtr AttachTable);

public IMAPITable GetAttachmentTable()
{
// Call the dll function
IntPtr tablePtr = IntPtr.Zero;
HRESULT hr = pIMessageGetAttachmentTable(this.ptr, ref
tablePtr);
if (hr != HRESULT.S_OK)
throw new Exception("GetAttachmentTable failed: " +
hr.ToString());
return new MAPITable(tablePtr);
}

When i try to run this i get
Can't find an Entry Point 'IMessageGetAttachmentTable' in a PInvoke DLL
'MAPIlib.dll'.

Can anyone help?


Thanks
Neil
 
C

Chris Tacke, MVP

Sure, I'd expect that from your code. You are trying to use a function
entry point called "IMessageGetAttachmentTable" and there certainly isn't
such a thing. The method is GetAttachmentTable and it's exposed by the
IMessage interface
(http://msdn2.microsoft.com/en-us/library/ms530463(EXCHG.10).aspx). You
can't just slap the interface/class name together with a function name and
expect to call it.

That's not the only issue, though. You can't just change the name and have
it work either. GetAttachmentTable isn't a direct entry point in a DLL,
which is what P/Invoke requires. It's a method *on an interface*. That
means you need an IMessage instance, and you need to call
GetAttachementTable on that. This *cannot* be done in managed code. You'd
need a native C wrapper that could call the method as your proxy.

Where did you get this definition anyway? It looks suspiciously like it was
desined for that kind of a scenario (calling an already created native shim)
as the first parameter according to the docs is a ULONG flags variable, not
a pointer to itself.

-Chris
 
S

Shawrie

Hi

i thought the call was a bit strange. It is within a c++ wrapper. I have
basically based it on some examples i found on the web. I have tried settting
the entry point to GetAttachmentTable but still no luck. Do you know what i
should set the entry point for this method?

thanks for your help

Chris Tacke said:
Sure, I'd expect that from your code. You are trying to use a function
entry point called "IMessageGetAttachmentTable" and there certainly isn't
such a thing. The method is GetAttachmentTable and it's exposed by the
IMessage interface
(http://msdn2.microsoft.com/en-us/library/ms530463(EXCHG.10).aspx). You
can't just slap the interface/class name together with a function name and
expect to call it.

That's not the only issue, though. You can't just change the name and have
it work either. GetAttachmentTable isn't a direct entry point in a DLL,
which is what P/Invoke requires. It's a method *on an interface*. That
means you need an IMessage instance, and you need to call
GetAttachementTable on that. This *cannot* be done in managed code. You'd
need a native C wrapper that could call the method as your proxy.

Where did you get this definition anyway? It looks suspiciously like it was
desined for that kind of a scenario (calling an already created native shim)
as the first parameter according to the docs is a ULONG flags variable, not
a pointer to itself.

-Chris


Shawrie said:
Hi

i wonder if someone can help me. Im trying to use the GetAttachmentTable
routine in MAPI.

[DllImport("MAPIlib.dll", EntryPoint = "IMessageGetAttachmentTable")]
private static extern HRESULT
pIMessageGetAttachmentTable(IntPtr
msg, ref IntPtr AttachTable);

public IMAPITable GetAttachmentTable()
{
// Call the dll function
IntPtr tablePtr = IntPtr.Zero;
HRESULT hr = pIMessageGetAttachmentTable(this.ptr, ref
tablePtr);
if (hr != HRESULT.S_OK)
throw new Exception("GetAttachmentTable failed: " +
hr.ToString());
return new MAPITable(tablePtr);
}

When i try to run this i get
Can't find an Entry Point 'IMessageGetAttachmentTable' in a PInvoke DLL
'MAPIlib.dll'.

Can anyone help?


Thanks
Neil
 
S

Shawrie

Hi

My apologies i got totally wrong end of the stick. I hadnt doen the wrapper
correctly

thanks

Chris Tacke said:
Sure, I'd expect that from your code. You are trying to use a function
entry point called "IMessageGetAttachmentTable" and there certainly isn't
such a thing. The method is GetAttachmentTable and it's exposed by the
IMessage interface
(http://msdn2.microsoft.com/en-us/library/ms530463(EXCHG.10).aspx). You
can't just slap the interface/class name together with a function name and
expect to call it.

That's not the only issue, though. You can't just change the name and have
it work either. GetAttachmentTable isn't a direct entry point in a DLL,
which is what P/Invoke requires. It's a method *on an interface*. That
means you need an IMessage instance, and you need to call
GetAttachementTable on that. This *cannot* be done in managed code. You'd
need a native C wrapper that could call the method as your proxy.

Where did you get this definition anyway? It looks suspiciously like it was
desined for that kind of a scenario (calling an already created native shim)
as the first parameter according to the docs is a ULONG flags variable, not
a pointer to itself.

-Chris


Shawrie said:
Hi

i wonder if someone can help me. Im trying to use the GetAttachmentTable
routine in MAPI.

[DllImport("MAPIlib.dll", EntryPoint = "IMessageGetAttachmentTable")]
private static extern HRESULT
pIMessageGetAttachmentTable(IntPtr
msg, ref IntPtr AttachTable);

public IMAPITable GetAttachmentTable()
{
// Call the dll function
IntPtr tablePtr = IntPtr.Zero;
HRESULT hr = pIMessageGetAttachmentTable(this.ptr, ref
tablePtr);
if (hr != HRESULT.S_OK)
throw new Exception("GetAttachmentTable failed: " +
hr.ToString());
return new MAPITable(tablePtr);
}

When i try to run this i get
Can't find an Entry Point 'IMessageGetAttachmentTable' in a PInvoke DLL
'MAPIlib.dll'.

Can anyone help?


Thanks
Neil
 
Z

Zahid Ali

Can you please write the wrapper code here

thanks



Shawri wrote:

HiMy apologies i got totally wrong end of the stick.
21-Apr-08

H

My apologies i got totally wrong end of the stick. I hadnt doen the wrappe
correctl

thank

:

Previous Posts In This Thread:

GetAttachmentTable and DLLIMPORT
H

i wonder if someone can help me. Im trying to use the GetAttachmentTable
routine in MAPI

[DllImport("MAPIlib.dll", EntryPoint = "IMessageGetAttachmentTable")
private static extern HRESULT pIMessageGetAttachmentTable(IntPtr
msg, ref IntPtr AttachTable)

public IMAPITable GetAttachmentTable(

// Call the dll functio
IntPtr tablePtr = IntPtr.Zero
HRESULT hr = pIMessageGetAttachmentTable(this.ptr, ref
tablePtr)
if (hr != HRESULT.S_OK
throw new Exception("GetAttachmentTable failed: " +
hr.ToString())
return new MAPITable(tablePtr)


When i try to run this i get
Can't find an Entry Point 'IMessageGetAttachmentTable' in a PInvoke DLL
'MAPIlib.dll'

Can anyone help

Thank
Neil

Sure, I'd expect that from your code.
Sure, I'd expect that from your code. You are trying to use a function
entry point called "IMessageGetAttachmentTable" and there certainly isn't
such a thing. The method is GetAttachmentTable and it's exposed by the
IMessage interface
(http://msdn2.microsoft.com/en-us/library/ms530463(EXCHG.10).aspx). You
can't just slap the interface/class name together with a function name and
expect to call it

That's not the only issue, though. You can't just change the name and have
it work either. GetAttachmentTable isn't a direct entry point in a DLL,
which is what P/Invoke requires. It's a method *on an interface*. That
means you need an IMessage instance, and you need to call
GetAttachementTable on that. This *cannot* be done in managed code. You'd
need a native C wrapper that could call the method as your proxy

Where did you get this definition anyway? It looks suspiciously like it was
desined for that kind of a scenario (calling an already created native shim)
as the first parameter according to the docs is a ULONG flags variable, not
a pointer to itself

-Chri


Hii thought the call was a bit strange. It is within a c++ wrapper.
H

i thought the call was a bit strange. It is within a c++ wrapper. I have
basically based it on some examples i found on the web. I have tried settting
the entry point to GetAttachmentTable but still no luck. Do you know what i
should set the entry point for this method

thanks for your hel

:

HiMy apologies i got totally wrong end of the stick.
H

My apologies i got totally wrong end of the stick. I hadnt doen the wrappe
correctl

thank

:


Submitted via EggHeadCafe - Software Developer Portal of Choice
..NET Constructor Applied
http://www.eggheadcafe.com/tutorial...2bd-2efad5224a3f/net-constructor-applied.aspx
 

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