PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Compact Framework GetAttachmentTable and DLLIMPORT

Reply

GetAttachmentTable and DLLIMPORT

 
Thread Tools Rate Thread
Old 21-04-2008, 12:29 PM   #1
Shawrie
Guest
 
Posts: n/a
Default GetAttachmentTable and DLLIMPORT


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



  Reply With Quote
Old 21-04-2008, 01:11 PM   #2
Chris Tacke, MVP
Guest
 
Posts: n/a
Default Re: GetAttachmentTable and DLLIMPORT

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" <Shawrie@discussions.microsoft.com> wrote in message
news:2F8038E9-0B1A-44D1-BB7A-C2980C8BC61E@microsoft.com...
> 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
>
>
>


  Reply With Quote
Old 21-04-2008, 01:28 PM   #3
Shawrie
Guest
 
Posts: n/a
Default Re: GetAttachmentTable and DLLIMPORT

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, MVP" wrote:

> 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" <Shawrie@discussions.microsoft.com> wrote in message
> news:2F8038E9-0B1A-44D1-BB7A-C2980C8BC61E@microsoft.com...
> > 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
> >
> >
> >

>
>

  Reply With Quote
Old 21-04-2008, 02:46 PM   #4
Shawrie
Guest
 
Posts: n/a
Default Re: GetAttachmentTable and DLLIMPORT

Hi

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

thanks

"Chris Tacke, MVP" wrote:

> 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" <Shawrie@discussions.microsoft.com> wrote in message
> news:2F8038E9-0B1A-44D1-BB7A-C2980C8BC61E@microsoft.com...
> > 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
> >
> >
> >

>
>

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off