Solved

Bad DLL calling convention

Posted on 2002-04-12
9
149 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

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

Industry Leaders: 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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month2 days, 18 hours left to enroll

622 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