Use of delegate

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



I am having a hard time with delegates, but here I must pass a delegate and
a pointer to a structure. I am totally lost. Passing the pointer to
rlistsys_resp_func and RLISTSYS_DETAIL is where I am lost. Any hint would
be highly appreciated.

C Header:
_declspec(dllexport) extern void rlistsys(RLISTSYS_PARMS *rlistsys_parms,
RLISTSYS_RESP *rlistsys_resp, void (*rlistsys_resp_func)(RLISTSYS_DETAIL
*));

VB.NET
Dim RLISTSYS_DETAIL As New TRLISTSYS_DETAIL
Dim objDelegate As RLISTSYS_FUNC
objDelegate = AddressOf RLISTSYS_FUNC_RUN
rlistsys(RLISTSYS_PARMS, RLISTSYS_RESP, objDelegate, RLISTSYS_DETAIL)

Module1
Public Delegate Sub RLISTSYS_FUNC(ByRef RLISTSYS_DETAIL As
TRLISTSYS_DETAIL)
Public Sub RLISTSYS_FUNC_RUN(ByRef RLISTSYS_DETAIL As TRLISTSYS_DETAIL)
frmMain.grd.Rows.Add(CleanInput(RLISTSYS_DETAIL.name), CleanInput
(RLISTSYS_DETAIL.description))
End Sub

Public Declare Function rlistsys Lib "remotapi.dll" (ByRef RLISTSYS_PARMS
As TRLISTSYS_PARMS, ByRef RLISTSYS_RESP As TRLISTSYS_RESP, ByRef
objDelegate As RLISTSYS_FUNC, ByRef RLISTSYS_DETAIL As TRLISTSYS_DETAIL) As
Integer


Error:

System.ArgumentException was unhandled
Message="Type could not be marshaled because the length of an embedded
array instance does not match the declared length in the layout."
Source="Chainlinkwork"
StackTrace:
at Chainlinkwork.Module1.rlistsys(TRLISTSYS_PARMS& RLISTSYS_PARMS,
TRLISTSYS_RESP& RLISTSYS_RESP, RLISTSYS_FUNC& objDelegate, TRLISTSYS_DETAIL&
RLISTSYS_DETAIL)


.



Relevant Pages

  • Re: Help with delegates
    ... Sometimes your code needs what in classic C language is called "a pointer to ... objects and return an integer with the comparision result. ... A .NET delegate is class which encapsulates a pointer to a ... > Public Delegate Function GetTotalDelegate() as Decimal ...
    (microsoft.public.dotnet.languages.vb)
  • Re: DllImport, Callbacks and garbage collection
    ... you are passing a structure containing "Delegate" types ... You have to pass the Delegate "function" pointer, ... public static extern IntPtr strncpy; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: ARRRGGGHHHH Function Pointers!!!!
    ... RuntimeMethodHandle. ... when unmanaged code "calls back" into managed code ... (passing a delegate as arg), and adjusts the delegate callback method ... code passing a delegate to get a correctly adjusted method pointer back. ...
    (microsoft.public.dotnet.framework.interop)
  • Re: Loading dlls dynamically
    ... Hmmm, in .NET, a pointer to a function is delegate. ... > How do I load and run dll functions dynamically please? ... > internal static extern IntPtr GetProcAddress(IntPtr hModule, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Use of delegate
    ... The delegate part seems to be okay, youre just calling it from addressof, ... > declaration looks like below. ... > Dim objDelegate As RLISTSYS_FUNC ...
    (microsoft.public.dotnet.languages.vb)