帮我看看这个代码有什么问题?

seawaterblue seawaterblue 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
这个是一个arcgis的示例代码,在我开发的机器上运行没有问题,但是注册到别人的机器上时在程序运行完退出的时候出现以下错误:


具体信息如下:
************* 异常文本 **************
System.AccessViolationException: 尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
在 System.Windows.Forms.UnsafeNativeMethods.IOleInPlaceObject.GetWindow(IntPtr& hwnd)
在 System.Windows.Forms.AxHost.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** 已加载的程序集 **************
mscorlib
程序集版本: 2.0.0.0
Win32 版本: 2.0.50727.3053 (netfxsp.050727-3000)
基本代码: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
ContentsView
程序集版本: 1.0.4727.37063
Win32 版本: 1.0.4727.37063
基本代码: file:///C:/ContentsView.DLL
----------------------------------------
ESRI.ArcGIS.ArcMapUI
程序集版本: 9.3.0.1770
Win32 版本: 9.3.0.1770
基本代码: file:///C:/WINDOWS/assembly/GAC_MSIL/ESRI.ArcGIS.ArcMapUI/9.3.0.1770__8fc3cc631e44ad86/ESRI.ArcGIS.ArcMapUI.dll
----------------------------------------
System.Windows.Forms
程序集版本: 2.0.0.0
Win32 版本: 2.0.50727.3053 (netfxsp.050727-3000)
基本代码: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
程序集版本: 2.0.0.0
Win32 版本: 2.0.50727.3053 (netfxsp.050727-3000)
基本代码: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
程序集版本: 2.0.0.0
Win32 版本: 2.0.50727.3053 (netfxsp.050727-3000)
基本代码: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
ESRI.ArcGIS.AxControls
程序集版本: 9.3.0.1770
Win32 版本: 9.3.0.1770
基本代码: file:///C:/WINDOWS/assembly/GAC_MSIL/ESRI.ArcGIS.AxControls/9.3.0.1770__8fc3cc631e44ad86/ESRI.ArcGIS.AxControls.dll
----------------------------------------
ESRI.ArcGIS.Controls
程序集版本: 9.3.0.1770
Win32 版本: 9.3.0.1770
基本代码: file:///C:/WINDOWS/assembly/GAC_MSIL/ESRI.ArcGIS.Controls/9.3.0.1770__8fc3cc631e44ad86/ESRI.ArcGIS.Controls.dll
----------------------------------------
Accessibility
程序集版本: 2.0.0.0
Win32 版本: 2.0.50727.3053 (netfxsp.050727-3000)
基本代码: file:///C:/WINDOWS/assembly/GAC_MSIL/Accessibility/2.0.0.0__b03f5f7f11d50a3a/Accessibility.dll
----------------------------------------
System.Windows.Forms.resources
程序集版本: 2.0.0.0
Win32 版本: 2.0.50727.3053 (netfxsp.050727-3000)
基本代码: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms.resources/2.0.0.0_zh-CHS_b77a5c561934e089/System.Windows.Forms.resources.dll
----------------------------------------
mscorlib.resources
程序集版本: 2.0.0.0
Win32 版本: 2.0.50727.3053 (netfxsp.050727-3000)
基本代码: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------

************** JIT 调试 **************
要启用实时(JIT)调试,
该应用程序或计算机的 .config 文件(machine.config)的 system.windows.forms 节中必须设置
jitDebugging 值。
编译应用程序时还必须启用
调试。

例如:

<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>

启用 JIT 调试后,任何无法处理的异常
都将被发送到在此计算机上注册的 JIT 调试器,
而不是由此对话框处理。

那个示例的源程序如下

using System;
using System.Drawing;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.ADF.CATIDs;
using ESRI.ArcGIS.Framework;
using ESRI.ArcGIS.ArcMapUI;

namespace CommandInheritingBaseCommand
{

[Guid("46bd0933-acac-4c33-8669-1255db03ca5c")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("CommandInheritingBaseCommand.ZoomToLayer")]
public sealed class ZoomToLayer : BaseCommand
{
#region COM Registration Function(s)
[ComRegisterFunction()]
[ComVisible(false)]
static void RegisterFunction(Type registerType)
{
// Required for ArcGIS Component Category Registrar support
ArcGISCategoryRegistration(registerType);

//
// TODO: Add any COM registration code here
//
}

[ComUnregisterFunction()]
[ComVisible(false)]
static void UnregisterFunction(Type registerType)
{
// Required for ArcGIS Component Category Registrar support
ArcGISCategoryUnregistration(registerType);

//
// TODO: Add any COM unregistration code here
//
}

#region ArcGIS Component Category Registrar generated code
/// <summary>
/// Required method for ArcGIS Component Category registration -
/// Do not modify the contents of this method with the code editor.
/// </summary>
private static void ArcGISCategoryRegistration(Type registerType)
{
string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
MxCommands.Register(regKey);

}
/// <summary>
/// Required method for ArcGIS Component Category unregistration -
/// Do not modify the contents of this method with the code editor.
/// </summary>
private static void ArcGISCategoryUnregistration(Type registerType)
{
string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
MxCommands.Unregister(regKey);

}

#endregion
#endregion

private IApplication m_application;
public ZoomToLayer()
{
//
// TODO: Define values for the public properties
//
base.m_category = "Developer Samples"; //localizable text
base.m_caption = "Zoom To Layer CSharp"; //localizable text
base.m_message = "Zoom to the extent of the active layer in the TOC"; //localizable text
base.m_toolTip = "Zoom To Layer CSharp"; //localizable text
base.m_name = "DeveloperSamples_ZoomToLayerCSharp"; //unique id, non-localizable (e.g. "MyCategory_ArcMapCommand")
try
{
//
// TODO: change bitmap name if necessary
//
string bitmapResourceName = GetType().Name + ".bmp";
base.m_bitmap = new Bitmap(GetType(), bitmapResourceName);
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap");
}
}

#region Overriden Class Methods

/// <summary>
/// Occurs when this command is created
/// </summary>
/// <param name="hook">Instance of the application</param>
public override void OnCreate(object hook)
{
if (hook == null)
return;

m_application = hook as IApplication;

//Disable if it is not ArcMap
if (hook is IMxApplication)
base.m_enabled = true;
else
base.m_enabled = false;

// TODO: Add other initialization code
}

/// <summary>
/// Occurs when this command is clicked
/// </summary>
public override void OnClick()
{
IMxDocument mxDocument = GetMxDocument(m_application);
ZoomToLayerInTOC(mxDocument);
}

#endregion

#region "Zoom to Active Layer in TOC"

public void ZoomToLayerInTOC(ESRI.ArcGIS.ArcMapUI.IMxDocument mxDocument)
{
if (mxDocument == null)
{
return;
}
ESRI.ArcGIS.Carto.IActiveView activeView = mxDocument.ActiveView;

// Get the TOC
ESRI.ArcGIS.ArcMapUI.IContentsView IContentsView = mxDocument.CurrentContentsView;

// Get the selected layer
System.Object selectedItem = IContentsView.SelectedItem;
if (!(selectedItem is ESRI.ArcGIS.Carto.ILayer))
{
return;
}
ESRI.ArcGIS.Carto.ILayer layer = selectedItem as ESRI.ArcGIS.Carto.ILayer;


// Zoom to the extent of the layer and refresh the map
activeView.Extent = layer.AreaOfInterest;
activeView.Refresh();
}
#endregion

#region "Get MxDocument from ArcMap"

public ESRI.ArcGIS.ArcMapUI.IMxDocument GetMxDocument(ESRI.ArcGIS.Framework.IApplication application)
{

if (application == null)
{
return null;
}
ESRI.ArcGIS.ArcMapUI.IMxDocument mxDocument = ((ESRI.ArcGIS.ArcMapUI.IMxDocument)(application.Document)); // Explicit Cast

return mxDocument;

}
#endregion

}
}
...全文

相关推荐

AIGC Copilot代码审查:AI如何帮你发现潜在问题

本文旨在全面解析AI辅助代码审查技术(AIGC Copilot)的工作原理、实现方法和实际应用。AI如何理解代码语义机器学习在代码缺陷检测中的应用与传统静态分析工具的区别实际开发中的集成方式本文首先介绍AI代码审查的基本概念,然后深入技术细节,包括算法原理和数学模型。接着通过实际案例展示应用场景,最后讨论未来发展趋势。AIGC: 人工智能生成内容,在本文特指AI生成的代码审查建议静态分析: 在不执行代码的情况下分析其结构和属性抽象语法树(AST): 源代码语法结构的树状表示。

AI大模型应用工坊

需求不清时,如何让 AI 帮你补全问题,而不是瞎写代码

这篇文章探讨了如何处理模糊需求并利用AI辅助开发,避免因需求不明确导致的返工问题。文章提出了以下核心方法: 需求不清时,AI最擅长暴露问题:直接让AI实现模糊需求会导致大量未经确认的假设被写入代码,正确做法是先让AI生成需要确认的问题清单。 五类问题分类法:将问题按业务规则、权限与状态、数据与边界、异常与幂等、交付与验证五个维度分类,确保系统性覆盖。 候选方案分析:让AI为每个问题提供多个解决方案,分析每个方案的成本、用户体验和风险,但不替开发者做决策。 结构化确认流程:提供了从原始需求到最终确认的六步工作

全栈弄潮儿²⁰²⁶

chrome-headless-shell-win32-159.0.8132.0(Canary).zip

chrome-headless-shell-win32-159.0.8132.0(Canary).zip

LCG元

惠普150 联想1821 1831 1831W定影清零,转印带清零

惠普150 联想1821 1831 1831W定影清零,转印带清零,报错不打印,通过清零软件可以清除。内附使用说明。

weixin_45614853

【电液伺服执行器与PI控制器】带有PI控制器的电液伺服执行器的模拟研究(Simulink仿真实现)

内容概要:本文围绕带有PI控制器的电液伺服执行器开展模拟研究,利用Simulink工具构建系统仿真模型,深入分析PI控制器在电液伺服系统中的控制性能与动态响应特性。研究内容涵盖系统建模、PI控制参数整定、仿真结果分析等关键环节,重点探讨PI控制器对系统稳定性、响应速度及抗干扰能力的优化作用,并通过仿真验证控制策略的有效性与实用性; 适合人群:具备自动控制原理、液压传动基础知识及Simulink仿真能力的自动化、机械电子、控制工程等相关专业的高校学生、研究生及工程技术人员; 使用场景及目标:①用于自动控制类课程的教学实验或课程设计,帮助学生深入理解电液伺服系统的工作原理与典型控制方法;②应用于工业高精度执行机构的控制器设计,为实际工程中的系统优化提供理论支撑与仿真验证手段; 阅读建议:文中提供的Simulink模型与仿真流程具备良好的可复现性,建议读者结合具体工况调整PI参数,进一步探究PID或其他先进控制算法的改进效果,以深化对控制系统设计的理解与应用能力。

三伯
评论 6
收藏 已收藏
分享
返回顶部
seawaterblue
C# 111,129 成员 642,539 内容