Old 32-bit DLL; cannot get calls working in 64-bit MS-Excel - PtrSafe or more?

mcm91201

New Member
Joined
Dec 4, 2012
Messages
16
I am not a programmer so please beer with me.


I am running:


Windows v10 Pro ver 1607 OS Build 14393.953
MS-Office 365 ProPlus Version 1701 Build 7766.2060 (there is a Star Trek joke in there somewhere)
MS-Excel 2016 MSO (16.0.7766.7080) 64-bit


I am trying to get an old dll running in new MS-Excel. I use a tool developed by the French space agency (CNES) to calculate satellite link parameters. The tool can be found at https://logiciels.cnes.fr/content/propa?language=en: . The tool consists of a 32-bit dll (propa.dll) and a VBA file (propa.bas). To get the tool to work you put the dll in the MS-Excel path (I stuff it in c:\windows\system32), open up MS-Excel, import the .bas (I stuff it in the same directory as the dll), and start using the dll using the functions defined in the bas file. This worked great all the way through Win v8.1 and MS-Excel 2013 (32-bit). Now upgraded to 64-bit and not so good with the dll/bas. I have reviewed as much as I can find on the web and have some hints but appear to not know what I am doing.


I have the original "VBA6" bas file and a modified "VBA7" bas file listed below. Here are questions comments running through my head; all I care about is getting it working but these questions may give me some understanding to someone else's solution.


VBA6 bas file has an Attribute line; no idea what it does. https://msdn.microsoft.com/EN-US/library/office/gg264344.aspx


The (#if VBA7 - Declare functions - #else) defines everything for VBA7. The (#else - Declare functions - #end if) defines everything for VBA6 or older.
http://www.mrexcel.com/forum/excel-questions/988981-32-bit-visual-basic-applications-64-bit-pc.html


When looking at the VBA code in MS-Excel Developer the VBA7 is compiled "black/blue". The VBA6 stuff is red "error". Trying to call the functions defined in the compiled portion of the bas file (VBA7) gives NAME? errors.


Deleting the #if-then-#else-#end if statements and the VBA6 declarations leaving the VBA7 stuff alone still does not get the VBA7 to work in MS-Excel.


I am guessing that I have two problems here: 1. VBA7 variables in/out of dll are wrong, and 2. if-then-else-endif is wrong.

All of the dll function call input and outputs are of type double. I assume that these are all safe in a 64-bit system or is there something I must do on top of adding the PtrSafe keyword? https://msdn.microsoft.com/en-us/library/office/gg251723.aspx


The aliases all end in an @## is that a clue about variables?

Any help appreciated

Mike


*****Original bas file starts here*****

Rich (BB code):
Attribute VB_Name = "Propa"


Declare Function Agaz Lib "propa" _
           Alias "_Calcule_Agaz@32" (ByVal freq As Double, _
                 ByVal Elevation As Double, _
                 ByVal Temperature As Double, _
                 ByVal ro As Double) As Double


Declare Function Acloud Lib "propa" _
           Alias "_Calcule_Anuages@24" (ByVal freq As Double, _
                 ByVal Elevation As Double, _
                 ByVal L As Double) As Double


Declare Function Arain Lib "propa" _
           Alias "_Calcule_Apluie@64" (ByVal lat As Double, _
                 ByVal freq As Double, _
                 ByVal Elevation As Double, _
                 ByVal Indispo As Double, _
                 ByVal hstation As Double, _
                 ByVal hpluie As Double, _
                 ByVal R001 As Double, _
                 ByVal polar As Double) As Double


Declare Function Iscint Lib "propa" _
           Alias "_Calcule_Scintillation@56" (ByVal Nwet As Double, _
                 ByVal freq As Double, _
                 ByVal Elevation As Double, _
                 ByVal Indispo As Double, _
                 ByVal hstation As Double, _
                 ByVal eta As Double, _
                 ByVal Diam As Double) As Double


Declare Function Nwet Lib "propa" _
           Alias "_Calcule_coindice_refraction@16" (ByVal latitude As Double, _
                 ByVal longitude As Double) As Double


Declare Function TTC Lib "propa" _
           Alias "_Calcule_contenu_eau_liquide@24" (ByVal latitude As Double, _
                 ByVal longitude As Double, _
                 ByVal Indispo As Double) As Double


Declare Function rain_height Lib "propa" _
           Alias "_Calcule_hauteur_pluie@16" (ByVal latitude As Double, _
                 ByVal longitude As Double) As Double


Declare Function rain_intensity Lib "propa" _
           Alias "_Calcule_intensite_pluie@24" (ByVal latitude As Double, _
                 ByVal longitude As Double, _
                 ByVal Indispo As Double) As Double


Declare Function Temperature Lib "propa" _
           Alias "_Calcule_temperature@16" (ByVal latitude As Double, _
                 ByVal longitude As Double) As Double


Declare Function WVC Lib "propa" _
           Alias "_Calcule_vapeur_d_eau@16" (ByVal latitude As Double, _
                 ByVal longitude As Double) As Double


Declare Function iwvc Lib "propa" _
           Alias "_Calcule_contenu_vapeur_eau@24" (ByVal latitude As Double, _
                 ByVal longitude As Double, _
                 ByVal Indispo As Double) As Double


Declare Function Agaz_exceeded Lib "propa" _
           Alias "_Calcule_Agaz_depassee@40" (ByVal freq As Double, _
                 ByVal Elevation As Double, _
                 ByVal Temperature As Double, _
                 ByVal iwvc As Double, _
                 ByVal ro As Double) As Double


Public Declare Function version Lib "propa" _
           Alias "_version@0" () As Long

*****End of original bas file*****


Everything I read says that this edited bas file should do it.


*****Edited bas file*****

Rich (BB code):
#If VBA7 Then
Declare PtrSafe Function Agaz Lib "C:\Windows\System32\propa" _
                   Alias "_Calcule_Agaz@32" (ByVal freq As Double, _
                         ByVal Elevation As Double, _
                         ByVal Temperature As Double, _
                         ByVal ro As Double) As Double


Declare PtrSafe Function Acloud Lib "C:\Windows\System32\propa" _
                   Alias "_Calcule_Anuages@24" (ByVal freq As Double, _
                         ByVal Elevation As Double, _
                         ByVal L As Double) As Double


Declare PtrSafe Function Arain Lib "C:\Windows\System32\propa" _
                   Alias "_Calcule_Apluie@64" (ByVal lat As Double, _
                         ByVal freq As Double, _
                         ByVal Elevation As Double, _
                         ByVal Indispo As Double, _
                         ByVal hstation As Double, _
                         ByVal hpluie As Double, _
                         ByVal R001 As Double, _
                         ByVal polar As Double) As Double


Declare PtrSafe Function Iscint Lib "C:\Windows\System32\propa" _
                   Alias "_Calcule_Scintillation@56" (ByVal Nwet As Double, _
                         ByVal freq As Double, _
                         ByVal Elevation As Double, _
                         ByVal Indispo As Double, _
                         ByVal hstation As Double, _
                         ByVal eta As Double, _
                         ByVal Diam As Double) As Double


Declare PtrSafe Function Nwet Lib "C:\Windows\System32\propa" _
                   Alias "_Calcule_coindice_refraction@16" (ByVal latitude As Double, _
                         ByVal longitude As Double) As Double


Declare PtrSafe Function TTC Lib "C:\Windows\System32\propa" _
                   Alias "_Calcule_contenu_eau_liquide@24" (ByVal latitude As Double, _
                         ByVal longitude As Double, _
                         ByVal Indispo As Double) As Double


Declare PtrSafe Function rain_height Lib "C:\Windows\System32\propa" _
                   Alias "_Calcule_hauteur_pluie@16" (ByVal latitude As Double, _
                         ByVal longitude As Double) As Double


Declare PtrSafe Function rain_intensity Lib "C:\Windows\System32\propa" _
                   Alias "_Calcule_intensite_pluie@24" (ByVal latitude As Double, _
                         ByVal longitude As Double, _
                         ByVal Indispo As Double) As Double


Declare PtrSafe Function Temperature Lib "C:\Windows\System32\propa" _
                   Alias "_Calcule_temperature@16" (ByVal latitude As Double, _
                         ByVal longitude As Double) As Double


Declare PtrSafe Function WVC Lib "C:\Windows\System32\propa" _
                   Alias "_Calcule_vapeur_d_eau@16" (ByVal latitude As Double, _
                         ByVal longitude As Double) As Double


Declare PtrSafe Function iwvc Lib "C:\Windows\System32\propa" _
                   Alias "_Calcule_contenu_vapeur_eau@24" (ByVal latitude As Double, _
                         ByVal longitude As Double, _
                         ByVal Indispo As Double) As Double


Declare PtrSafe Function Agaz_exceeded Lib "C:\Windows\System32\propa" _
                   Alias "_Calcule_Agaz_depassee@40" (ByVal freq As Double, _
                         ByVal Elevation As Double, _
                         ByVal Temperature As Double, _
                         ByVal iwvc As Double, _
                         ByVal ro As Double) As Double


Public Declare PtrSafe Function version Lib "C:\Windows\System32\propa" _
                   Alias "_version@0" () As Long


#Else


Declare Function Agaz Lib "C:\Windows\System32\propa" _
           Alias "_Calcule_Agaz@32" (ByVal freq As Double, _
                 ByVal Elevation As Double, _
                 ByVal Temperature As Double, _
                 ByVal ro As Double) As Double


Declare Function Acloud Lib "C:\Windows\System32\propa" _
           Alias "_Calcule_Anuages@24" (ByVal freq As Double, _
                 ByVal Elevation As Double, _
                 ByVal L As Double) As Double


Declare Function Arain Lib "C:\Windows\System32\propa" _
           Alias "_Calcule_Apluie@64" (ByVal lat As Double, _
                 ByVal freq As Double, _
                 ByVal Elevation As Double, _
                 ByVal Indispo As Double, _
                 ByVal hstation As Double, _
                 ByVal hpluie As Double, _
                 ByVal R001 As Double, _
                 ByVal polar As Double) As Double


Declare Function Iscint Lib "C:\Windows\System32\propa" _
           Alias "_Calcule_Scintillation@56" (ByVal Nwet As Double, _
                 ByVal freq As Double, _
                 ByVal Elevation As Double, _
                 ByVal Indispo As Double, _
                 ByVal hstation As Double, _
                 ByVal eta As Double, _
                 ByVal Diam As Double) As Double


Declare Function Nwet Lib "C:\Windows\System32\propa" _
           Alias "_Calcule_coindice_refraction@16" (ByVal latitude As Double, _
                 ByVal longitude As Double) As Double


Declare Function TTC Lib "C:\Windows\System32\propa" _
           Alias "_Calcule_contenu_eau_liquide@24" (ByVal latitude As Double, _
                 ByVal longitude As Double, _
                 ByVal Indispo As Double) As Double
                 
Declare Function rain_height Lib "C:\Windows\System32\propa" _
           Alias "_Calcule_hauteur_pluie@16" (ByVal latitude As Double, _
                 ByVal longitude As Double) As Double
                 
Declare Function rain_intensity Lib "C:\Windows\System32\propa" _
           Alias "_Calcule_intensite_pluie@24" (ByVal latitude As Double, _
                 ByVal longitude As Double, _
                 ByVal Indispo As Double) As Double


Declare Function Temperature Lib "C:\Windows\System32\propa" _
           Alias "_Calcule_temperature@16" (ByVal latitude As Double, _
                 ByVal longitude As Double) As Double
                 
Declare Function WVC Lib "C:\Windows\System32\propa" _
           Alias "_Calcule_vapeur_d_eau@16" (ByVal latitude As Double, _
                 ByVal longitude As Double) As Double
                 
Declare Function iwvc Lib "C:\Windows\System32\propa" _
           Alias "_Calcule_contenu_vapeur_eau@24" (ByVal latitude As Double, _
                 ByVal longitude As Double, _
                 ByVal Indispo As Double) As Double
                 
Declare Function Agaz_exceeded Lib "C:\Windows\System32\propa" _
           Alias "_Calcule_Agaz_depassee@40" (ByVal freq As Double, _
                 ByVal Elevation As Double, _
                 ByVal Temperature As Double, _
                 ByVal iwvc As Double, _
                 ByVal ro As Double) As Double


Public Declare version Lib "C:\Windows\System32\propa" _
           Alias "_version@0" () As Long


#End If

*****End of edited bas file*****
 
Last edited by a moderator:
because it is now 64bit, that is the root cause

Yes. Thank you for pointing that out.

Are you saying that 64-bit applications do not have a variable type double? What variable type does a 64-bit application use for a floating point number? Or are you saying that a double, an 8-byte (64-bit) IEEE floating point number, is not 64-bits?
 
Upvote 0

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Double is the correct type, but as far as I know a 64bit program cannot directly load a 32bit dll so this simply won't work without an updated dll.
 
Upvote 0
Double is the correct type, but as far as I know a 64bit program cannot directly load a 32bit dll so this simply won't work without an updated dll.

Thank you. I am still thrown that when I first started this thread the errors I had in the spreadsheet were of the type #NAME!. After updating the bas file these errors became #VALUE! Errors specifically referencing data types. In the first case it was not recognizing the functions whereas in the second case it recognized the function calls but choked on the data input or output.

I have requested the source code and see if I can figure something out with C.
 
Upvote 0
A #VALUE error from a worksheet function really only tells you that something went wrong in the function.
 
Upvote 0
A #VALUE error from a worksheet function really only tells you that something went wrong in the function.

See Comment #6 above. The cell shows #VALUE! But it specifically states that a value is the wrong data type.

The old joke about a woman whose son is a writer. He makes people happy, sad, angry, very emotional prose. He writes error messages for Microsoft.
 
Upvote 0
I wouldn't necessarily expect the error messages to be able to cover every conceivable scenario.
 
Upvote 0
Thank you. I am still thrown that when I first started this thread the errors I had in the spreadsheet were of the type #NAME!. After updating the bas file these errors became #VALUE! Errors specifically referencing data types. In the first case it was not recognizing the functions whereas in the second case it recognized the function calls but choked on the data input or output.

I have requested the source code and see if I can figure something out with C.
Mike, did you ever find a solution to your problem? I have recently updated to Office 365 and face the exact same problem. Appreciate this post comes 5 years after your original post!
 
Upvote 0
Mike, did you ever find a solution to your problem? I have recently updated to Office 365 and face the exact same problem. Appreciate this post comes 5 years after your original post!
I paid a software developer colleague to rework the VBA bas file. He reverse engineered the 64-bit version of the dll then updated the bas file. I have looked at his code but have not been able to determine exactly how he made things happy. Sorry - not much help.
 
Upvote 0
Following a quick google search, I found this PROPA softaware website : PROPA | LOGICIELS CNES

There is a 64bit version of the dll that you can download.

I hope I am not violating anything here. :oops:
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top