PInvoke and nnotes.dll

Hi all,

I am writing an addin using a C++ bridge dll calling out to a managed C# dll. Using late binding I am able to get hold of the current notes session etc, but my problems start when I try and make calls to functions in the nnotes.dll.

I am using PInvoke to call out to the function OSPathNetConstruct. My declaration is as follows:

[DllImport(“nnotes.dll”, EntryPoint = “OSPathNetConstruct”)]

    public static extern UInt16 OSPathNetConstruct(Int64 PortName, String ServerName, String FileName, ref StringBuilder retPathName);

I then call it as follows:

StringBuilder mySB = new StringBuilder(1024);

OSPathNetConstruct(0, ServerName, FileName, ref mySB);

The code executes without error but my StringBuilder is always empty.

I tried replacing ref StringBuilder with an IntPtr in the declaration, and used it in the following way:

IntPtr ptr = Marshal.AllocCoTaskMem(1024);

OSPathNetConstruct(0, ServerName, FileName, ptr);

string s = Marshal.PtrToStringAuto(ptr);

This just returns a jumble of characters that make no sense what so ever.

Any help would be greatly appreciated.