首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >发送SCI_GETTEXT (和其他)使应用程序崩溃

发送SCI_GETTEXT (和其他)使应用程序崩溃
EN

Stack Overflow用户
提问于 2014-02-04 23:45:49
回答 1查看 412关注 0票数 3

我试图在我的RealStudio应用程序中使用Scintilla编辑器。我能够加载DLL,创建Scintilla子窗口,并向窗口发送消息,只要消息参数不引用字符串。如果我尝试获取或设置字符串,Windows将立即使用错误代码5(访问被拒绝)终止应用程序。

下面是我的代码,来自包含窗口的Open事件:

代码语言:javascript
复制
  #If TargetWin32 Then
    Declare Function CreateWindowExA Lib "User32" (ExStyle As Integer, ClassName As CString, WindowName As CString, Style As Integer, X As Integer, Y As Integer, Width As Integer, Height As Integer, Parent As Integer, Menu As Integer, Instance As Integer, Param As Ptr) As Integer
    Declare Function SendMessageA Lib "User32" (HWND As Integer, Message As UInt32, WParam As Ptr, LParam As Ptr) As Integer
    Const SCI_GETLENGTH = 2006
    Const SCI_GETTEXT = 2182
    Const WS_CHILD = &h40000000
    Const WS_CLIPCHILDREN = &h02000000
    Const WS_TABSTOP = &h00010000
    Const WS_VISIBLE = &h10000000


    ' IsFunctionAvailable calls LoadLibrary and GetProcAddress
    If System.IsFunctionAvailable("Scintilla_DirectFunction", "SciLexer") Then
      ' Create the Scintilla child window
      Dim SciHandle As Integer = CreateWindowExA(0, "Scintilla", "", WS_CHILD Or WS_CLIPCHILDREN Or WS_TABSTOP Or WS_VISIBLE, 5, 5, Me.Width - 10, Me.Height - 10, Me.Handle, 0, 0, Nil)

      Dim count, buffer As MemoryBlock
      ' Get the current character count
      Dim c As  Integer = SendMessageA(SciHandle, SCI_GETLENGTH, Nil, Nil) ' This works

      count = New MemoryBlock(4) ' Store the count in a MemoryBlock
      count.Int32Value(0) = c + 1
      buffer = New MemoryBlock(c + 1) ' allocate the buffer
      Call SendMessageA(SciHandle, SCI_GETTEXT, count, buffer) ' This crashes
    End If
  #endif

为了我的生命,我弄不明白为什么它不起作用。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-05 08:23:13

SCI_GETTEXT声明如下:

代码语言:javascript
复制
SCI_GETTEXT(int length, char *text)

这意味着:将长度参数作为整数传递,并传递指向文本缓冲区的指针。

但是,您的代码传递一个指向长度的整数的指针。试一试:

代码语言:javascript
复制
Declare Function SendMessageAip Lib "User32" (HWND As Integer, Message As UInt32, WParam As Integer, LParam As Ptr) As Integer
buffer = New MemoryBlock(c + 1) ' allocate the buffer
Call SendMessageAip(SciHandle, SCI_GETTEXT, c+1, buffer)
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21565942

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档