【发布时间】:2011-01-24 06:34:46
【问题描述】:
我有一个包含本地 DLL 接口的模块;它看起来像这样:
// nvtt.dll binding module
module private NvTextureTools =
type NvttInputOptions = IntPtr
[<DllImport("nvtt", CallingConvention = CallingConvention.Cdecl)>]
extern NvttInputOptions nvttCreateInputOptions()
[<DllImport("nvtt", CallingConvention = CallingConvention.Cdecl)>]
extern void nvttDestroyInputOptions(NvttInputOptions)
[<DllImport("nvtt", CallingConvention = CallingConvention.Cdecl)>]
extern void nvttSetInputOptionsAlphaMode(NvttInputOptions, AlphaMode alphaMode)
[<DllImport("nvtt", CallingConvention = CallingConvention.Cdecl)>]
extern void nvttSetInputOptionsGamma(NvttInputOptions, float inputGamma, float outputGamma)
[<DllImport("nvtt", CallingConvention = CallingConvention.Cdecl)>]
extern void nvttSetInputOptionsWrapMode(NvttInputOptions, WrapMode mode)
(有 5 倍以上的功能,但这应该给出大致的概念)。
有没有办法只指定一次 DllImport 参数?据我了解,我不能从 DllImport 继承(它是密封的,无论如何我认为如果不是它就行不通),我不能使用反射来添加必要的属性,因为我需要它们编译时间。
我可以使用反射创建一个带有 P/Invoke 方法的全新类,但这会使调用它们变得很麻烦。
有什么想法吗?
【问题讨论】: