Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. COM Interopability problem

COM Interopability problem

Scheduled Pinned Locked Moved C#
questioncsharpcomsysadmindata-structures
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    iliyang
    wrote on last edited by
    #1

    I'm trying to control FlashGet using COM in my .NET application. I made a wrapper class of the jccatch COM server. I create an instance of the JetCarNetscapeClass defined in the wrapper class. The method AddUrl works fine - it has three string parameters. The problem comes from the AddUrlList method. In the original declaration in the COM server it has a VARIANT* pList parameter, and the wrapper class marshalizes it as ref object pList. So, when I pass an array or ArrayList of strings, an exception is thrown. What kind of parameter should I pass to the method or how can I change the default marshalizing behavior? I couldn't find a solution and I searched a lot.

    H 1 Reply Last reply
    0
    • I iliyang

      I'm trying to control FlashGet using COM in my .NET application. I made a wrapper class of the jccatch COM server. I create an instance of the JetCarNetscapeClass defined in the wrapper class. The method AddUrl works fine - it has three string parameters. The problem comes from the AddUrlList method. In the original declaration in the COM server it has a VARIANT* pList parameter, and the wrapper class marshalizes it as ref object pList. So, when I pass an array or ArrayList of strings, an exception is thrown. What kind of parameter should I pass to the method or how can I change the default marshalizing behavior? I couldn't find a solution and I searched a lot.

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      And ArrayList will not marshal the same as an array of strings. What you passed to the interop'd method AddUrlList depends on what the documentation states. More than likely you must pass it a SAFEARRAY. Since you created an interop assembly (RCW) using VS.NET or tlbimp.exe, you've lost the opportunity to define the correct UnmanagedType to the MarshalAsAttribute, namely the UnmanagedType.SafeArray type. You can, however, re-declare the same interface yourself with the ComImportAttribute and the correct GuidAttribute and ComInterfaceAttribute (with values the same as the one in the interop assembly). If you read the documentation for the UnmanagedType.SafeArray you should get some idea of how to marshal the string[] array correctly. You could also try using Marshal.GetNativeVariantForObject, but you'll need additional methods from the Marshal class to marshal the returned IntPtr correctly as an object. The method above would probably be easier (you won't have to marshal the data yourself; .NET will do it for you). Again, though, this all depends on what the AddUrlList is expecting. If you were to tell us what the API documentation states (not what tlbimp.exe or VS.NET thinks it should be in the interop assembly), that will most likely help. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups