Hi all,

I'm pretty new to pocket pc development and COM in general. I have a
dll file which is used by C++, C# on Win32, and C++ on PocketPC.
However, C# on PocketPC fails. Is there something that needs to be set
in the dll project to make it PocketPC/CLR friendly? Anyway, here is
the DLL Import that works in C# on Win32:

[DllImport("acccore.dll", EntryPoint="#111", PreserveSig=false)]
private static extern void AccCreateSession(
[MarshalAs(UnmanagedType.LPStruct)] Guid riid,
[MarshalAs(UnmanagedType.IDispatch)] out object session);

I know that in C# on Win32, I can pass in the IID , whereas I have the
hardcoded GUID on my Pocket sample. On the pocket version, i get a
NotSupportedException and it fails. Any general idea as to why? DO my
data types need to be marshalled differently?

Here is the C++ function signature:
STDAPI AccCreateSession(REFIID iid, void** ppv) {...}

Re: PocketPC C# COM interop - NotSupportedException ? by Peter

Peter
Wed Feb 28 02:09:35 CST 2007

Perhaps the MarshalAs(UnmanagedType.LPStruct) isn't being interpreted
correctly, also I don't think the PreserveSig field on DllImport is being
used correctly try this:-

[DllImport("acccore.dll", EntryPoint="#111")]
private static extern void AccCreateSession(
ref Guid riid,
[MarshalAs(UnmanagedType.IDispatch)] out object session);

Peter

--
Peter Foot
Device Application Development MVP
www.peterfoot.net | www.inthehand.com

<rsattar@gmail.com> wrote in message
news:1172629258.689655.149960@k78g2000cwa.googlegroups.com...
> Hi all,
>
> I'm pretty new to pocket pc development and COM in general. I have a
> dll file which is used by C++, C# on Win32, and C++ on PocketPC.
> However, C# on PocketPC fails. Is there something that needs to be set
> in the dll project to make it PocketPC/CLR friendly? Anyway, here is
> the DLL Import that works in C# on Win32:
>
> [DllImport("acccore.dll", EntryPoint="#111", PreserveSig=false)]
> private static extern void AccCreateSession(
> [MarshalAs(UnmanagedType.LPStruct)] Guid riid,
> [MarshalAs(UnmanagedType.IDispatch)] out object session);
>
> I know that in C# on Win32, I can pass in the IID , whereas I have the
> hardcoded GUID on my Pocket sample. On the pocket version, i get a
> NotSupportedException and it fails. Any general idea as to why? DO my
> data types need to be marshalled differently?
>
> Here is the C++ function signature:
> STDAPI AccCreateSession(REFIID iid, void** ppv) {...}
>


Re: PocketPC C# COM interop - NotSupportedException ? by rsattar

rsattar
Thu Mar 01 19:08:29 CST 2007

Hi Peter,

Thank you for your reply. Your suggested changes completely fixed my
problem! Interestingly, the old DllImport works fine on the
normal .Net Framework, but it just fails on the compact framework. Any
idea why? Perhaps the compact framework doesn't marshall the LPStruct
correctly?

There was an additional thing I had to do on my Pocket PC development,
and that is that my dll file, acccore.dll, depends on 2 other DLLs. I
had to also copy (understandably) the 2 dlls to the same path as my
executable. When those DLLs are not present and I try your fix, it
gives me a MissingMethodException with a message saying "can't fine P/
INvoke DLL 'acccore.dll' ", which I thought was strange (isn't there a
exception that more accurately describes the problem?).

Anyway, thank you for your help.

On Feb 28, 12:09 am, "Peter Foot [MVP]" <feedb...@nospam-
inthehand.com> wrote:
> Perhaps the MarshalAs(UnmanagedType.LPStruct) isn't being interpreted
> correctly, also I don't think the PreserveSig field on DllImport is being
> used correctly try this:-
>
> [DllImport("acccore.dll", EntryPoint="#111")]
> private static extern void AccCreateSession(
> ref Guid riid,
> [MarshalAs(UnmanagedType.IDispatch)] out object session);
>
> Peter
>
> --
> Peter Foot
> Device Application Development MVPwww.peterfoot.net|www.inthehand.com
>
> <rsat...@gmail.com> wrote in message
>
> news:1172629258.689655.149960@k78g2000cwa.googlegroups.com...
>
> > Hi all,
>
> > I'm pretty new to pocket pc development and COM in general. I have a
> > dll file which is used by C++, C# on Win32, and C++ on PocketPC.
> > However, C# on PocketPC fails. Is there something that needs to be set
> > in the dll project to make it PocketPC/CLR friendly? Anyway, here is
> > the DLL Import that works in C# on Win32:
>
> > [DllImport("acccore.dll", EntryPoint="#111", PreserveSig=false)]
> > private static extern void AccCreateSession(
> > [MarshalAs(UnmanagedType.LPStruct)] Guid riid,
> > [MarshalAs(UnmanagedType.IDispatch)] out object session);
>
> > I know that in C# on Win32, I can pass in the IID , whereas I have the
> > hardcoded GUID on my Pocket sample. On the pocket version, i get a
> > NotSupportedException and it fails. Any general idea as to why? DO my
> > data types need to be marshalled differently?
>
> > Here is the C++ function signature:
> > STDAPI AccCreateSession(REFIID iid, void** ppv) {...}