Solved

Calling a DLL function that returns a struct in NSIS.

Posted on 2010-09-24
6
1,093 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
Comment Utility
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
Comment Utility
Okay thank-you I will try to make i work and I will get back to you.
0
 

Author Comment

by:jonathan_hills
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:jonathan_hills
Comment Utility
Sorry duplicate code posted in that post above.
0
 

Author Comment

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

Author Closing Comment

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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
A short article about problems I had with the new location API and permissions in Marshmallow
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

772 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

10 Experts available now in Live!

Get 1:1 Help Now