Mattias Sjögren
2004-04-29 16:04:10 UTC
void __stdcall GetLogin(BSTR appname, BSTR caption, BSTR* username, BSTR* password, bool reshow)
//copy return values to byref parameters passed in
LPCSTR luser = retuser.operator LPCTSTR();
LPCSTR lpass = retpass.operator LPCTSTR();
*username = SysAllocStringByteLen(luser, retuser.GetLength());
*password = SysAllocStringByteLen(lpass, retpass.GetLength());
(retuser and repass are CStrings)
What are my options if I want to use this from C#? I tried it using
[MarshalAs(UnmanagedType.Bstr)] StringBuilder username
Did you try with UnmanagedType.AnsiBStr instead? That should be the//copy return values to byref parameters passed in
LPCSTR luser = retuser.operator LPCTSTR();
LPCSTR lpass = retpass.operator LPCTSTR();
*username = SysAllocStringByteLen(luser, retuser.GetLength());
*password = SysAllocStringByteLen(lpass, retpass.GetLength());
(retuser and repass are CStrings)
What are my options if I want to use this from C#? I tried it using
[MarshalAs(UnmanagedType.Bstr)] StringBuilder username
appropriate one since you're allocating the BSTR with
SysAllocStringByteLen. I'd try
[DllImport("...")]
static extern void GetLogin(
[MarshalAs(UnmanagedType.AnsiBStr)] string appname,
[MarshalAs(UnmanagedType.AnsiBStr)] string caption,
[MarshalAs(UnmanagedType.AnsiBStr)] out string username,
[MarshalAs(UnmanagedType.AnsiBStr)] out string password,
[MarshalAs(UnmanagedType.I1)] bool reshow );
Mattias
--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.