there is such a structure

struct VkExtensionProperties { char extensionName[VK_MAX_EXTENSION_NAME_SIZE]; uint32_t specVersion; } 

and the method in which it is used

VkResult vkEnumerateInstanceExtensionProperties(const char* pLayerName, uint32_t* pPropertyCount, VkExtensionProperties* pProperties)

in c # wrote so

 public unsafe struct VkExtensionProperties { public fixed char extensionName[(int)vk.VK_MAX_EXTENSION_NAME_SIZE]; public uint specVersion; } VkResult vkEnumerateInstanceExtensionProperties([MarshalAs(UnmanagedType.LPWStr)] string pLayerName, ref uint pPropertyCount,[Out] [MarshalAs(UnmanagedType.LPArray)] VkExtensionProperties[] vkExtensionProperties); 

but the structures are empty. How to import structure and method correctly?

  • What does import mean? Use in with #? - MrBin

2 answers 2

char in C # does not mean that in C ++. Instead of an array of char in this case, you need to use string and ByValTStr.

 [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)] public struct VkExtensionProperties { [MarshalAs(UnmanagedType.ByValTStr, SizeConst=(int)vk.VK_MAX_EXTENSION_NAME_SIZE)] public string extensionName; public uint specVersion; } 

    You can add an operator to the structure

     VkExtensionProperties* operator ()(const char* p, uint32_t k) { if (p) strcpy(extensionName, p); specVersion = k; return this; } 

    and then you can pass to your function like this:

     const char* name = "pLayerName"; uint32_t k{5}; VkExtensionProperties v; vkEnumerateInstanceExtensionProperties(name, &k, v(name, k)); 

    the fields of the object v will be initialized by the first and second argument