Solved

Calling a DLL function that returns a struct in NSIS.

Posted on 2010-09-24
6
1,143 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
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 …

756 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