Solved

Calling a DLL function that returns a struct in NSIS.

Posted on 2010-09-24
6
1,106 Views
Last Modified: 2012-05-11
Hi experts I have created an NSIS installer that is now required to check the version of a DLL before it installs the file. The DLL is written in C and the function I am trying to call is the following:

EXPORT int __stdcall getVersion(VERSION_STRUCT* version){
      
            version->major = verMajor;
            version->minor = verMinor;
            version->revision = verRevision;
            
            return 1;
}            

My question is how can you create a struct in the .nsi script, assign values to this struct by calling the getVersion function in the DLL from the .nsi script,  and finally how can I compare the components of the struct to other integers to check if the DLL is a new version or not.

A VBScript solution is also possible, but not preferred.

Thanks.
0
Comment
Question by:jonathan_hills
  • 5
6 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 33755861
Take a look at http://nsis.sourceforge.net/Calling_an_external_DLL_using_the_System.dll_plugin ("Calling an external DLL using the System.dll plugin") - the scoop would be to

System::Call 'YourDllName::YourDllFunction(i, *i, t) i(.r0, r1, .r2) .r3'
0
 

Author Comment

by:jonathan_hills
ID: 33756195
Okay thank-you I will try to make i work and I will get back to you.
0
 

Author Comment

by:jonathan_hills
ID: 33757205
So far I have this in my function in the .nsi script:


SetOutPath $TEMP\eInspect                               ; create temp directory
      file "..\bin\myDLL.dll"            ; copy dll there

       # allocate
      System::Alloc 12

      Pop $0
      System::Call "*$0(i 5, i 2, i 513)"

      # call
      System::Call "..\bin\myDLL.dll::getVersion(i r0)"

      # get       
      System::Call "*$0(i.r0, i.r1, i.r2)"
      
      # print
      DetailPrint "Major: $0"
      DetailPrint "Minor: $1"
      DetailPrint "Revision: $2"
      #free
      System::Free $0

And in my dll function I have

EXPORT int __stdcall getVersion(VERSION_STRUCT* version){
      
            version->major = verMajor;
            version->minor = verMinor;
            version->revision = verRevision;
            
            return 1;
}                  


It runs it is just the numbers contained in the struct do not change from the initial values I give them. What am I doing wrong with the DLL function call?

SetOutPath $TEMP\eInspect             			; create temp directory
	file "..\bin\myDLL.dll"            ; copy dll there

	 # allocate
	System::Alloc 12

	Pop $0
	System::Call "*$0(i 5, i 2, i 513)"

	# call
	System::Call "..\bin\myDLL.dll::getVersion(i r0)"

	# get	 
	System::Call "*$0(i.r0, i.r1, i.r2)"
	
	# print free
	DetailPrint "Major: $0"
	DetailPrint "Minor: $1"
	DetailPrint "Revision: $2"
	#free
	System::Free $0

Open in new window

0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:jonathan_hills
ID: 33757212
Sorry duplicate code posted in that post above.
0
 

Author Comment

by:jonathan_hills
ID: 33757343
Never mind I ended up figuring it out, thanks for the help jkr.
0
 

Author Closing Comment

by:jonathan_hills
ID: 33757347
Not a complete answer to the question, but still pointed me in the correct direction.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The viewer will learn how to dynamically set the form action using jQuery.

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

29 Experts available now in Live!

Get 1:1 Help Now