c# 调用xxx.dll非托管代码
[DllImport("libvlc")]
private unsafe static extern void libvlc_media_player_set_hwnd(CoreHandle coreHandle, void* drawable);
错误 2 不安全代码只会在使用 /unsafe 编译的情况下出现
//设置父窗口
unsafe public void VedioSetParent(CoreHandle coreHandle, IntPtr hear)
{
libvlc_media_player_set_hwnd(coreHandle, (hear.ToPointer()));
}
错误 1 不安全代码只会在使用 /unsafe 编译的情况下出现
错误在于void* drawable 进行了强转 在xxx.dll里 接口为
/**
* Set a Win32/Win64 API window handle (HWND) where the media player should
* render its video output. If LibVLC was built without Win32/Win64 API output
* support, then this has no effects.
*
* \param p_mi the Media Player
* \param drawable windows handle of the drawable
*/
LIBVLC_API void libvlc_media_player_set_hwnd ( libvlc_media_player_t *p_mi, void *drawable );
怎么实现C#代码的修改啊...
------解决方案--------------------libvlc_media_player_t是一个结构体吧,你把它先贴出来。。。
------解决方案--------------------为什么用unsafe呢??
[DllImport("libvlc")]
public static extern void libvlc_media_player_set_hwnd(CoreHandle coreHandle, IntPtr drawable);
------解决方案--------------------正确做法:
C# code
[DllImport("libvlc")]
public static extern void libvlc_media_player_set_hwnd(ref libvlc_media_player_t p_mi, IntPtr drawable);
------解决方案--------------------
可以在定义前用unsafe标识:
unsafe class xx
{
[DllImport("libvlc")]
public static extern void libvlc_media_player_set_hwnd
...
}
编译设置中勾上 允许使用不安全代码.
------解决方案--------------------
CoreHandle,libvlc_media_player_t这两个都是自定义类型吧?
------解决方案--------------------
为什么非要非托管呢,
用托管代码,然后手动回收垃圾就行啊.