• Welcome to Valhalla Legends Archive.
 

[VC++ and VB6] Bad DLL Calling Convention

Started by Joe[x86], November 25, 2005, 07:22 PM

Previous topic - Next topic

Yoni

Quote from: TheMinistered on November 26, 2005, 07:05 PM
Visual Basic uses BSTR for strings.  That is what  you should use as well.
N and O put together spell NO

MyndFyre

Quote from: TheMinistered on November 26, 2005, 07:05 PM
Visual Basic uses BSTR for strings.  That is what  you should use as well.
BSTR is a COM type, not a C type.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

UserLoser.

Blerf.cpp:

void __stdcall Bleh(int blah, char *boo)
{
    if(blah > 0)
        strcpy(boo, "bleh");
}


Blerf.def:

Bleh=Bleh


APIDeclares.bas:

Declare Sub Bleh Lib "Blerf.dll" (ByVal Blah As Long, ByVal Boo As Long)


CoolModule.bas:

Sub Meh()
    Dim Eh As String
    Eh = Space(256)
    Call Bleh(1, Eh)
End Sub


Bleh, you get the point

TehUser

Quote from: Joe on November 26, 2005, 02:52 PM
<snip>
   if (ret == "") {
      return product;
   } else {
      return ret;
   }


You're still trying to use == to compare strings.

Kp

Quote from: TehUser on November 27, 2005, 11:52 AM
Quote from: Joe on November 26, 2005, 02:52 PM
<snip>
   if (ret == "") {
      return product;
   } else {
      return ret;
   }


You're still trying to use == to compare strings.

Yes, but unless his compiler is totally braindead, it's ok in this case.  ret was initialized to point at an empty string, and now he's comparing to see whether it points at an empty string.  If the compiler is pooling strings (and it really should!), then the two will have the same address and it'll be OK.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Joe[x86]

Quote from: TehUser on November 27, 2005, 11:52 AM
Quote from: Joe on November 26, 2005, 02:52 PM
<snip>
   if (ret == "") {
      return product;
   } else {
      return ret;
   }


You're still trying to use == to compare strings.

Oops..

Quote from: Kp on November 27, 2005, 12:10 PM
Quote from: TehUser on November 27, 2005, 11:52 AM
Quote from: Joe on November 26, 2005, 02:52 PM
[...]
You're still trying to use == to compare strings.
[...]unless his compiler is totally braindead [...]

Lets asume VC++ is braindead. =p
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

TheMinistered

#21
I was assuming he was using an MFC DLL considering he is just now figuring out how to do it... thus...

Quote
If we want to pass strings to a DLL as input or to get strings from a DLL as output and we want to do this in the most general way, we are told from Microsoft to use the BSTR type.

The only reason char* works in this case is because it's being passed as ANSI.  However, if microsoft encourages the use of BSTR in this case then why not?

Quote
Again from the MSDN documentation (in a remote part of it, to be honest !), we read what follows:

1.  Visual Basic always creates a new BSTR containing ANSI characters (not UNICODE ones!) when passing a string to a DLL
2.  Visual Basic always gets a BSTR containing UNICODE characters when getting a string from a DLL
http://www.codeproject.com/dll/BSTR_CString_conversion.asp

Joe[x86]

Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.