I have a native C++ function that I call from a C# project using pinvoke.
extern \"C\" _declspec(dllexport) void GetCmdKeyword( wchar_t** cmdKeyword, uint pCmd
You cannot infer the length from the pointer. The information must be passed as a separate value alongside the pointer to the array.
I wonder why you use raw IntPtr
rather than C# arrays. I think the answer you accepted to your earlier question has the code that you need: Pinvoking a native function with array arguments.
OK, looking at the edit to the question, the actual scenario is a little different. The function returns a pointer to a null-terminated array of wide characters. Your pinvoke should be:
[DllImport(...)]
static extern void GetCmdKeyword(out IntPtr cmdKeyword, uint pCmdNum);
Call it like this:
IntPtr ptr;
GetCmdKeyword(ptr, cmdNum);
string cmdKeyword = Marshal.PtrToStringUni(ptr);