locked
Importing COM into device application RRS feed

  • Question

  • hello everyone, now im facing a problem when importing COM.

    theres a sample in @"Windows Mobile 6 SDK\Samples\PocketPC\CPP\win32\CameraCapture", and it works well with my emulator.

    therefore id like to translate it to csharp code, and the problem appears here.

    in the sample, one of the interfaces is declared as:

    #if defined(__cplusplus) && !defined(CINTERFACE)
     
     MIDL_INTERFACE("52d6f586-9f0f-4824-8fc8-e32ca04930c2")
     IDMOWrapperFilter : public IUnknown
     {
     public:
      virtual HRESULT STDMETHODCALLTYPE Init( 
       REFCLSID clsidDMO,
       REFCLSID catDMO) = 0;
      
     };
     
    #else 	/* C style interface */
     //...
    #endif
    
    
    and in .net normally it should be as:

     [ComImport,
     // SuppressUnmanagedCodeSecurity, // not supported in .netcf, so i made it commented.
     Guid("52d6f586-9f0f-4824-8fc8-e32ca04930c2"),
     InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
     public interface IDMOWrapperFilter
     {
      [PreserveSig]
      int Init(
       [In, MarshalAs(UnmanagedType.LPStruct)] Guid clsidDMO,
       [In, MarshalAs(UnmanagedType.LPStruct)] Guid catDMO
       );
     }
    
    
    then i start debugging (on the emulator), and when calling this init method it throws an notsupportedexception. after i delete the two marshalas() properties, there is no exception at all.

    meanwhile, it works well with another interface:

     [ComVisible(true), ComImport,
     Guid("55272A00-42CB-11CE-8135-00AA004BB851"),
     InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
     public interface IPropertyBag
     {
      [PreserveSig]
      int Read(
       [In, MarshalAs(UnmanagedType.LPWStr)] string pszPropName,
       [In, Out, MarshalAs(UnmanagedType.Struct)] ref object pVar,
       [In] IntPtr pErrorLog);
    
      [PreserveSig]
      int Write(
       [In, MarshalAs(UnmanagedType.LPWStr)] string pszPropName,
       [In, MarshalAs(UnmanagedType.Struct)] ref object pVar);
     }
    
    
    im confused.


    can you refer any articles or even tell me whats wrong between these declarations? thank you.


    • Edited by HeroXXiv Sunday, June 13, 2010 2:32 AM formats
    Sunday, June 13, 2010 2:25 AM

Answers

  • Try this:

     

    public
     interface
     IDMOWrapperFilter
    {
    [PreserveSig]
    int Init(
    ref Guid clsidDMO,
    ref Guid catDMO
    );
    }

    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by warrentang Friday, June 18, 2010 5:39 AM
    Sunday, June 13, 2010 8:56 PM