惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Forbes - Security
Forbes - Security
GbyAI
GbyAI
WordPress大学
WordPress大学
小众软件
小众软件
Y
Y Combinator Blog
The GitHub Blog
The GitHub Blog
S
SegmentFault 最新的问题
A
About on SuperTechFans
月光博客
月光博客
F
Fortinet All Blogs
宝玉的分享
宝玉的分享
Microsoft Security Blog
Microsoft Security Blog
大猫的无限游戏
大猫的无限游戏
Hugging Face - Blog
Hugging Face - Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
V2EX
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
N
Netflix TechBlog - Medium
Jina AI
Jina AI
博客园 - 聂微东
Schneier on Security
Schneier on Security
云风的 BLOG
云风的 BLOG
博客园 - 司徒正美
N
News | PayPal Newsroom
PCI Perspectives
PCI Perspectives
Last Week in AI
Last Week in AI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
P
Proofpoint News Feed
Hacker News: Ask HN
Hacker News: Ask HN
B
Blog
aimingoo的专栏
aimingoo的专栏
P
Privacy International News Feed
Martin Fowler
Martin Fowler
罗磊的独立博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More
NISL@THU
NISL@THU
Know Your Adversary
Know Your Adversary
C
Cybersecurity and Infrastructure Security Agency CISA
博客园 - 叶小钗
N
News and Events Feed by Topic
T
The Exploit Database - CXSecurity.com
Stack Overflow Blog
Stack Overflow Blog
S
Security @ Cisco Blogs
D
Darknet – Hacking Tools, Hacker News & Cyber Security
V
Vulnerabilities – Threatpost
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Threatpost
IT之家
IT之家
B
Blog RSS Feed

博客园 - 所言非虚

未来谁才是移动互联网的入口? [Oracle]Sqlplus连接成功,但pl/sql连接不成功,提示“ora-12145:无法解析指定的连接标识符” Windows待机、休眠、睡眠的区别以及程序运行策略 [Worldwind]worldwind源码编译 windows server 2008 x64下oracle 10gR2的安装方法 [长期]常见问题收集 最佳编程字体推荐 GDAL问题收集 向量点积与叉积的定义及应用 空间平面法向量求法 【解决】加载图片"内存不足"问题 【原创】随鼠标移动显示地图经纬度 - 所言非虚 - 博客园 【原创】客户端添加兴趣点,并随地图变化而变化 - 所言非虚 - 博客园 【原创】利用ESRI自带的符号库进行符号化 FireFox与IE的兼容 【转】兼容IE和FireFox的鼠标滚轮事件 DIV的精确定位 - 所言非虚 - 博客园 ArcGIS Server开发的一些小经验 [译]ArcGIS Server Map Service Cache的组织结构
ArcSDE C API在.NET中的调用 - 所言非虚
所言非虚 · 2008-03-10 · via 博客园 - 所言非虚
在.NET中调用API函数C#:
        

using System.Runtime.InteropServices;
[DllImport(
"sde.dll")]//还有其他的属性可参考MSDN
public static extern Int32 SE_connection_create(string server, string instance, string database, string username, string pwd, ref SE_ERROR error, out IntPtr pSdeConn);


VB.NET:
        

Imports System.Runtime.InteropServices
<DllImport("sde.dll", SetLastError:=True, ThrowOnUnmappableChar:=True)> _
Public Shared Function SE_connection_create(ByVal server As StringByVal instance As String,ByVal database As StringByVal username As StringByVal password As StringByRef error1 As SE_ERROR,ByRef connection As IntPtr) As Int32
End Function

        还可以使用Declar关键字来引用API函数,这里就不介绍了。
ArcSDE C API的声明方法
        '--------------↓声明SE_ERROR结构体↓-----------------
        

        <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _
        Public Structure SE_ERROR
 

            Public sde_error As Int32
            Public ext_error As Int32
            '<MarshalAs(UnmanagedType.ByValArray, SizeConst:=512)> _
            Public err_msg1 As Char()
            '<MarshalAs(UnmanagedType.ByValArray, SizeConst:=4096)> _
            Public err_msg2 As Char()
        End Structure

        '--------------↑声明SE_ERROR结构体↑-----------------

        '-------------------调用SE_connection_create函数----------------------
        '------------------连接SDE-------------------------
        '返回结果
        'SE_SUCCESS     0
        'SE_FAILURE     -1
        'SE_NO_ACCESS   -15
        'SE_SDE_NOT_STARTED     -5
        'SE_IOMGR_NOT_AVAILABLE     -101
        'SE_INVALID_DATABASE        -162
        'SE_INVALID_SERVER      -100
        'SE_INVALID_POINTER     -65
        'SE_INVALID_USER        -9
        'SE_LOGIN_NOT_ALLOWED       -8
        'SE_DBMS_DOES_NOT_SUPPORT       -1008
        'SE_NET_FAILURE     -10
        'SE_NET_TIMEOUT     -11
        'SE_SERVICE_NOT_FOUND       -102
        'SE_TASKS_EXCEEDED      -7

        <DllImport("sde.dll", SetLastError:=True,ThrowOnUnmappableChar:=True)> _
        Public Shared Function SE_connection_create(ByVal server As String, ByVal instance As String, _
        ByVal database As String, ByVal username As String, ByVal password As String, ByRef error1 As SE_ERROR, _
        ByRef connection As IntPtr) As Int32
        End Function

 '----------------------------调用SE_connection_free函数-------------------------
        '----------------------------释放SDE连接----------------------
        <DllImport("sde.dll", SetLastError:=True, ThrowOnUnmappableChar:=True)> _
        Public Shared Sub SE_connection_free(ByVal Byrefconnection As IntPtr)
        End Sub

在程序中的调用

Imports QHProject.SDE_C_API
Imports System.Runtime.InteropServices

Partial Class MapServicePage
    Inherits System.Web.UI.Page

    Private Shared conn As IntPtr = Nothing
    Private error1 As QHProject.SDE_C_API.SDE_C_API_Operation.SE_ERROR = Nothing

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 

    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim i As Int32 = SDE_C_API_Operation.SE_connection_create("CL", "5151", "sde", "sde", "clbeyond", error1, conn)
        Button1.Text = i.ToString()

    End Sub

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        SDE_C_API_Operation.SE_connection_free(conn)
    End Sub
End Class

连接成功后Button的Text属性会显示为0,表示连接成功,在任务管理器中就会发现出现了一个gsrvr.ext进程。断开连接后gsrvr.exe进程就会消失。
当然前提是要在程序中将连接字段conn声明为shared类型(C#中的Static类型)。
需要注意的是Instance不是"esri_sde",而是端口号,一般为5151。
                                                                           2008年3月10日15:41:31