COM call from WndProc causes runtime error 8001010D


hello all,
following scenario: i'm developing .net 1.1 application in c# burn cds/dvds via imapiv2.
for unimportant reason i'm stuck .net 1.1 makes implementation pretty tricky anyways. right i'm having pretty basic com-architecture related problem. i've react on events when cds/dvds inserted or removed machine , (on inserting) media details (writable? rewritable? capacity? free sectors etc). purpose use wndproc shown in following snippets:
 
btw: there way these message without window?

code snippet

using system;
using system.windows.forms;
 
namespace burningtests
{
 public delegate void wndprocdelegate(ref message m);
 
 public class wndprocprovider : nativewindow
 {
  public wndprocdelegate onwndproc;
 
  public wndprocprovider(form parent)
  {
   parent.handlecreated += new eventhandler(this.onhandlecreated);
   parent.handledestroyed += new eventhandler(this.onhandledestroyed);
  }
 
  internal void onhandlecreated(object sender, eventargs e)
  {
   assignhandle(((form)sender).handle);
  }
 
  internal void onhandledestroyed(object sender, eventargs e)
  {
   releasehandle();
  }
 
  protected override void wndproc(ref message m)
  {
   if(onwndproc != null)
    onwndproc(ref m);
 
   base.wndproc (ref m);
  }
 }
}

 

code snippet

using system;
using system.data;
using system.globalization;
using system.text.regularexpressions;
using system.threading;
using system.windows.forms;
using burningtests;
using imapi2.interop;
 
namespace xxx.imapi2burningservices
{
 public class bsburner
 {
  private const int wm_devicechange = 0x0219;
  private const int dbt_devicearrival = 0x8000;
  private const int dbt_deviceremovecomplete = 0x8004;
 
  public bsburnerupdatedelegate burnerupdate;
 
  // [...]
 
  private form helperform;
  private wndprocprovider wndprocprovider;
 
  private static regex regexhresultexc;
 
  static bsburner()
  {
   regexhresultexc = new regex(".*hresult:.?0x([0-9a-f]*).*");
  }
 
  public bsburner(form helperform)
  {
   this.helperform = helperform;
 
   if (helperform != null)
   {
    wndprocprovider = new wndprocprovider(helperform);
    wndprocprovider.onwndproc += new wndprocdelegate(onwndproc);
   }
  }
 
  ~bsburner()
  {
   // [...]
  }
 
  private void onwndproc(ref message m)
  {
   if (convert.toint32(m.msg) == wm_devicechange)
   {
    switch (m.wparam.toint32())
    {
     case (dbt_devicearrival):
      this.refreshmediainfo();
      break;
     case (dbt_deviceremovecomplete):
      this.refreshmediainfo();
      break;
    }
   }
  }
 
  public void refreshmediainfo()
  {
   // here comes hell lot of code several com calls imapi
   // fails on runtime error 8001010d when called
   // wndproc
  }
 }
}

 

from runtime error 8001010d conclude, wndproc approach of nativewindow realised through com. occurrence of runtime error / logical. 1 ugly way solve start .net timer calling refreshmediainfo method; definately prefer not this.
i wonder if there way these events without using wndproc , in best case without using com (whether using directly or indirectly in example).
and wonder if possible make com calls while synchronized com call not finished special locking or synchronization techniques (or clever workarounds).

 

 

just in case stumbles on problem:
a quick , seemingly sufficient solution problem use dummy lock object, lock in wndproc this:

private void onwndproc(ref message m)
{
  lock(lockobject)
  {
    // if(condition) { // start thread }
  }     
}

and lock before each com call may done before synchron com call of wndproc finished. in theory there little gap com call before synchron com call of wndproc finished. approach worked/works fine me , proved in little stress test.

regards,  jacob


.NET Framework  >  Common Language Runtime Internals and Architecture



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

job syspolicy_purge_history job fail in sqlserver 2008

Trying to register with public marketplace error with 'Get-AzureStackStampInformation'