Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

How to use a dll from InstallScript correctly?


5 replies to this topic

MillionsterNutzer

MillionsterNutzer
  • Full Members
  • 6 posts

Posted 19 March 2009 - 10:15

Hi!

For one of my setups I need to access a dll (it´s a VB dll and it will be also registered for com) to do the following:

- First I will need to create an object from a sprecific class of mydll. Let´s call it MyClass and MyObject. The constructor won´t need any parameters.

- Second I will need to call some functions with MyObject. These functions will need some parameters and out-parameters. Most of these parameters and return values will be of Type LONG and BSTR, but also every function will have an out parameter that is a struct (let´s call it MyErrorStruct) that contains two LONGs (lErrorSystem and lErrorNr) and a BSTR (szDescription). Ofcourse MyErrorStruct is also defined in my Dll.

I´ve already done a lot with InstallScript but I didn´t need an external dll until now, and I don´t have any clue how to solve my Problem. Looking around in help files, forums and the internet I found two funtions that seem relevant for me:
- CoCreateObject and
- UseDll
I found plenty examples, but I still don´t understand...

...how can I instanciate a object of a specfic class? In both fuctions above only the dll or the ProgId is given and an object is created - but of what class??? How can I specify MyClass? How can I specify MyErrorStruct?

...how do I have to handle the parameters and the return values? In these examples there are often 'pointers' and commands like '->' and '&' and I also haven´t ever used a BSTR...
I only need LONGs, BSTR, MyErrorStruct for my funtions could anyone please tell me how to use them in InstallScript?

Could any one help me with my problem?

Best Regards

Ralf

PS: Ihr dürft auch gerne auf deutsch antworten ;-)

Edited by MillionsterNutzer, 19 March 2009 - 10:16.


Stefan Krueger

Stefan Krueger

    InstallSite.org

  • Administrators
  • 13,269 posts

Posted 19 March 2009 - 18:51

UseDLL doesn't work with VB "DLLs" because they aren't "real" DLLs but COM objects.
I'm not sure about your other questions.

MillionsterNutzer

MillionsterNutzer
  • Full Members
  • 6 posts

Posted 20 March 2009 - 10:06

Hi Stefan?

What about BStrings and out parameters:

- Can I simply use a normal STRING-Definition in InstallScript? I haven´t found anything about problems with BStrings and InstallScript on the internet, therefore I guess no one else had problems with this circumstance, so I shouldn´t have either.

- What about the out-parameters? When using CreateObject I don´t have a prototype definition, therefore I don´t have any influence how the parameters are handled. But I can´t imagine that no one else before me used a com-function with out-parameters in his InstallScript.

I´ve played around a bit with CreateObject and my dll. It seems as if I´m instantiating the correct object of my dll when using the ProgID. All the functions I need can be called (name of functions and number of parameters are correct), but I always get...

---------------------------
Unbehandelte Ausnahme
---------------------------
Fehlernummer: 0x80070057
Beschreibung: Falscher Parameter.
Setup wird jetzt beendet.

...an unhadled exception, because of a wrong parameter. I guess this error really depends on 'MyErrorStruct ' that always must be submitted. I also tried to rebuild this struct in InstallScript and submit this replica, but the error stays the same.

Right now my code looks like this:

CODE

typedef MYERRORSTRUCT
begin
LONG     lErrorSystem;
LONG     lErrorNr;
STRING  szDescription;
end;

function UseComDll()
  MYERRORSTRUCT myError;
begin
 set myObject = CoCreateObject ("MyDll.MyClass.1");
 if (IsObject(myObject )) then
    MessageBox("MyClass successfully instantiate",INFORMATION);

    //myError.m_lErrorSystem = 1; //no effect
    //myError.m_lErrorNr = 1; //no effect
    //myError.m_szDescription = "abc"; //no effect

    //myObject.Open(byref myError); //invalid syntax
    //myObject.Open(NULL); //Here comes a "wrong parameter" error

    myObject.Open(myError); //Here comes a "wrong parameter" error
 
 //... even more code

 endif;

 //... even more code

end;


Any ideas how to solve my problem?

Regards

Ralf


phood

phood
  • Full Members
  • 37 posts

Posted 20 April 2009 - 20:17

Can you call the COM directly from InstallScript without using a DLL?

haralds

haralds
  • Full Members
  • 5 posts

Posted 30 May 2009 - 02:35

We've been using a DLL for eight years written in C++.

It now fails on some (most?) Vista systems, because it does not get the privilege elevation of the calling installscript, so it cannot write a configuration file into the application directory.

Behaviors are different between Home and other versions like Ultimate, as well as full foreign installs like French.

Caveat emptor...



phood

phood
  • Full Members
  • 37 posts

Posted 23 June 2009 - 16:25

I thought the .dll code ran under the same context as the calling executable. So far, I've not had problems with Vista, but I haven't had as much experience.

Are you talking about MSI or installscript?