से संरचनाओं की एक सरणी प्राप्त करें मेरे पास एक सी # .NET 2.0 सीएफ प्रोजेक्ट है जहां मुझे देशी सी ++ डीएलएल में एक विधि का आह्वान करने की आवश्यकता है। यह मूल विधि TableEntry
प्रकार की एक सरणी देता है। उस समय मूल विधि को बुलाया जाता है, मुझे नहीं पता कि सरणी कितनी बड़ी होगी।देशी डीएल से सी # अनुप्रयोग
मैं देशी डीएलएल से सी # परियोजना में तालिका कैसे प्राप्त कर सकता हूं? नीचे प्रभावी रूप से मेरे पास क्या है।
// in C# .NET 2.0 CF project
[StructLayout(LayoutKind.Sequential)]
public struct TableEntry
{
[MarshalAs(UnmanagedType.LPWStr)] public string description;
public int item;
public int another_item;
public IntPtr some_data;
}
[DllImport("MyDll.dll",
CallingConvention = CallingConvention.Winapi,
CharSet = CharSet.Auto)]
public static extern bool GetTable(ref TableEntry[] table);
SomeFunction()
{
TableEntry[] table = null;
bool success = GetTable(ref table);
// at this point, the table is empty
}
// In Native C++ DLL
std::vector<TABLE_ENTRY> global_dll_table;
extern "C" __declspec(dllexport) bool GetTable(TABLE_ENTRY* table)
{
table = &global_dll_table.front();
return true;
}
धन्यवाद, PaulH
कि TABLE_ENTRY ** हो नहीं करना चाहिए, जब से तुम एक सूचक लिखना चाहते हैं? – OregonGhost
@OregonGost - आप सही हैं, यह होना चाहिए। – PaulH