Solved

Bad DLL calling convention

Posted on 2002-04-12
9
137 Views
Last Modified: 2010-05-02
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
Comment
Question by:iskitua
  • 5
  • 4
9 Comments
 
LVL 18

Expert Comment

by:mdougan
ID: 6937196
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
 
LVL 18

Expert Comment

by:mdougan
ID: 6937202
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
 
LVL 18

Expert Comment

by:mdougan
ID: 6937212
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
 

Author Comment

by:iskitua
ID: 6937410
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 18

Expert Comment

by:mdougan
ID: 6937691
What is the DLL written in?  Is it an Active-X control in VB or a C or C++ DLL?
0
 

Author Comment

by:iskitua
ID: 6937729
It's a C++ DLL
Better yet... I'm using VB4!
0
 

Author Comment

by:iskitua
ID: 6937761
It's a C++ DLL
Better yet... I'm using VB4!
0
 
LVL 18

Accepted Solution

by:
mdougan earned 200 total points
ID: 6937924
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
 

Author Comment

by:iskitua
ID: 6947731
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now