Using DynamicInvoke?

T

Terry Olsen

I'm using the SciLexer.dll to write a code editor for an in-house scripting
language. I have the editor window up on a form but I need to use it's API.
I've used the following commands to load the dll:

Private scihWnd As Integer 'Scintilla's hWnd
Private SciFunc As Integer 'Scintilla's Main Function Call
Private sciptr As Integer 'Scintilla's Direct Pointer
Private scihmod As Integer 'Scintilla's hMod

scihmod = LoadLibrary("SciLexer.DLL")
If scihmod = 0 Then
Throw New Exception("Unable to load SciLexer.dll")
Exit Sub
End If

scihWnd = CreateWindowEx(...)
SciFunc = GetProcAddress(scihWnd, "Scintilla_DirectFunction")
sciptr = SendMessage(scihWnd, SCI_GETDIRECTPOINTER, 0, 0)

Now I need to call the the SciFunc that was returned from the GetProcAddress
call.

Is this the correct way to do it? I haven't had time to try it yet because
I'm on my way out the door, so I thought i'd ask the question ahead of time.
Here's my tentative code...

Private Function Scintilla(ByVal args() As Object) As Object
Dim t As Type = Nothing
Dim ret As Object = Nothing
ret = Marshal.GetDelegateForFunctionPointer(SciFunc,
t).DynamicInvoke(args)
Return ret
End Function

My next question, isn't there a way to pass an array on the fly without
declaring and filling an array first? Something like:

Scintilla({sciptr,"SCI_SETTEXT",0,"This is my text"})

Thanks!
 
H

Herfried K. Wagner [MVP]

Terry Olsen said:
I'm using the SciLexer.dll to write a code editor for an in-house
scripting language. I have the editor window up on a form but I need to
use it's API. I've used the following commands to load the dll:

Private scihWnd As Integer 'Scintilla's hWnd
Private SciFunc As Integer 'Scintilla's Main Function Call
Private sciptr As Integer 'Scintilla's Direct Pointer
Private scihmod As Integer 'Scintilla's hMod

scihmod = LoadLibrary("SciLexer.DLL")
If scihmod = 0 Then
Throw New Exception("Unable to load SciLexer.dll")
Exit Sub
End If

scihWnd = CreateWindowEx(...)
SciFunc = GetProcAddress(scihWnd, "Scintilla_DirectFunction")
sciptr = SendMessage(scihWnd, SCI_GETDIRECTPOINTER, 0, 0)

A Window handle does not have functions. The first parameter of
'GetProcAddress' expects a 'HMODULE'. You can use the handle returned by
'LoadLibrary' there.
My next question, isn't there a way to pass an array on the fly without
declaring and filling an array first? Something like:

Scintilla({sciptr,"SCI_SETTEXT",0,"This is my text"})

'Scintilla(New Object() {..., ...})'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top