我似乎无法正确传递正确的论点。我明白了
“无效名称解析缓冲区大小”错误
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 to all、ref to struct、更改为 string、int、uint 什么都没有!!!
帮助...
我正在寻找的是 CN=SomeFirstName SomeLastName/OU=Corp/O=test