Including a DLL in an XML Web Service

cackle

Newcomer
Joined
Jun 17, 2003
Messages
3
Hello everyone. Thanks in advance for your advice.

I'm building a web service that needs to access a DLL that was written in C++. I saw somewhere that the way to access a specific function from a DLL is to declare it thusly:

Code:
Public Declare Function GetResultsTextBSTR Lib "BridgerTracker.dll"
(ByVal iFormat As enumBridgerTrackerFormat) As String

This seems to work in terms of allowing the program to recognize the function. However, when I call this function (or any other function from the DLL that returns a string), I'm only getting the first character of what should be returned.

For example, if the function is supposed to return "Numer of Matches: 90" it returns "N" instead. I have a feeling this has to do with two thngs -- that the DLL was written with VB 6.0 in mind and also it was written in C++, so I have to do some sort of conversion. Functions that return an integer are also not returning the right number by a factor of 4 billion.

The example code that was given to me actually does do a conversion, but it is a conversion that was deprecated from VB 6.0 to VB.NET. I found the way to do it in VB.NET and it still doesn't work.

Just for reference, here's what I changed for that conversion:

Code:
StrConv(GetLastErrorMessageBSTR(), vbFromUnicode)

goes to:

Code:
Dim s As String
Dim b() As Byte

b = System.Text.UnicodeEncoding.Unicode.GetBytes(GetLastErrorMessageBSTR())
s = System.Text.ASCIIEncoding.ASCII.GetString(b)

Does anyone have an idea of what I can do?

I'm using ASP.NET Web Matrix to program this Web Service.

Thanks.
 
Functions that return an integer are also not returning the right number by a factor of 4 billion.

I'm not a C++ expert, so I don't know what's wrong with the
strings. However, it is worth pointing out that an Integer variable
in VB6 is 16-bit, whereas an Integer in VB.NET (and the whole
.NET framework) is 32-bit (the Int32 object). Make sure that the
number you're returning in the DLL is the same size as the
variable you're setting it to, as this could be causing the number
problem.
 
The int thing is right.

Here's how I fixed the strings (with help from my co-worker):

Code:
Public Declare Function GetResultsTextBSTR Lib "BridgerTracker.dll"
(ByVal iFormat As enumBridgerTrackerFormat) As <MarshalAs(UnmanagedType.BSTR)> String

The string was being returned as a Binary string by the DLL and I hadn't told VB.NET that was the case.
 
Back
Top