我目前正在开发一个.NET Framework 4.7.2应用程序。我需要使用来自非托管C++库的逻辑。我不能使用C++/CLI(托管C++)。
我试图找出如何将C#字典转换为非托管C++:
Dictionary<string, float> myData
您知道在非托管的C++中,Dictionary<string, float>
的正确等效是什么吗?
谢谢!
我目前正在开发一个.NET Framework 4.7.2应用程序。我需要使用来自非托管C++库的逻辑。我不能使用C++/CLI(托管C++)。
我试图找出如何将C#字典转换为非托管C++:
Dictionary<string, float> myData
您知道在非托管的C++中,Dictionary<string, float>
的正确等效是什么吗?
谢谢!
// C# side: wrap your Dictionary<string, float> into a class implementing this interface.
// lock() in the implementation if C++ retains the interface and calls it from other threads.
[Guid( "..." ), InterfaceType( ComInterfaceType.InterfaceIsIUnknown )]
interface iMyDictionary
{
void getValue( string key, out float value );
void setValue( string key, float value );
}
[DllImport("my.dll")]
extern static void useMyDictionary( iMyDictionary dict );
// C++ side of the interop.
__interface __declspec( uuid( "..." ) ) iMyDictionary: public IUnknown
{
HRESULT __stdcall getValue( const wchar_t *key, float& value );
HRESULT __stdcall setValue( const wchar_t *key, float value );
};
extern "C" __declspec( dllexport ) HRESULT __stdcall useMyDictionary( iMyDictionary* dict );