当前位置:编程学习 > C#/ASP.NET >>

端口监听

//厂商提供的DLL的说明文件
TCPIPServerOpen(ListenPort)
   参数:
参数名称 参数类型 数据类型 参数说明
ListenPort 设定值 整数 监听的端口号

返回值:
名称 返回值
成功 True
失败 False

举例:
   ListenPort=8000
   TCPIPServerOpen(ListenPort)
////////////////
vb中代码和C#一样,但是VB中可以执行,运行正确
但是在C#中如下代码报错
code=csharp]
 bool flag = false;
int ListenPort = 8000;         
flag = SystemLayer.TCPIPServerOpen(ListenPort );[/code]

未处理 System.AccessViolationException
  Message="尝试读取或写入受保护的内存。这通常指示其他内存已损坏。"
  Source="SmartKey"
  StackTrace:
       在 SmartKey.SystemLayer.TCPIPServerOpen(Int32 ListenPort)
       在 SmartKey.Form1.Form1_Load(Object sender, EventArgs e) 位置Form1.cs:行号 49
       在 System.Windows.Forms.Form.OnLoad(EventArgs e)
       在 System.Windows.Forms.Form.OnCreateControl()
       在 System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
       在 System.Windows.Forms.Control.CreateControl()
       在 System.Windows.Forms.Control.WmShowWindow(Message& m)
       在 System.Windows.Forms.Control.WndProc(Message& m)
       在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       在 System.Windows.Forms.ContainerControl.WndProc(Message& m)
       在 System.Windows.Forms.Form.WmShowWindow(Message& m)
       在 System.Windows.Forms.Form.WndProc(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       在 System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
       在 System.Windows.Forms.Control.SetVisibleCore(Boolean value)
       在 System.Windows.Forms.Form.SetVisibleCore(Boolean value)
       在 System.Windows.Forms.Control.set_Visible(Boolean value)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.Run(Form mainForm)
       在 SmartKey.Program.Main() 位置 行号 17
       在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       在 System.Threading.ThreadHelper.ThreadStart()
  InnerException: 
--------------------编程问答-------------------- 调用约定要保持一致,是stdcall 还是 cdecl --------------------编程问答-------------------- 给的DLL 不知道什么语言,
我用的是C# 环境是2010.。 --------------------编程问答-------------------- 三种约定我都实验了 没有用 
还是报错

用 Delphi  也不报错。。。

应该是VS2010 本身哪设置或者调用问题?
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,