Passing Single Data types to DLL's 
Author Message
 Passing Single Data types to DLL's

I can pass Integer Data types, one-at-a-time and as an array, without
problem. Thanks for that help people. Now, I'd like to pass a Single Data
type to a DLL but keep getting the dreaded " Bad DLL Calling Convention".
What am I doing wrong? I've declared function as:

Declare Function rMin Lib "rMathLib.DLL" (ByVal X1 As Single, ByVal X2 As
Single) As Single

and I use it as:

rMinTemp = rMin(rMinTemp, rTemp).

As you can see, I initialize rMinTemp (Yes, I really do) to some value,
grab a number to compare the first with, ship them over to rMin and expect
one of the values to come back. (Yes, this is only an exercise.) The very
same method works for Integer Data types. Again, any ideas.

Thanks in advance.



Mon, 02 Feb 1998 03:00:00 GMT  
 Passing Single Data types to DLL's

Quote:

>I can pass Integer Data types, one-at-a-time and as an array, without
>problem. Thanks for that help people. Now, I'd like to pass a Single Data
>type to a DLL but keep getting the dreaded " Bad DLL Calling Convention".
>What am I doing wrong? I've declared function as:

>Declare Function rMin Lib "rMathLib.DLL" (ByVal X1 As Single, ByVal X2 As
>Single) As Single

>and I use it as:

>rMinTemp = rMin(rMinTemp, rTemp).

>As you can see, I initialize rMinTemp (Yes, I really do) to some value,
>grab a number to compare the first with, ship them over to rMin and expect
>one of the values to come back. (Yes, this is only an exercise.)

        Is this your own dll or one that you got somewhere? Usually what
you do with real types is not try to pass them by value or return real values -
typically you'd pass them by reference and also pass a dummy variable by reference
for the dll to fill in with the result. You set up your dll to expect pointers
to singles (or maybe that's the default, I don't know exactly where you are), and
then you'd

Declare Function rMin Lib "rMathLib.DLL" (X1 As Single, X2 As Single,
        Ans As Single) as Integer
, you dim X1, X2, and ans as Single, say

X1=2
X2=3
hmm=rMin(X1,X2,ans)

and if you got it right you'd end up with ans=2. (The returned value could be
an error code...)

--
David Ullrich
Don't you guys find it tedious typing the same thing
after your signature each time you post something?
I know I do, but when in Rome...



Mon, 02 Feb 1998 03:00:00 GMT  
 Passing Single Data types to DLL's

Quote:

> I can pass Integer Data types, one-at-a-time and as an array, without
> problem. Thanks for that help people. Now, I'd like to pass a Single Data
> type to a DLL but keep getting the dreaded " Bad DLL Calling Convention".
> What am I doing wrong? I've declared function as:

> Declare Function rMin Lib "rMathLib.DLL" (ByVal X1 As Single, ByVal X2 As
> Single) As Single

> and I use it as:

> rMinTemp = rMin(rMinTemp, rTemp).

> As you can see, I initialize rMinTemp (Yes, I really do) to some value,
> grab a number to compare the first with, ship them over to rMin and expect
> one of the values to come back. (Yes, this is only an exercise.) The very
> same method works for Integer Data types. Again, any ideas.

> Thanks in advance.

Did you _explicitly_ declared your 'rMinTemp' and 'rTemP' as 'single' ?
('single' is 4 bytes whereas 'integer' is only 2 bytes, so if you forget to
declare the right type, VB will assume type 'integer' thus resulting in an
error.) This might be the reason why it works with integers but not with
singles.

-- Hartmut
________________________________________________________________

Hartmut Dieterich       Tel: 089-636-42687
ZFE T SN 5              Fax: 089-636-49802

81730 Muenchen
________________________________________________________________



Fri, 06 Feb 1998 03:00:00 GMT  
 Passing Single Data types to DLL's


Quote:

> > I can pass Integer Data types, one-at-a-time and as an array, without
> > problem. Thanks for that help people. Now, I'd like to pass a Single Data
> > type to a DLL but keep getting the dreaded " Bad DLL Calling Convention".
> > What am I doing wrong? I've declared function as:

> > Declare Function rMin Lib "rMathLib.DLL" (ByVal X1 As Single, ByVal X2 As
> > Single) As Single

> > and I use it as:

> > rMinTemp = rMin(rMinTemp, rTemp).

> > As you can see, I initialize rMinTemp (Yes, I really do) to some value,
> > grab a number to compare the first with, ship them over to rMin and expect
> > one of the values to come back. (Yes, this is only an exercise.) The very
> > same method works for Integer Data types. Again, any ideas.

> > Thanks in advance.

> Did you _explicitly_ declared your 'rMinTemp' and 'rTemP' as 'single' ?

It is declared in the Declare Function ...  That's why we do it.  This problem
would only arise if the params were declares 'As Any'.  VB converts to the
param type specified in the Function declaration.

At least, it should do.

--
I've got more important things to do than a {*filter*}y .sig file, alright?!

Tom Wheeley



Sat, 07 Feb 1998 03:00:00 GMT  
 Passing Single Data types to DLL's

says...

Quote:


>> Now, I'd like to pass a Single Data
>> type to a DLL but keep getting the dreaded " Bad DLL Calling Convention".
>> What am I doing wrong? I've declared function as:

>> Declare Function rMin Lib "rMathLib.DLL" (ByVal X1 As Single, ByVal X2 As
>> Single) As Single

>> and I use it as:

>> rMinTemp = rMin(rMinTemp, rTemp).
>> As you can see, I initialize rMinTemp (Yes, I really do) to some value,
>> grab a number to compare the first with, ship them over to rMin and expect
>> one of the values to come back. (Yes, this is only an exercise.) The very
>> same method works for Integer Data types. Again, any ideas.
>Did you _explicitly_ declared your 'rMinTemp' and 'rTemP' as 'single' ?
>('single' is 4 bytes whereas 'integer' is only 2 bytes, so if you forget to
>declare the right type, VB will assume type 'integer' thus resulting in an
>error.)

If the parameters are passed "ByVal ... as Single" there should be no need to
make them the correct type as an expression is no less valid.

Something to watch out for is that Borland (C++ V3.1 anyway) and the rest of
the world (MS) don't agree on how to return reals (Singles or Doubles) so VB
(MS) can't (won't) cope with it, so you would need to pass the result back in
anouher parameter passed by reference (no byval) and this _would_ have to be
of the correct type.

This may be nothing to do with your problem, of course!



Sat, 07 Feb 1998 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Passing structures/user defined types to DLL's

2. passing arrays of user defined types to dll's

3. Passing of C language's union data type in VB application

4. passing a data type to a DLL??

5. problem of converting C's union type to VB's a data type

6. problem of converting C's union type to VB's a data type

7. Passing user data type to function causes type mismatch error

8. Data Type Usage: Single vs Currency vs Decimal

9. Round Single Data Type to 2 decimal places

10. Variable with Single Data Type rounded to 2 decimal places

11. Crystal and Single data types

12. Single data type BUG ???

 

 
Powered by phpBB® Forum Software