Solved

Bad DLL calling convention

Posted on 2002-04-12
9
147 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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!

 

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
 
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

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!

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

734 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