Unicode String Parameters in DLL's



We are converting our application to work with Unicode. The Word macro in
our application "communicates" with our main application via a C DLL. This
DLL includes several functions which return Unicode strings back to the
macro as input parameters. My question is, what is the correct declaration
for the DLL functions in VBA?

I currently have it working like this:

Private Declare Function GetUserName Lib "MyDLL.dll" (ByVal lpUser As Long)
As Integer

GetUserName simply copies the user name into a Unicode string.

I call this function from VBA code with something like this:

Dim sUser as String
sUser = String(255, Asc(" "))

GetUserName StrPtr(sUser)

This seems to work, but I've only tested it with standard characters (i.e.
nothing outside of the normal Latin character set). I'm concerned about
VBA's automatic converting to ANSI, although I don't really understand what
that means... Does it mean that VBA will convert the sUser string to ANSI
when I try to access it, and so any characters outside of the ANSI set will
be converted to question marks or something like that?

Any help you can give me on this would be greatly appreciated.


.



Relevant Pages

  • Re: Call C DLL from VB.net-problem..array gains 4 bytes!
    ... No, Unicode strings don't, by definition, have a header with the size. ... you're writing code in C++, for example, the only difference between an ANSI ... which take an array of bytes. ... > Remember the DLL declaration... ...
    (microsoft.public.windowsce.app.development)
  • Re: passing a string to a dll
    ... bool DLLRect::PullWhisker ... The interface for the DLL exported function could be like so: ... based on _UNICODE flag, e.g. ... I think that in these days those ANSI strings are something from the ...
    (microsoft.public.vc.mfc)
  • Re: Populating CString in Win32 dll interface that accepts LPCTSTR
    ... ReleaseBuffer() if I actually modify the buffer after GetBuffer is called ... But the OP wanted the string to be "populated" by the DLL. ... Unicode or ANSI string, but the DLL might think it is a non-const pointer to an ANSI ...
    (microsoft.public.vc.mfc)
  • Re: Convert DOS Cyrillic text to Unicode
    ... > I would expect Notepad will have Windows Cyrillic or Unicode or think it ... > Strings in .NET are always Unicode! ... > read this stream validly converting it to Unicode. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: D6 and COM
    ... descriptions of the IDL, right? ... Dolphin discovered in the DLL are not? ... Unicode strings. ...
    (comp.lang.smalltalk.dolphin)