相关疑难解决方法(0)

为什么我不能将我的COM对象转换为它在C#中实现的接口?

我在dll中有这个接口(此代码在元数据中显示在Visual Studio中):

#region Assembly XCapture.dll, v2.0.50727
// d:\svn\dashboard\trunk\Source\MockDiagnosticsServer\lib\XCapture.dll
#endregion

using System;
using System.Runtime.InteropServices;

namespace XCapture
{
    [TypeLibType(4160)]
    [Guid("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")]
    public interface IDiagnostics
    {
        [DispId(1)]
        void GetStatusInfo(int index, ref object data);
    }
}
Run Code Online (Sandbox Code Playgroud)

所以我用这样的类创建了一个COM服务器:

[ComVisible(true)]
[Guid(SimpleDiagnosticsMock.CLSID)]
[ComDefaultInterface(typeof(IDiagnostics))]
[ClassInterface(ClassInterfaceType.None)]
public class SimpleDiagnosticsMock : ReferenceCountedObject, IDiagnostics
{
    public const string CLSID = "281C897B-A81F-4C61-8472-79B61B99A6BC";

    // These routines perform the additional COM registration needed by 
    // the service. ---- stripped from example

    void IDiagnostics.GetStatusInfo(int index, ref object data)
    {
        Log.Info("GetStatusInfo called with index={0}, data={1}", index, data); …
Run Code Online (Sandbox Code Playgroud)

c# com

13
推荐指数
2
解决办法
3万
查看次数

如何通过.NET API打开AutoCAD 2015

我已经浏览了一个小时,还没有找到有助于此的东西.我正在使用C#从VS2013中的.NET API打开AutoCAD,但出于某种原因,我无法让AutoCAD实际启动.我正在使用以下代码:

using System;
using System.Runtime.InteropServices;

using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;

namespace IOAutoCADHandler
{
    public static class ACADDocumentManagement
    {
        [CommandMethod("ConnectToAcad")]
        public static void ConnectToAcad()
        {

            AcadApplication acAppComObj = null;
            // no version number so it will run with any version
            const string strProgId = "AutoCAD.Application";

            // Get a running instance of AutoCAD
            try
            {
                acAppComObj = (AcadApplication)Marshal.GetActiveObject(strProgId);
            }
            catch // An error occurs if no instance is running
            {
                try
                {
                    // Create a new instance of AutoCAD
                    acAppComObj …
Run Code Online (Sandbox Code Playgroud)

.net c# autocad visual-studio-2013

11
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×2

.net ×1

autocad ×1

com ×1

visual-studio-2013 ×1