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:
Hello, in the rain intensity, they take the value of unavialability as 0.01%. the say the model they use for rain intensity as the reason for this 0.01% unavailability. But for calculating the rain attenuation, it takes this rain intensity into account and the user defined unavailbility as well. So, in total, it takes two unavailability factors into account. and this 0.01% seems too stringent. what do you think about this ? thanks
Hi Aravind -- you can read ITU-R P.618-13. In there (section 2.2.1.1, step 4) you see the method to calculate the rain attenuation relies on the "R_001" value, even if the unavailability you are considering in general is not 0.01%.
 
Upvote 0

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Forum statistics

Threads
1,215,430
Messages
6,124,849
Members
449,194
Latest member
HellScout

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