Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2005

Tip: Looking for answers? Try searching our database.

Unicode String Parameters in DLL's

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Unknown - 30 Mar 2005 19:14 GMT
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.
Tom Winter - 31 Mar 2005 15:41 GMT
You've probably heard something wrong about "VBA's automatic converting to
ANSI". Strings in VB6 and VBA are Unicode. (The forms package in VB6 it NOT
Unicode, so you might have heard some stuff about that. VBA's forms package
is Unicode.) I do this exact same kind of thing when calling Windows Unicode
APIs. VB/VBA will see the Unicode characters put in your "buffer" by your
DLL just fine. It doesn't so any kind of conversion before or after the DLL
call.

One thing to watch out for is if your DLL routine puts a zero byte at the
end of the string. To VBA, a zero byte is just another character in the
string (Chr$(0)); it does not terminate the string. You'll need a routine to
scan where the zero byte is and then only take the text before that zero
byte. I can give you a function for that if you need.

Signature

Tom Winter
tom@nospam.amosfivesix.com

> We are converting our application to work with Unicode.  The Word macro in
> our application "communicates" with our main application via a C DLL.
[quoted text clipped - 24 lines]
>
> Any help you can give me on this would be greatly appreciated.
Unknown - 31 Mar 2005 17:57 GMT
Cool.  Thanks Tom.  I have a routine that grabs the text before the trailing
zero.

Thanks again.

> You've probably heard something wrong about "VBA's automatic converting to
> ANSI". Strings in VB6 and VBA are Unicode. (The forms package in VB6 it
[quoted text clipped - 39 lines]
>>
>> Any help you can give me on this would be greatly appreciated.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.