2011-07-19 17 views
1
  • 是否有C#/WPF應用 到CoInitialize()替代加載並使用COM組件?
  • 在創建WPF 應用程序COM合規性時,是否有任何設置需要檢查?

回答

0

你可以這樣做;你只需要知道COM組件的ProgID。

public static object COMCreateObject (string sProgID) 
{ 
    // We get the type using just the ProgID 
    Type oType = Type.GetTypeFromProgID (sProgID); 
    if (oType != null) 
    {     
     return Activator.CreateInstance(oType); 
    } 

    return null; 
} 

假設你的淨3.5或4.0框架內工作,WPF應用程序可以處理的創建和COM的破壞對象外的開箱,只要確定你是你妥善處理。