Solved

Bad DLL calling convention

Posted on 2002-04-12
9
135 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Window placement 17 65
Need VBS version of Excel date conversion 4 53
using Access 8 53
Modifying Conditional Format from VBA code 3 33
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

746 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

14 Experts available now in Live!

Get 1:1 Help Now