-1

正しい引数を正しく渡すことができないようです。私は得る

「無効な名前解析バッファ サイズ」エラー

dname.h の Lotus Notes 関数

STATUS LNPUBLIC DNParse(
DWORD  Flags,
const char far *TemplateName,
const char far *InName,
DN_COMPONENTS far *Comp,
WORD  CompSize);

下の構造

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct DN_COMPONENTS
{   
         public int Flags;
         [MarshalAs(UnmanagedType.LPWStr)]
         public string C;
         public short OLength;
         [MarshalAs(UnmanagedType.LPWStr)]
         public string O;
         [MarshalAs(UnmanagedType.LPWStr)]
         public string CN;
};

c#

以下は私が試したことです

Status sts = 0;
StringBuilder szServer = new StringBuilder(names.MAXUSERNAME);
string notUsedString = null;
DWORD notUsed = 0;
dname.DN_COMPONENTS xdDC = new DN_COMPONENTS();
sts = nnotesDLL.SECKFMGetUserName(szServer);            
//IntPtr structPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(dname.DN_COMPONENTS)));
//UInt16 num = Convert.ToUInt16(Marshal.SizeOf(structPtr));
//WORD num = Convert.ToUInt16(Marshal.SizeOf(structPtr));
int num = Marshal.SizeOf(typeof(DN_COMPONENTS));            
IntPtr structPtr = Marshal.AllocCoTaskMem(num);



sts = nnotesDLL.DNParse(notUsed, notUsedString, szServer, structPtr, (UInt32)num);
this.xdDC = (dname.DN_COMPONENTS)Marshal.PtrToStructure(structPtr, typeof(dname.DN_COMPONENTS));
xdDC.CN = Decode(Marshal.ReadIntPtr(structPtr), ushort.MaxValue);

///CN=SomeFirstName SomeLastName/OU=Corp/O=test

「SomeFirstName SomeLastName」を探しています

[DllImport("nnotes.DLL", CallingConvention = CallingConvention.StdCall)]
 public unsafe static extern Status DNParse(DWORD notUsed, string notUsedString,     StringBuilder     InName, IntPtr structPtr, UInt32 structPtrSizeOf);

すべてのバリエーションを ref から struct へ、ref から struct へ、string へ、int へ、uint へと変更してみました。

ヘルプ...

私が探しているのは CN=SomeFirstName SomeLastName/OU=Corp/O=test です

4

1 に答える 1