Groups | Blog | Home
all groups > vb.net > january 2008 >

vb.net : Using DynamicInvoke?


Terry Olsen
1/7/2008 7:16:02 AM
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!

Herfried K. Wagner [MVP]
1/7/2008 3:23:04 PM
"Terry Olsen" <tolsen64@hotmail.com> schrieb:
[quoted text, click to view]

A Window handle does not have functions. The first parameter of
'GetProcAddress' expects a 'HMODULE'. You can use the handle returned by
'LoadLibrary' there.

[quoted text, click to view]

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

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
AddThis Social Bookmark Button