Attempting to call Coolprop from VB.net (Visual Studio 2017)

312 views
Skip to first unread message

Spiz103

unread,
Dec 18, 2017, 12:11:05 PM12/18/17
to coolprop-users
Well,
I've been trying to use Coolprop to do some thermodynamic calculations but I can't, no matter what, get a project to work that allows me to call it from inside VB.net using VS 2017.

I've found some files that purported to be working examples for earlier versions of Visual Studio but they unfortunately throw horrible exception errors in 2017.

Does anyone have any idea how to get it working? I've tried all the instructions on the sourceforge website but am getting basically nowhere?

Jorrit Wronski

unread,
Dec 18, 2017, 5:24:14 PM12/18/17
to coolpro...@googlegroups.com

Hi,

 

have you had a look at the Excel wrapper? I am not an expert in VB, but isn’t VB.net closely related to the code used to call a DLL from Excel? Download the Windows installer and look at the Excel plugin to get an idea of what I am talking about: http://www.coolprop.org/coolprop/wrappers/Excel/index.html#automated-installation

 

Jorrit

--
You received this message because you are subscribed to the Google Groups "coolprop-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coolprop-user...@googlegroups.com.
To post to this group, send email to coolpro...@googlegroups.com.
Visit this group at https://groups.google.com/group/coolprop-users.
For more options, visit https://groups.google.com/d/optout.

Ian Bell

unread,
Dec 18, 2017, 9:31:14 PM12/18/17
to coolpro...@googlegroups.com
I would say the things to do would be:

1) Rewind to the version of visual basic that we claim works.  Make sure it works for you.  If not figure out why not.
2) Take the working project from old VS and import into VS 2017.  Make sure that works.
3) Start over with VS 2017.

At each step, error logs are indispensable.  This statement is useless from a debugging standpoint: "throw horrible exception errors" :)

Kind Regards,
Ian

On Mon, Dec 18, 2017 at 3:24 PM, Jorrit Wronski <jo...@ipu.dk> wrote:

Hi,

 

have you had a look at the Excel wrapper? I am not an expert in VB, but isn’t VB.net closely related to the code used to call a DLL from Excel? Download the Windows installer and look at the Excel plugin to get an idea of what I am talking about: http://www.coolprop.org/coolprop/wrappers/Excel/index.html#automated-installation

 

Jorrit

 

 

From: coolprop-users@googlegroups.com [mailto:coolprop-users@googlegroups.com] On Behalf Of Spiz103
Sent: Monday, December 18, 2017 6:11 PM
To: coolprop-users
Subject: [coolprop-users] Attempting to call Coolprop from VB.net (Visual Studio 2017)

 

Well,
I've been trying to use Coolprop to do some thermodynamic calculations but I can't, no matter what, get a project to work that allows me to call it from inside VB.net using VS 2017.

I've found some files that purported to be working examples for earlier versions of Visual Studio but they unfortunately throw horrible exception errors in 2017.

Does anyone have any idea how to get it working? I've tried all the instructions on the sourceforge website but am getting basically nowhere?

--
You received this message because you are subscribed to the Google Groups "coolprop-users" group.

To unsubscribe from this group and stop receiving emails from it, send an email to coolprop-users+unsubscribe@googlegroups.com.
To post to this group, send email to coolprop-users@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "coolprop-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coolprop-users+unsubscribe@googlegroups.com.
To post to this group, send email to coolprop-users@googlegroups.com.

Spiz103

unread,
Dec 19, 2017, 6:59:50 AM12/19/17
to coolprop-users
More, more detailed information:

I have attempted to use multiple wrappers without success - either I get errors detailing failure to load the DLL, or I get a "cannot find entry" type error.

I have also attempted to use multiple versions of the library using the LibreOffice Wrapper provided on Sourceforge - using the 32 bit stdcall DLL as directed.

This is a Windows 7 machine, however my Windows 10 netbook runs the 6.0.0 LibreOffice Wrapper/DLL combination perfectly.
So I have no idea what is going on really.

For example the LibreOffice Wrapper throws errors "BASIC Runtime Error, Error loading DLL file" repeatedly for each exposed function.





On Tuesday, 19 December 2017 02:31:14 UTC, Ian Bell wrote:
I would say the things to do would be:

1) Rewind to the version of visual basic that we claim works.  Make sure it works for you.  If not figure out why not.
2) Take the working project from old VS and import into VS 2017.  Make sure that works.
3) Start over with VS 2017.

At each step, error logs are indispensable.  This statement is useless from a debugging standpoint: "throw horrible exception errors" :)

Kind Regards,
Ian
On Mon, Dec 18, 2017 at 3:24 PM, Jorrit Wronski <jo...@ipu.dk> wrote:

Hi,

 

have you had a look at the Excel wrapper? I am not an expert in VB, but isn’t VB.net closely related to the code used to call a DLL from Excel? Download the Windows installer and look at the Excel plugin to get an idea of what I am talking about: http://www.coolprop.org/coolprop/wrappers/Excel/index.html#automated-installation

 

Jorrit

 

 

From: coolpro...@googlegroups.com [mailto:coolpro...@googlegroups.com] On Behalf Of Spiz103
Sent: Monday, December 18, 2017 6:11 PM
To: coolprop-users
Subject: [coolprop-users] Attempting to call Coolprop from VB.net (Visual Studio 2017)

 

Well,
I've been trying to use Coolprop to do some thermodynamic calculations but I can't, no matter what, get a project to work that allows me to call it from inside VB.net using VS 2017.

I've found some files that purported to be working examples for earlier versions of Visual Studio but they unfortunately throw horrible exception errors in 2017.

Does anyone have any idea how to get it working? I've tried all the instructions on the sourceforge website but am getting basically nowhere?

--
You received this message because you are subscribed to the Google Groups "coolprop-users" group.

To unsubscribe from this group and stop receiving emails from it, send an email to coolprop-user...@googlegroups.com.
To post to this group, send email to coolpr...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "coolprop-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coolprop-user...@googlegroups.com.
To post to this group, send email to coolpro...@googlegroups.com.

Spiz103

unread,
Dec 19, 2017, 8:20:05 AM12/19/17
to coolprop-users
Further to my last message:

Unfortunately rolling back to VS2012 is no longer an option as that software is no longer provided by Microsoft except to people with an MSDN subscription,

I have managed to get it to load the x64 DLL, however it now throws the exception error "System.EntryPointNotFoundException: 'Unable to find an entry point named '_Props@32' in DLL 'CoolProp.dll'.'" when it attempts to actually call a command in it.
I am pretty sure I am in the correct architecture as otherwise I get an error "System.BadImageFormatException: 'An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)'" - which I understand is associated with calling a 64 bit DLL with a 32 bit call?

Spiz103

unread,
Dec 19, 2017, 9:34:23 AM12/19/17
to coolprop-users
Sorry for yet another message by me,

Please find attached my code - I started with the original Coolprop VB.net example wrapper and it has mutated into this since it doesn't seem to work on VS2017 at all, not even recognising the C# component properly.

I have managed to work out the entry point problem using the manifest txt file on Sourceforge, however have run into a brick wall that the execution of this code generates a System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.' Error at the point at which the actual call to the DLL is made, the input does not appear to be malformed in any way and it is not throwing a segmentation fault.

So at this point I am entirely stumped.
Example.vb.txt

Ian Bell

unread,
Dec 19, 2017, 10:23:03 AM12/19/17
to coolpro...@googlegroups.com
Hmm maybe I need to look into this.  Can you please file an issue on this topic on GitHub?

--
You received this message because you are subscribed to the Google Groups "coolprop-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coolprop-users+unsubscribe@googlegroups.com.
To post to this group, send email to coolprop-users@googlegroups.com.

Spiz103

unread,
Dec 19, 2017, 12:48:58 PM12/19/17
to coolprop-users
As requested I have made a Github issue with my most up to date information, #1623 https://github.com/CoolProp/CoolProp/issues/1623


On Tuesday, 19 December 2017 15:23:03 UTC, Ian Bell wrote:
Hmm maybe I need to look into this.  Can you please file an issue on this topic on GitHub?
On Dec 19, 2017 7:34 AM, "Spiz103" <edmund....@student.manchester.ac.uk> wrote:
Sorry for yet another message by me,

Please find attached my code - I started with the original Coolprop VB.net example wrapper and it has mutated into this since it doesn't seem to work on VS2017 at all, not even recognising the C# component properly.

I have managed to work out the entry point problem using the manifest txt file on Sourceforge, however have run into a brick wall that the execution of this code generates a System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.' Error at the point at which the actual call to the DLL is made, the input does not appear to be malformed in any way and it is not throwing a segmentation fault.

So at this point I am entirely stumped.

--
You received this message because you are subscribed to the Google Groups "coolprop-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coolprop-user...@googlegroups.com.
To post to this group, send email to coolpro...@googlegroups.com.

Alessandro Mandelli

unread,
Mar 15, 2018, 10:49:35 AM3/15/18
to coolprop-users
Hello, I'm trying to use Coolprop in a vb.net vs2017 solution.
How did you get through the "Unable to find an entry point" dreaded error.
Despite using precompiled dll, or recompiling the solution from scratch, nothing works.
I can't get through the missing entry point.

Ian Bell

unread,
Mar 15, 2018, 11:02:23 PM3/15/18
to coolpro...@googlegroups.com
1) Do you want VB.NET or VB? 
2) What have you tried so far?  It's hard to tell from your question.  What does "nothing works" mean?  Logs/screenshots please
3) Can you please show your build log of your recompiled solution from scratch?

--
You received this message because you are subscribed to the Google Groups "coolprop-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coolprop-users+unsubscribe@googlegroups.com.
To post to this group, send email to coolprop-users@googlegroups.com.

Alessandro Mandelli

unread,
Mar 16, 2018, 3:18:42 AM3/16/18
to coolprop-users
1) Does even vb exist any longer? vb is just an alias for vb.net, clearly.
2) I've tried everything, from using the wrappers (most of them, including excel and c#) to recompile from scratch, with both cmake and vs2017. Compiling always ends succesfully. Specifically compiling with cmake and -DCOOLPROP_SHARED_LIBRARY although with 38 warnings pertaining mostly to TR1 machine namespace, yet again the resulting DLL can't be referenced from VS2017, and can't even be registered via regsvr32 for the same reason: can't find the entry point (my 0.02: namespace and main are missing, probably a swig issue)
3) Of course. What folder the logs are saved into? Is that ./build/x64/Release/ALL_BUILD by any chance?

The question remains: how did the OP get through the entry point problem with the manifest?

Cheers.



Il giorno venerdì 16 marzo 2018 04:02:23 UTC+1, Ian Bell ha scritto:
1) Do you want VB.NET or VB? 
2) What have you tried so far?  It's hard to tell from your question.  What does "nothing works" mean?  Logs/screenshots please
3) Can you please show your build log of your recompiled solution from scratch?
On Thu, Mar 15, 2018 at 8:49 AM, Alessandro Mandelli <alessandr...@coster.eu> wrote:
Hello, I'm trying to use Coolprop in a vb.net vs2017 solution.
How did you get through the "Unable to find an entry point" dreaded error.
Despite using precompiled dll, or recompiling the solution from scratch, nothing works.
I can't get through the missing entry point.


Il giorno martedì 19 dicembre 2017 14:20:05 UTC+1, Spiz103 ha scritto:
Further to my last message:

Unfortunately rolling back to VS2012 is no longer an option as that software is no longer provided by Microsoft except to people with an MSDN subscription,

I have managed to get it to load the x64 DLL, however it now throws the exception error "System.EntryPointNotFoundException: 'Unable to find an entry point named '_Props@32' in DLL 'CoolProp.dll'.'" when it attempts to actually call a command in it.
I am pretty sure I am in the correct architecture as otherwise I get an error "System.BadImageFormatException: 'An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)'" - which I understand is associated with calling a 64 bit DLL with a 32 bit call?

--
You received this message because you are subscribed to the Google Groups "coolprop-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coolprop-user...@googlegroups.com.
To post to this group, send email to coolpro...@googlegroups.com.

Alessandro Mandelli

unread,
Mar 16, 2018, 10:04:33 AM3/16/18
to coolprop-users
Nevermind, I solved with a trick. I installed DWSIM, which has an interface made for coolprop.
I referenced DWSIM.Thermodynamics.Coolpropinterface.dll in my solution.

The code looks like this (for PropsSI only. Extend declarations to include more function). Works for AnyCPU, x86 and x64.


Imports CoolProp

Public Class Form1

    Declare Function PropsSI_private Lib "Coolprop.dll" Alias "PropsSI" (ByVal output As String, ByVal Name1 As String, ByVal Value1 As Double, ByVal Name2 As String, ByVal Value2 As Double, ByVal Ref As String) As Double


    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
          'put your stuff here
    End Sub

    Public Function PropsSI(ByVal output As String, ByVal Name1 As String, ByVal Value1 As Double, ByVal Name2 As String, ByVal Value2 As Double, ByVal fluid As String) returns Double

        PropsSI_temp = PropsSI_private(output, Name1, Value1, Name2, Value2, fluid)
        If Math.Abs(PropsSI_temp) > 1.0E+30 Then
            Return 0
        Else
            Return PropsSI_temp
        End If

    End Function

End Class

Ian Bell

unread,
Mar 16, 2018, 10:56:02 AM3/16/18
to coolpro...@googlegroups.com
I'm surprised your code *does* work on all the platform options actually, I would have thought that it would have had to find the matching DLL - did you compile a 32-bit DLL and a 64-bit DLL?

I think we are talking about different things when we talk about VB.  I have in mind the .NET framework, for which you should follow basically the C# instructions (http://www.coolprop.org/coolprop/wrappers/Csharp/index.html#csharp) to build the C# wrapper, and then link that into your VB.NET project (http://www.coolprop.org/coolprop/wrappers/VB.net/index.html#vbdotnet).  Did you try following those instructions?  That would be my recommendation - though I can see that the formatting of the VB docs got a bit messed up...

To unsubscribe from this group and stop receiving emails from it, send an email to coolprop-users+unsubscribe@googlegroups.com.
To post to this group, send email to coolprop-users@googlegroups.com.

Alessandro Mandelli

unread,
Mar 16, 2018, 11:05:32 AM3/16/18
to coolpro...@googlegroups.com
I didn't actually compile anything this time. I just lended the precompiled DWSIM interface .dll which in turn references to their precompiled coolprop.dll and it works.

I followed the instructions for c# , as already explained. The resulting coolprop.dll is still unmanaged code.
Also the vb.net instructions lead to the same experience.


--
Cordiali saluti
Best regards


Alessandro Mandelli
Technical support group coordinator
alessandr...@costergroup.eu


Sede legale/operativa Milano: Via San G.B. De La Salle 4/A 20132 Milano Tel:+39.02.2722121  Fax: +39.02.2593645

Coster Group s.r.l. 

Risparmio e Contabilizzazione Energia  - Building Automation - Monitoring - Remote Control

Sede operativa Novi Ligure: Via Trattati di Maastricht, 32 15067 Novi Ligure (AL) Tel. +39 0143 329717 Fax +39 0143329707

Sede operativa Roma: Via Stefano Longanesi 14 00146 Roma Tel:+39 065534191 Fax: +39.06.5566517

Stabilimento e Spedizioni: Via Gen. Treboldi, 190/192 - 25048 Edolo (BS)

www.costergroup.eu

Indirizzo PEC: coste...@pec.it

Numero REA: MI - 2108989

C. F. e P.I. : 09712950964

Le informazioni contenute in questa e-mail sono ad uso esclusivo del destinatario indicato e coperte dal segreto professionale.

Se non siete il destinatario indicato, vi informiamo che la diffusione o la riproduzione della comunicazione è contraria alle vigenti disposizioni di legge. Se questa comunicazione vi fosse pervenuta per errore, vi preghiamo di volerci avvertire per telefono o telefax o e-mail chiamando i numeri indicati e di distruggere quanto ricevuto.

Alessandro Mandelli

unread,
Mar 17, 2018, 8:45:37 AM3/17/18
to coolpro...@googlegroups.com
The answer was much easier. To use the Coolprop.dll in a vb.net framework project (or any .net framework project) the entry points must be redefined.
The missing entry points were caused by decoration of the names of the Functions and Subs at compile time.


----
Imports System.Runtime.InteropServices

Public Class Principale

    <DllImport("Coolprop.dll", EntryPoint:="CSharp_PropsSI")>
    Public Shared Function PropsSI(ByVal output As String, ByVal Name1 As String, ByVal Value1 As Double,

                                   ByVal Name2 As String, ByVal Value2 As Double, ByVal Ref As String) As Double
    End Function
    <DllImport("Coolprop.dll", EntryPoint:="CSharp_set_reference_stateS")>
    Public Shared Sub set_reference_stateS(ByVal in1 As String, ByVal in2 As String)
    End Sub

    Function myTest(ByVal temp As Single) As Double

        set_reference_stateS("R134A", "IIR")
        entin = PropsSI("H", "T", SuctionTempNumericUpDownSummer.Value + 273.15, "Q", 6, "R134A")
        Return entin

    End Function
----

​​

Ian Bell

unread,
Mar 17, 2018, 12:47:06 PM3/17/18
to coolpro...@googlegroups.com
Actually, I'm not sure that is truly necessary.  If you followed the instructions on the website for VB.net (exactly), all the functions are defined already, you just need to make sure they get into your project.  Can you send a screenshot of your VB.net project in Visual Studio with the CoolProp C# code integrated?  

Alessandro Mandelli

unread,
Mar 17, 2018, 12:53:31 PM3/17/18
to coolpro...@googlegroups.com

​I dont' integrate c# code in my vb.net project. I just call the coolprop.dll, compiled with c# wrappers.​
​But because the wrappers decorate the name​s of the function and subs, the dll can't be referenced directly in the project.
Inspecting the .dll with a dll inspector revealed why vs2017 cound't find any entry points to the exposed functions and subs.

Ian Bell

unread,
Mar 17, 2018, 12:58:22 PM3/17/18
to coolpro...@googlegroups.com
But integrating the C# module into VB.net is what you *should* do, because then you get access to the low-level interface, which is far more performant than the high-level interface.  This all said, I'm not an expert, but any time you can rely on auto-generated code, that is almost always more reliable and easier to maintain than hand-rolled code.

Spiz103

unread,
Mar 17, 2018, 1:54:03 PM3/17/18
to coolprop-users
This is the Code that I managed to eventually get working:

Module Module1
   
Private Declare Function PropsSI_private Lib "C:\CoolProp\CoolProp-x64.dll" Alias "PropsSI" (ByVal ReturnValue As String, ByVal Name1 As String, ByVal Value1 As Double, ByVal Name2 As String, ByVal Value2 As Double, ByVal Ref As String) As Double
   
Private Declare Function Props1SI_private Lib "C:\CoolProp\CoolProp-x64.dll" Alias "Props1SI" (ByVal Ref As String, ByVal ReturnValue As String) As Double
   
Private Declare Function HAProps_private Lib "C:\CoolProp\CoolProp-x64.dll" Alias "HAProps" (ByVal ReturnValue As String, ByVal Input1Name As String, ByVal Value1 As Double, ByVal Input2Name As String, ByVal Value2 As Double, ByVal Input3name As String, ByVal Value3 As Double) As Double

   
Public Function PropsSI(ByVal ReturnValue As String, ByVal Name1 As String, ByVal Value1 As Double, ByVal Name2 As String, ByVal Value2 As Double, ByVal Ref As String) As Double
       
PropsSI = PropsSI_private(ReturnValue, Name1, Value1, Name2, Value2, Ref)
   
End Function

   
Public Function Props1SI(ByVal Ref As String, ByVal ReturnValue As String) As Double
       
Props1SI = Props1SI_private(Ref, ReturnValue)
   
End Function

   
Public Function HAProps(ByVal ReturnValue As String, ByVal Input1Name As String, ByVal Value1 As Double, ByVal Input2Name As String, ByVal Value2 As Double, ByVal Input3name As String, ByVal Value3 As Double) As Double
       
HAProps = HAProps_private(ReturnValue, Input1Name, Value1, Input2Name, Value2, Input3name, Value3)
   
End Function

   
Sub Main()
       
Console.WriteLine(PropsSI("T", "P", 101325, "Q", 0, "Water"))
   
End Sub

End Module
This avoids calling C# wrappers explicitly and simply directly calls the DLL.
The entry points are the hard part as they are different for the x64 and x86 versions of the library.


Alessandro Mandelli

unread,
Mar 17, 2018, 2:28:03 PM3/17/18
to coolpro...@googlegroups.com
More or less, that's what I did.
The downside of this approach is that a Private Declare is necessary for each and every sub and function included in Coolprop.dll

--
Cordiali saluti
Best regards


Alessandro Mandelli
Technical support group coordinator
alessandr...@costergroup.eu


Sede legale/operativa Milano: Via San G.B. De La Salle 4/A 20132 Milano Tel:+39.02.2722121  Fax: +39.02.2593645

Coster Group s.r.l. 

Risparmio e Contabilizzazione Energia  - Building Automation - Monitoring - Remote Control

Sede operativa Novi Ligure: Via Trattati di Maastricht, 32 15067 Novi Ligure (AL) Tel. +39 0143 329717 Fax +39 0143329707

Sede operativa Roma: Via Stefano Longanesi 14 00146 Roma Tel:+39 065534191 Fax: +39.06.5566517

Stabilimento e Spedizioni: Via Gen. Treboldi, 190/192 - 25048 Edolo (BS)

www.costergroup.eu

Indirizzo PEC: coste...@pec.it

Numero REA: MI - 2108989

C. F. e P.I. : 09712950964

Le informazioni contenute in questa e-mail sono ad uso esclusivo del destinatario indicato e coperte dal segreto professionale.

Se non siete il destinatario indicato, vi informiamo che la diffusione o la riproduzione della comunicazione è contraria alle vigenti disposizioni di legge. Se questa comunicazione vi fosse pervenuta per errore, vi preghiamo di volerci avvertire per telefono o telefax o e-mail chiamando i numeri indicati e di distruggere quanto ricevuto.


To unsubscribe from this group and stop receiving emails from it, send an email to coolprop-users+unsubscribe@googlegroups.com.
To post to this group, send email to coolprop-users@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages