Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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:

 

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:

 

StrConv(GetLastErrorMessageBSTR(), vbFromUnicode)

 

goes to:

 

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.

  • *Experts*
Posted
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.

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted

The int thing is right.

 

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

 

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...