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:

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
as you say its a 32 bit file, being addressed by a 64bit system. is there a 64 bit version available from the original source.

system32 is a 32bit store in general

i think there is a WOW64 path
 
Upvote 0
AFAIK, 64bit applications cannot use 32 bit dlls .. You will need to check with the dll provider if they have a 64bit version of the dll.
 
Upvote 0
as you say its a 32 bit file, being addressed by a 64bit system. is there a 64 bit version available from the original source.

system32 is a 32bit store in general

i think there is a WOW64 path


I have also tried the c:\Windows\SysWow64 path. That worked on the Win v8.1 and MS-Excel 2013 configuration.

A 64-bit version of the utility is not available.
 
Upvote 0
OK. When originally working this problem the VBA6 version of the propa.bas file reported #NAME! errors in the spreadsheet.

I removed all references to the VBA6 code and updated the propa.bas file to look like below. I specifically called out path and filename. I then placed the propa.dll in the c:\Windows\SysWOW64 directory per Mole999 above. I had tried this earlier but did not notice these results until this morning. With the new propa.bas file the error changed to #VALUE! and hovering over the cell gave the message "A value used in the formula is of the wrong data type"; this seems like huge progress - Excel is recognizing the function names. The question is whether it is the wrong data type going in to the dll or is it the wrong data type coming out? Is there a way to check this? All of the variables handed off in the functions are of type double; is type double supported in VBA6 (32-bit) and VBA7 (64-bit) for backward compatibility?

https://msdn.microsoft.com/en-us/library/office/gg264155.aspx

I left the values going into the functions as doubles and changed all the return values coming out of the functions into long with no success. Again, double has to be supported?

Here is an example function call where D6 = latitude and D7 = longitude. Can you check data type in the spreadsheet or must you do it in the propa.bas file? No idea how to use the debugger

=rain_intensity(D6,D7,0.01)

Again thanks for any help.



Code:
Declare PtrSafe Function Agaz Lib "C:\Windows\SysWOW64\propa.dll" _
                   Alias "_Calcule_Agaz@32" (ByVal freq As Double, _
                         ByVal Elevation As Double, _
                         ByVal Temperature As Double, _
                         ByVal ro As Double) As Long


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


Declare PtrSafe Function Arain Lib "C:\Windows\SysWOW64\propa.dll" _
                   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 Long


Declare PtrSafe Function Iscint Lib "C:\Windows\SysWOW64\propa.dll" _
                   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 Long


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


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


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


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


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


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


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


Declare PtrSafe Function Agaz_exceeded Lib "C:\Windows\SysWOW64\propa.dll" _
                   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 Long


Public Declare PtrSafe Function version Lib "C:\Windows\SysWOW64\propa.dll" _
                   Alias "_version@0" () As Long
 
Upvote 0
Just a stab in the dark. Try replacing Double with LongLong or with LongPtr
 
Upvote 0
Just a stab in the dark. Try replacing Double with LongLong or with LongPtr

Double is floating point; Long, Longlong, LongPtr are integer.

The only floating point of that size is double and it is the same for both Office 2010 and 2013+. If double has not changed since Office 2010 does it require PtrSafe in declaration? Why is it behaving differently?

https://msdn.microsoft.com/en-us/library/office/gg264155.aspx

https://msdn.microsoft.com/en-us/library/office/gg264155(v=office.14).aspx
 
Last edited:
Upvote 0
because it is now 64bit, that is the root cause
 
Upvote 0

Forum statistics

Threads
1,216,076
Messages
6,128,670
Members
449,463
Latest member
Jojomen56

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