1

I'm in the process of migrating data from a Microsoft Access database into one in SQL Server 2008. The data contains a not insubstantial number of errors that had never been dealt with properly. As part of sanitizing the data I'm attempting to import a DLL I wrote using Visual Studio 2017 to perform some tasks that VBA isn't very good at. Unfortunately it's giving me an error when I try to use it, saying "Can't find DLL entry point DoubleIsSpecialValue in C:\Projects\VSR\Library\float.dll" (Run-time error '453').

I created the DLL with Visual C++ in Visual Studio 2017 as a Win32 library, although with the functionality it uses it could just as well have been compiled in C. I made no changes to the default "dllmain.cpp" file it generated, which contains the DllMain() entry function. The function in question was declared in "stdafx.h" as

#define FLOATLIBRARY_API __declspec(dllexport)

FLOATLIBRARY_API bool DoubleIsSpecialValue(double value);

and implemented in "float.cpp" as

FLOATLIBRARY_API bool DoubleIsSpecialValue(double value) {
    return isnan(value) || isinf(value) || ((value == 0.0) && (copysign(1.0, value) == -1.00));
}

all of which appears to be the correct standard usage, as far as I can tell.

I imported the function into VBA as

Public Declare Function DoubleIsSpecialValue _
       Lib "C:\Projects\VSR\Library\float.dll" _
       (ByVal value As Double) As Boolean

I've tried a number of different variations in trying to make it work: moving the file to other locations, registering it with regsrvr32.exe (which said it couldn't load the module), and adding an alias to the import command under the same name (which automatically gets removed by the editor when I move to a different line), none of which were successful.

Any ideas on where the problem lies? This is the first of a number of functions I would like to use so any help would be much appreciated.

buchWyrm
  • 127
  • 10
  • 1
    Not an answer to your question, but this function at least seems pointless to run on an Access table. A double in a table is either a double or NULL, there is no such thing here as NaN or Infinity or whatever it is your 3rd expression checks for. I think VBA would be more useful for this, since it knows the Access data types. – Andre Jul 14 '17 at 19:29
  • There is a standard bit signature that indicates NaN. I know that VBA doesn't support it, but the presence of such a value in a SQL Server table is a problem. So if by chance a value contains this combination of bits, or more likely got copied from another program, it is important that the value be replaced before it's copied to SQL Server. – buchWyrm Jul 14 '17 at 19:53
  • 1
    @Andre - An Access database certainly can contain `NaN` and `Infinity` values in a column of type `Double`. Although I'm not aware of a way to *insert* such values from Access itself, it can be done from an external application (e.g., [C#](https://pastebin.com/ncWfrfna)). See [this answer](https://stackoverflow.com/a/33193176/2144390). – Gord Thompson Jul 14 '17 at 21:36
  • 1
    (whistle) Thanks @GordThompson, this was completely new to me. -- From your linked answer it seems that SQL would be a better way to find those values than an external function. – Andre Jul 14 '17 at 22:11
  • 2
    see: [How do you get VB6 to initialize doubles with +infinity, -infinity and NaN?](https://stackoverflow.com/questions/885994/how-do-you-get-vb6-to-initialize-doubles-with-infinity-infinity-and-nan) – TnTinMn Jul 15 '17 at 02:46
  • @TnTinMn, thanks for the link re: +/-infinity, NaN. That explains how such values could have gotten into the table in the first place, as well as establishing a method to filter for them. I'd still like an answer to my initial questions, however, as the capacity to import functions from other languages does still have the potential to be beneficial. – buchWyrm Jul 17 '17 at 18:20
  • ` I'd still like an answer to my initial questions` -- Unfortunately, I cannot help you with C library as that is not my thing. However, your profile indicates that you primarily work with C# and I have to ask why you just did not write a COM exposed .Net assembly? That is very easy to do and consume in VBA. – TnTinMn Jul 17 '17 at 18:29

0 Answers0