Solved

Calling a DLL function that returns a struct in NSIS.

Posted on 2010-09-24
6
1,172 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

 

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

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

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

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

728 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