Jump to content

Calling Dll


jwurmz
 Share

Recommended Posts

I'm working with some old, flat database files that store information using the MBF specification (other thread). I've found a couple DLLs for converting MBF datatypes to their equivalent IEEE formats, but I've never used DllCaLL before so I'm not sure I'm doing it properly. @error is set to 1 everytime I try ;)

I'm using MBFIEE32.DLL, found here.

According to the documentation:

MBFIEE32.DLL
                          MBF <-> IEEE Conversion

                     Free Sample Functions from Stamina
                    Copyright 1997, MicroDexterity, Inc.

            Free distribution encouraged, include this TXT file.

                For information, visit http://www.mdxi.com 
                          email: stamina@mdxi.com
                          or call +1 313-453-5872

                          -----------------------
  This free DLL is supplied "AS IS" -- no warranty is offered or implied.
                          -----------------------

     MBFIEE32.DLL contains 4 functions to convert floating point values
between IEEE format and the older Microsoft Binary Format (MBF).  It's 
intended to replace the older free library MBF2IEEE.DLL, which only works
in 16-bit Windows.

     The functions are:

        DxToIEEEd - Converts MBF Doubles to IEEE Doubles
        DxToIEEEs - Converts MBF Singles to IEEE Singles
        DxToMBFd  - Converts IEEE Doubles to MBF Doubles
        DxToMBFs  - Converts IEEE Singles to MBF Singles

     These are identical to functions in Stamina, a library of more than
260 functions written in 32-bit assembly language.  We offer these for free
hoping it will prompt you to take a look at the other routines in Stamina.


                              Instructions

     Copy MBFIEE32.DLL to your Windows\System (or System32) directory.
Don't install it in an application directory.

     Because these functions are exposed through a typelib, you don't need
to use Declares or function prototypes.  Just add a reference to this
library to your project.

     How you do that depends on what product you're using -- for VB5, the
"Project... References" menu is where you begin.  From there, Browse the
System directory, select MBFIEE32.DLL, and you're done.  The library will
appear in your Object Browser, and the DLL will be entered in the registry.

     The conversions happen in-place... these directly affect the variable
passed to them, for best speed and convenience.  Just read an MBF value
into an IEEE double, and invoke DxToIEEEd.  The variable will be converted
directly to IEEE.

     In VB: 

        Get #n,, ADouble#    ' ADouble is MBF in the file
        DxToIEEEd ADouble#   ' now ADouble is in IEEE format

     Going the other way:

        DxToMBFs ASingle!    ' IEEE ASingle is converted to MBF
        Put #n,, ASingle!    ' Store in the file as MBF

     For fields in a User-Defined Type, just point these routines at the
element of interest:

        Type FileRecType
          LongElement As Long
          DoubleElement As Double
           ...
        End Type

        Dim FileRec as FileRecType

        Get #n,, FileRec
        DxToIEEEd FileRec.DoubleElement

...so if I wanted to convert an MBF double to its IEEE equivalent I thought the correct syntax for the call would be:

$myMBFdouble = StringMid($currentrecord, 23, 8) ;"0xD0CCCCCCCCCC1084"
$myIEEEdouble = DllCall("MBFIEE32.DLL", "double", "DxToIEEEd", "double", $myMBFdouble) ;I also tried "str", etc.

...but as I mentioned, @error = 1 every time. Any thoughts?

Link to comment
Share on other sites

...so if I wanted to convert an MBF double to its IEEE equivalent I thought the correct syntax for the call would be:

$myMBFdouble = StringMid($currentrecord, 23, 8) ;"0xD0CCCCCCCCCC1084"
$myIEEEdouble = DllCall("MBFIEE32.DLL", "double", "DxToIEEEd", "double", $myMBFdouble) ;I also tried "str", etc.

...but as I mentioned, @error = 1 every time. Any thoughts?

I can't test that here but I see two problems here:

1) $myMBFdouble is a String variant, which is not what you want. You should probably extract the 8-byte value as a binary variant.

2) the DxToIEEEd routine does not _return_ a double, since it operates in place (aka ByRef). The return type should be "none" or "none:cdecl" if its interface is C-style [i'm not sure which will work]

So try defining a DllStruct for a "byte[8]" value and load [DllStructSetData] your MBF value there. I guess that the type of the parameter in DllCall, "double" should work. After the DllCall, retrieve the converted value "in place" by reading back parameter 1. Beware that DllCall returns an array: read the help for that.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

I can't test that here but I see two problems here:

1) $myMBFdouble is a String variant, which is not what you want. You should probably extract the 8-byte value as a binary variant.

2) the DxToIEEEd routine does not _return_ a double, since it operates in place (aka ByRef). The return type should be "none" or "none:cdecl" if its interface is C-style [i'm not sure which will work]

So try defining a DllStruct for a "byte[8]" value and load [DllStructSetData] your MBF value there. I guess that the type of the parameter in DllCall, "double" should work. After the DllCall, retrieve the converted value "in place" by reading back parameter 1. Beware that DllCall returns an array: read the help for that.

That's not correct! The dll function expects a string as an argument so the second "double" should be "str" in the op's example. But anyway, "error 1" means that the dll cannot be used so it doesn't matter that the parameters are wrong. It might not be compiled for WIn32.

I think it would be easier to make your own conversion from the information supplied here.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

The dll function expects a string as an argument

That's not what the Dll doc says!

Anyway you're right pointing out that DllCall returning 1 denotes a problem with the dll.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

That's not what the Dll doc says!

Well the func is

float FAR PASCAL _export CVS(HLSTR hlstr)

and I think HLSTR is a string. Why do you think it's a double?
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

that is exactly what I needed -- a breakdown of the MBF double structure! Thank you!!!

That link says that the mantissa for IEEE is 55 bits. It says the mantisasa for MBF is 51 bits. Then it says the mantissa for IEEE is 3 bits fewer.

So I think 55 should be 54 because then it is 3 bits fewer and it makes the number fit 64 bits.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

The DLL modifes the data directly and does not return the new value. I made the functions for you:

Func _DxToIEEEd($nDoubleVal)
    ; Author: Prog@ndy
    Local $aResult = DllCall("MBFIEE32.DLL", "none", "DxToIEEEd", "double*", $nDoubleVal)
    If @error Then Return SetError(1,0,0)
    Return $aResult[1]
EndFunc
Func DxToIEEEs($nFloatVal)
    ; Author: Prog@ndy
    Local $aResult = DllCall("MBFIEE32.DLL", "none", "DxToIEEEs", "float*", $nDoubleVal)
    If @error Then Return SetError(1,0,0)
    Return $aResult[1]
EndFunc
Func _DxToMBFd($nDoubleVal)
    ; Author: Prog@ndy
    Local $aResult = DllCall("MBFIEE32.DLL", "none", "DxToMBFd", "double*", $nDoubleVal)
    If @error Then Return SetError(1,0,0)
    Return $aResult[1]
EndFunc
Func DxToMBFs($nFloatVal)
    ; Author: Prog@ndy
    Local $aResult = DllCall("MBFIEE32.DLL", "none", "DxToMBFs", "float*", $nDoubleVal)
    If @error Then Return SetError(1,0,0)
    Return $aResult[1]
EndFunc

Func _BinaryToFloat($bBinary)
    ; Author: Prog@ndy
    Switch BinaryLen($bBinary)
        Case 4
            Local $sStruct = DllStructCreate("byte[4]")
            DllStructSetData($sStruct, 1, $bBinary)
            Return DllStructGetData(DllStructCreate('float', DllStructGetPtr($sStruct)),1)
        Case 8
            Local $sStruct = DllStructCreate("byte[8]")
            DllStructSetData($sStruct, 1, $bBinary)
            Return DllStructGetData(DllStructCreate('double', DllStructGetPtr($sStruct)),1)
    EndSwitch
EndFunc

;-----------------------------------------------------------------------------------------------------------------------

$MBFDouble = _BinaryToFloat(Binary("0xD0CCCCCCCCCC1084"))

DllOpen(@ScriptDir &"\MBFIEE32.DLL")
MsgBox(0, '', _DxToIEEEd($MBFDouble))

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Well the func is

and I think HLSTR is a string. Why do you think it's a double?

:ahem: from what I can read, there's no string :

The conversions happen in-place... these directly affect the variable
passed to them, for best speed and convenience. Just read an MBF value
into an IEEE double, and invoke DxToIEEEd. The variable will be converted
directly to IEEE.

 In VB: 

 Get #n,, ADouble# ' ADouble is MBF in the file
 DxToIEEEd ADouble# ' now ADouble is in IEEE format

 Going the other way:

 DxToMBFs ASingle! ' IEEE ASingle is converted to MBF
 Put #n,, ASingle! ' Store in the file as MBF

 For fields in a User-Defined Type, just point these routines at the element of interest:

 Type FileRecType
 LongElement As Long
 DoubleElement As Double
 ...
 End Type

 Dim FileRec as FileRecType

 Get #n,, FileRec
 DxToIEEEd FileRec.DoubleElement

Just for curiosity, where do you get float "FAR PASCAL _export CVS(HLSTR hlstr)" from?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

that is exactly what I needed -- a breakdown of the MBF double structure! Thank you!!!

This is the page I was pointing to in my reply in the other thread ;)

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

This is the page I was pointing to in my reply in the other thread ;)

Yes, somehow I missed the entire section with the diagrams. I think it was because I was under the assumption that the float I was working with was only 32 bits. Anyhow, thanks for all your help in both threads :evil:

ProgAndy, I tried using your functions but no matter what value I feed into them, I get 0 returned. I don't suppose it's because I'm using Windows 7, is it?

EDIT: Yep, ran it on an XP machine and it worked great. Thank you!

Edited by jwurmz
Link to comment
Share on other sites

Just for curiosity, where do you get float "FAR PASCAL _export CVS(HLSTR hlstr)" from?

I got that from the source that comes with the dll download from msdn.

float FAR PASCAL _export CVS(HLSTR hlstr)
{
    float src, dst;
    
    src = *(float *)VBDerefHlstr(hlstr);
    
    if( _fmsbintoieee(&src, &dst) )
    VBRuntimeError(VB_OVERFLOW);
    else
    return dst;
}

The dll and source I downloaded from here, and on that page it says

CVS and CVD Functions

These functions accept a 4-byte (CVS) or 8-byte (CVD) string as an argument. They expect the bit pattern of this string to represent a single or double precision MBF value, respectively. The function returns an IEEE result.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I got that from the source that comes with the dll download from msdn.

OK I get it now. We were talking about something entirely different : the dll that the OP downloaded and tried to have working.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

OK I get it now. We were talking about something entirely different : the dll that the OP downloaded and tried to have working.

Oops, Sorry, I don't know how I managed to get the wrong dll, so ignore my ramblings.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

  • 7 months later...

Hi,

Come across this thread, I would like to ask does it work on 64bit environment? As I am working on an old apps. it is rquired working Double MBF and Double IEEE on WIN7 64BIT.

Anyone can guide me to solve this problem?

Regards,

Chiu

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...