-1
Вот кусок кода:Делегаты и нативные методы
private static bool CreateDelegates()
{
IntPtr ptr;
//--- SoundTouch: createInstance
ptr = Kernel32Methods.GetProcAddress (libHandle, "[email protected]");
if (ptr != IntPtr.Zero)
{
createInstance = (st_createInstance) Marshal.GetDelegateForFunctionPointer
(ptr, typeof (st_createInstance));
}
//--- SoundTouch: destroyInstance
ptr = Kernel32Methods.GetProcAddress (libHandle, "[email protected]");
if (ptr != IntPtr.Zero)
{
destroyInstance = (st_destroyInstance) Marshal.GetDelegateForFunctionPointer
(ptr, typeof (st_destroyInstance));
}
}
И есть еще много assigments как выше в этом методе. Я хочу создать такой метод, как AssignProc (...), чтобы уменьшить количество кода.
void AssignProc (string procName, Delegate d, Type???)
{
IntPtr ptr;
ptr = Kernel32Methods.GetProcAddress (libHandle, procName);
if (ptr != IntPtr.Zero)
{
d = (Type???) Marshal.GetDelegateForFunctionPointer
(ptr, typeof (???));
}
}
Где:
private static st_createInstance createInstance;
[UnmanagedFunctionPointer (CallingConvention.StdCall)]
private delegate IntPtr st_createInstance();
Помощь :)
ошибка: Не удается CONVER делегат Т. – zgnilec
@zgnilec: Пожалуйста, смотрите обновленный код и объяснение. –
Невозможно скомпилировать, где находится «return (T) Marshal ...». – zgnilec