i declare / define delegate , callback function inside of calling method. possible ? if yes how ? code want execute my first implant operation on:
delegate bool mydelegate(intptr module, string type, intptr lparam); public static bool enumrestypeproc(intptr module, string typename, intptr lparam) { (((gchandle) lparam).target list<string>).add(typename); return true; } public static string[] getresourcetypes(intptr module) { list<string> result = new list<string>(); gchandle pin = gchandle.alloc(result); winapi.enumresourcetypes(module, marshal.getfunctionpointerfordelegate(new mydelegate(enumrestypeproc)), (intptr)pin); pin.free(); return result.toarray(); }
closest get:
delegate bool mydelegate(intptr module, string type, intptr lparam); public static string[] getresourcetypes(intptr module) { list<string> result = new list<string>(); gchandle pin = gchandle.alloc(result); mydelegate d = delegate(intptr handle, string typename, intptr lparam) { (((gchandle) lparam).target list<string>).add(typename); return true; }; winapi.enumresourcetypes(module, marshal.getfunctionpointerfordelegate(d), (intptr) pin); pin.free(); return result.toarray(); }
declaring delegate inside method not possible @ point. if compiled causes unmanaged code crash application.
yes, can use anonymous method or lambda expression.
// untested func<intptr, string, intptr, bool> inline = (module, typename, lparam) => { (((gchandle)lparam).target list<string>).add(typename); return true; }; winapi.enumresourcetypes(module, marshal.getfunctionpointerfordelegate(inline), (intptr)pin);
Comments
Post a Comment