• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 151
  • Last Modified:

Bad DLL calling convention

Converting to windows 2000... works in 95

Declare Function SendD Lib "MyDll" (AnyStructure as Any, ByVal iCode as Integer, ByVal ICount as Integer) as Long

I think it might be the structure being passed?
Public Type MyType
   sTypeOne as String * 15
   STypeTwo as String * 15
   STypeThree as String * 15
   STypeFour as String * 15
End Type

the Dll is looking for a Pointer, Ushort, Ushort

0
iskitua
Asked:
iskitua
  • 5
  • 4
1 Solution
 
mdouganCommented:
You could try this:

Dim x as mytype
Dim lPtr as long

x.stype1 = "Hello"
....

lPtr = VarPtr(x)

RC = MyAPI(lPtr.....)

Do you need to pass the structure by reference?  If not, it could be choking on that.  If you don't need to pass by reference, then add a ByVal in front of the AnyStructure parameter.
0
 
mdouganCommented:
Oh, one more thing, I don't know of any APIs, from Win95 on that actually take an Integer (2 byte data type).  I think that all parameters that were formerly integers under 16 bit OS were converted to Longs.  Try changing your As Integer parameters to As Long (if nothing else has worked)
0
 
mdouganCommented:
One other thought.  Even though you are defining the type with fixed length strings, you might need to actually initialize them, so try this:

Dim x as mytype

' put 15 binary zeros into each string
x.stype1 = String(15,0)
x.stype2 = String(15,0)
x.stype3 = String(15,0)
x.stype4 = String(15,0)

....

RC = MyAPI(x.....)

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
iskituaAuthor Commented:
Yep you thought of the same things I did.  Tried the ByVal and Longs.  It works If I compile and run the exe, but I can't step through the code, which I need to do to solve another unrelated problem!
0
 
mdouganCommented:
What is the DLL written in?  Is it an Active-X control in VB or a C or C++ DLL?
0
 
iskituaAuthor Commented:
It's a C++ DLL
Better yet... I'm using VB4!
0
 
iskituaAuthor Commented:
It's a C++ DLL
Better yet... I'm using VB4!
0
 
mdouganCommented:
VB4?  16 or 32 bit?  That could be the problem.  What about the C++ DLL.  Was it compiled under 16 bit or 32 bit architecture?  Could be that you're using a 16 bit VB program calling a 32 bit DLL and that alone might not work on Windows 2K because I think that Windows 2K doesn't do the same kind of "thunking" that was possible under Windows 95.

I'd suggest switching to VB 5 or 6, and making sure that your C++ DLL has been compiled on a 32 bit platform.  Then, if the C++ DLL references int data types, then in VB you will need to use Longs for those parameters.

When recompiling the C++ DLL, you'll have to make sure that the functions you are exporting are defined with the _stdcall calling convention.  VB uses the "pascal calling convention" and that is not what the default is for C or C++ programs.  Also, for a C++ program, you have to make sure that the function is declared as Extern C, because C++ mangles the actual name of the function at compile time to include references to the data types of the parameters - to allow for overloading.
0
 
iskituaAuthor Commented:
after all that it was something that you would think would have been there all the time; stdcall calling convention, but why it worked under 95... oh well.
thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now