Nevermind, figured it out by using a IntPtr as a buffer then reading
the bytes to a UTF7 string

IntPtr str = Marshal.AllocCoTaskMem(2000*8);
                IntPtr strP = Marshal.AllocCoTaskMem(8);
                Marshal.StructureToPtr(str, strP, false);

                LoadHullKeysByPtr(ref sPath, ref buffer[0], ref strP);

                byte[] strBuff = new byte[2000*8];
                for (int i = 0; i < strBuff.Length; i++)
                    strBuff[i] = Marshal.ReadByte(strP, i);

                string s = ASCIIEncoding.UTF7.GetString(strBuff);

                Marshal.FreeCoTaskMem(str);
                Marshal.FreeCoTaskMem(strP);



On Jan 5, 1:11 am, Kozar <[email protected]> wrote:
> Here is my problem, and im sure there is a relativly simple answer for
> this...
>
> I need to know if there is a way in C# to make the return of the sKey
> string value untouched so i can have the entire string which would be
> like this for the first 2 items "s101\0\0\0\0s101\0\0\0\0" as for now
> the sKey value is getting stopped at the first \0 this is what I want
> to stop. (no i cannot recompile the dll to not have null terminating
> values)
>
> I was thinking of using a IntPtr then to read the string via
> Marshal.ReadByte but I do not know how to do that.
>
> If I try to use string s = new string(new char[len]); it still null
> terminates and results with just "s101".
>
> Anybody have any bright idea's?
>
> [DllImport("v4face2.dll", EntryPoint = "LOADHULLKEYS",
> CharSet=CharSet.Ansi)]
> public static extern void LoadHullKeys(
>     [MarshalAs(UnmanagedType.AnsiBStr)]ref string sPath,
>     ref int arrayPtr,
>     ref String sKey);
>
> String sPath = "directoryPath";
> int[] buffer = int[125];
> String sKey = string.empty;
> LoadHullKeys(ref sPath, ref int buffer[0], ref sKey)
>
> Thanks,
> R. Kozar

Reply via email to