PDA

View Full Version : Using the Developer Automation Interface with C++



GlenMiller
01-20-2005, 09:12 PM
Has anyone tried the following C++ automation sample with IS 10.5?

http://www.installshield.com/news/newsletter/0209-articles/cppautomation.asp

It is crashing for me on the call to OpenProject. I get the following in my output window:

First-chance exception at 0x77e738b2 in nplan: 0xC000008F: Floating-point inexact result.
First-chance exception at 0x77e738b2 in nplan: 0xC000008F: Floating-point inexact result.
First-chance exception at 0x77e738b2 in nplan: Microsoft C++ exception: _com_error @ 0x0022dc74.

Is there anything I need to watch out for that isn't mentioned in the article?

GlenMiller
01-20-2005, 11:56 PM
The error message is "ActiveX component can't create object"

LewisQ
01-21-2005, 10:47 AM
Only done work with C# and VB .Net. All I can tell you is that you can expect some grief from the COM interop with both. I never tried with C++.

GlenMiller
01-21-2005, 10:59 AM
I've discovered that if I register ISWiAutomation1050.dll, then OpenProject() succeeds.

However, anything I try after that fails. For example, GetProductName() gives me the error "Object variable or With block variable not set". SaveProject() gives me the error "Unable to save file: . : The project is open in read-only mode or is being used by another process." (even though it's not read-only).

This is code from InstallShield's example - a working example is needed here!

Or would I be better off giving up on automation, and just manipulating the project's XML directly?

RobertDickau
01-21-2005, 11:16 AM
This worked for me:



#include <comdef.h>
#include <iostream>

using namespace std;

#import "C:\Program Files\InstallShield 10.5\System\ISWiAutomation1050.dll" no_namespace

int main(int argc, char *argv[])
{
HRESULT hr = CoInitialize(NULL);

if (FAILED(hr))
{
cout << "Couldn't initialize COM!" << endl;
return hr;
}

try
{
_ISWiProjectPtr oISM(__uuidof(ISWiProject));
oISM->OpenProject(_bstr_t("C:\\My InstallShield 10.5 Projects\\Test.ism"), VARIANT_TRUE);

_bstr_t bstrProductName = oISM->GetProductName( );
cout << "ProductName: " << static_cast<const char *>(bstrProductName) << endl;

BSTR bpv = ::SysAllocString(L"1.0.0");
oISM->PutProductVersion(&bpv);
::SysFreeString(bpv);

_bstr_t bstrProductVersion = oISM->GetProductVersion( );
cout << "\tProductVersion: " << static_cast<const char *>(bstrProductVersion) << endl;

_bstr_t bstrProductCode = oISM->GetProductCode( );
cout << "\tProductCode: " << static_cast<const char *>(bstrProductCode) << endl;

_bstr_t bstrPackageCode = oISM->GetPackageCode( );
cout << "\tPackageCode: " << static_cast<const char *>(bstrPackageCode) << endl;
}
oISM->SaveProject( );
oISM->CloseProject( );
}
catch(_com_error &e)
{
cout << "### Exception:" << endl << (const char*)(e.Description( )) << endl;
}

CoUninitialize( );
return 0;
}

GlenMiller
01-21-2005, 01:50 PM
OpenProject() is returning error code 4 for me. From the help:

There was a problem creating the merge module catalog. Verify that the merge module search path is correct (via the File Locations tab of the Options dialog or using -o for a standalone build), verify that no merge modules on the merge module path are corrupt, or self-register IsMMUpdater2.dll.

I have tried the following, in this order:
1. From the IDE, went to Tools->Options->Merge Modules, remove all paths except "C:\Program Files\InstallShield 10.5\Modules\i386"
2. Moved all files out of this folder.
3. registered IsMMUpdater2.dll

I still get the same error in each case. How can I determine what is causing this error?

GlenMiller
01-24-2005, 10:00 AM
It seems the problem is with IS10.5. I now have both ISX and IS10.5 installed on the same PC. The sample code works perfectly with the ISX dll. But it doesn't work at all with the IS10.5 dll (OpenProject() fails with "ActiveX component can't create object").

Has anyone else run into this? I'm not sure what else to try at this point...

RobertDickau
01-24-2005, 10:13 AM
Hmmm... I don't think it's a general problem; I have 10.5, X, and 9 installed on the same system, and that example I posted works here... Does it work with another project? On another system? Does a VBScript example using the 10.5 Automation interface work?

GlenMiller
01-24-2005, 05:02 PM
I was getting the problem with a new InstallScript MSI project (basically blank, created through the wizard). I've since tested with the sample Othello.ism that comes with 10.5 - same problem.

I tested a simple VBScript sample - that seems to work fine.

Haven't had a chance to try on another PC yet.

This is driving me crazy! :)

RobertDickau
01-25-2005, 09:50 AM
Could you post (at least an excerpt of) the C++ code you're using?

GlenMiller
01-25-2005, 10:47 AM
I just tried on another machine, this one was a clean build PC using the SAAuto dlls. Same problem. Both machines are WinXP. I've also tried a Win2K machine, but my project wouldn't compile for some reason.

Here is my code that works with SAAuto10.dll but fails on OpenProject() "ActiveX component can't create object" with SAAuto1050.dll.


#define IS10 0
#define IS1050 1

#include <comdef.h>
#include <iostream>

using namespace std;

// import information from type library
#if IS10
#import "E:\Program Files\Installshield X StandaloneBuild\SAAuto10.dll" no_namespace
#elif IS1050
#import "E:\Program Files\Installshield 10.5 StandaloneBuild\SAAuto1050.dll" no_namespace
#endif

int main(int argc, char *argv[])
{
// initialize COM
CoInitialize(NULL);

try
{
// instantiate the Developer Automation interface
_ISWiProjectPtr oISM(__uuidof(ISWiProject));

// open project read-write
#if IS10
int rc = oISM->OpenProject(_bstr_t("E:\\ISX_TEST\\IS10\\test1\\test1.ism"), VARIANT_FALSE);
#elif IS1050
int rc = oISM->OpenProject(_bstr_t("E:\\ISX_TEST\\IS1050\\test1\\test1.ism"), VARIANT_FALSE);
#endif

if ( rc == 0 )
{
// use GetXxxx syntax to get properties
_bstr_t bstrProductName = oISM->GetProductName( );
_bstr_t bstrProductVersion = oISM->GetProductVersion( );

// use (const char*) operator to cast the _bstr_t strings for cout
cout << "ProductName: " << (const char*)bstrProductName << endl;
cout << "ProductVersion: " << (const char*)bstrProductVersion << endl;

// save changes and clean up
oISM->SaveProject( );
oISM->CloseProject( );
}
}
catch(_com_error e)
{
// handle exceptions
cout << "*** Exception: " << (const char*)(e.Description( )) << endl;
}

CoUninitialize( );
return 0;
}

RobertDickau
01-25-2005, 10:50 AM
A quick sanity check: if you're using the Standalone build DLL, you'll need to make sure it's registered on a particular build machine. Perhaps reregister and try again (though it's odd the VBScript version worked...)?

GlenMiller
01-25-2005, 10:59 AM
I registered both SAAuto10.dll and SAAuto1050.dll on the clean build machine (I also re-registered both DLLs many times on my own machine while testing this). The code using SAAuto10.dll is working, so I assume everything is set up properly.

here is test1.zip, my 10.5 project file used in my sample (although the sample othello.ism project gives me the same problems).

RobertDickau
01-25-2005, 01:09 PM
As a test, does it work with the non-Standalone DLL (ISWiAutomation1050.dll)?

GlenMiller
01-25-2005, 01:41 PM
I haven't tried ISWiAutomation1050.dll on the 2nd (clean build) machine, but it does not work on my machine. This is the initial problem I had.

Can ISWiAutomation1050.dll be used on a clean build machine?

In summary, here's what I've tested so far:

- machine1 (my machine) has ISX and IS10.5 full installs
- machine2 has "clean build" installs of X and 10.5
- SAAuto10.dll is working from C++ on both machines
- SAAuto1050.dll is NOT working from C++ on both machines
- ISWiAutomation10.dll is working from C++ on machine1
- ISWiAutomation1050.dll is NOT working from C++ on machine1
- ISWiAutomation10.dll is working from VBScript on machine1
- ISWiAutomation1050.dll is working from VBScript on machine1

GlenMiller
01-31-2005, 01:48 PM
Has there been any progress on this?

We've ordered (or are the process of ordering) 3 licenses for IS10.5 Premier - which will be of little or no use to us if we can't get automation working.

RobertDickau
01-31-2005, 03:54 PM
Hmmm... The sample code I posted works with your test1.ism project, using ISWiAutomation1050.dll, anyway. As a sanity check, I assume the project isn't open in the development environment while you're running Automation code on it...

GlenMiller
02-02-2005, 03:56 PM
No, the project isn't open in the IDE. I am getting the same problem on a clean build machine, which doesn't even have the IDE installed.

There is obviously something different between the 10 and 10.5 DLL's, as automation using the 10 DLL's works consistently for me, while the 10.5 DLL's consistently do NOT work.

GlenMiller
02-03-2005, 09:49 AM
The 2 PCs that I am experiencing problems with (see earlier posts) are both developer workstations, running WinXP SP1 with VS .NET 2003.

I've also now tried to get this running (for further testing the automation problems) on 2 other PCs (both Win2K) and am getting the following error trying to compile the same project that builds OK on the XP PCs:

fatal error C1084: Cannot read type library file: 'E:\Program Files\Installshield X StandaloneBuild\SAAuto10.dll': Error loading type library/DLL.

I get the same error whether or not SAAuto10.dll is registered.

These Win2K PCs are the machines we actually use for our automated builds ... so, assuming I get the automation problems resolved with the 10.5 DLLs, I will eventually need to get my automation project building / running on these PCs as well. Or, upgrade them to WinXP? :(

icnocop
02-03-2005, 09:54 AM
Hello.

I, too, was having problems with the OpenProject method of the ISWiProject class.

However, I was getting a return value of 1.

In my case, I was also using the WindowsInstaller class and manipulating the database before using the ISWiProject class.

Since my automation task is written in C#, I had to explicitly call GC.Collect() after I was finished using the WindowsInstaller class so that my ism file would become unlocked and ready for the ISWiProject class.

Hope that helps (somebody).

RobertDickau
02-03-2005, 10:19 AM
Does this KB article have any bearing on the issue: http://support.installshield.com/kb/view.asp?articleid=Q108913?

GlenMiller
02-03-2005, 11:28 AM
That's the error. However, the article says to register the following files:

<ProgramFiles>\InstallShield\StandaloneBuild9\ismauto.tlb
<ProgramFiles>\Common Files\InstallShield\Shared\ismmupdater.tlb
<ProgramFiles>\InstallShield\DevStudio 9\System\iswibuild.dll
<ProgramFiles>\InstallShield\DevStudio 9\System\isappservices.dll

But only one of these files - ismauto.tlb - is available on a clean / standalone build PC. Registering only that file does not fix the error for me. Does a full install need to be done, so all these files can be registered, in order to fix this?

RobertDickau
02-03-2005, 03:54 PM
Hmmm... Perhaps the equivalent is IsAppSvc.dll in the Standalone directory (or IsAppServices.tlb in the same directory)?

GlenMiller
02-03-2005, 04:39 PM
IsAppSvc.dll won't self-register, and I've registered all the .tlb files in that folder (well, there's only two :)). I've even tried installing the SA build module from the CD (i had just xcopy'd it before). I've also tried registering a few other DLL's that looked important (some would register, some wouldn't).

I'm still getting the same error.

GlenMiller
02-09-2005, 02:37 PM
Hi Robert ... are you able to help me with this?

RobertDickau
02-09-2005, 03:08 PM
Just to back up a bit: is the compiler error the one to work out? At the beginning of the thread it seemed there were some run-time errors, but if those aren't issues any more...

Does VBScript work on any of your other test systems? You mentioned it worked on one system. Would using VBScript be a viable stop-gap measure?

GlenMiller
02-09-2005, 03:24 PM
They are both still issues.

I was getting run-time errors with the 1050 automation DLLs. So, in the meantime I have just been using the 10 automation DLLs for development / testing on my PC (WinXP). However, I later discovered the 10 automation DLLs won't even compile on our Win2K nightly build machines.

I'm not sure if VBScript will work for us. Our application generates a whole bunch of C preprocessor #define statements, which will be used by the automation code to configure the setup properly.

RobertDickau
02-09-2005, 03:30 PM
And how are you getting the Standalone system on a build system? By running the installer, or copying an existing expanded directory for it?

GlenMiller
02-09-2005, 03:36 PM
I have tried both methods - copying and registering (which worked fine for one of my WinXP test machines), and then installing it. Neither method worked on my Win2K test machines.

RobertDickau
02-09-2005, 03:59 PM
In that case, I'm not sure what it is; and I'm afraid I don't have a Windows 2000 system to test on. If VBScript isn't a viable option, this might be worth pursuing through http://mysupport.installshield.com...

icnocop
02-12-2005, 01:32 PM
I wonder what kind of errors you receive trying to register those dlls.

It may be a dependency issue. In that case, I would try and run depends.exe on the dlls to see if you have the minimum system requirements (ex. MFC dlls)

Patrickk
07-27-2005, 03:51 PM
I am getting the exact same error. My OS is WinXP. Developer 10.5 no upgrades. Visual Studio .Net 2003. I've tried even with Visual Studio 6.0 to no avail. I used the sample code in given in the earlier thread to avail as well. My code worked for Developer 10, but after I upgraded...ouch.
If another solution has been found, could you please forward it to me.

GlenMiller
07-27-2005, 04:19 PM
After logging a support request, the following solution has fixed the IS10 stand-alone system for me. I gave up on 10.5, as I seemed to be having all kinds of strange problems with it.


It appears that this issue can be resolved by copying the following files into the standalone build installation folder from a system that has the IDE installed:
C:\Program Files\InstallShield X\System\iswibuild.dll -> C:\Program Files\InstallShield X StandaloneBuild\
C:\Program Files\InstallShield X\System\isappservices.dll -> C:\Program Files\InstallShield X StandaloneBuild\
C:\Program Files\Common Files\InstallShield\Shared\ismmupdater.tlb -> C:\Program Files\InstallShield X StandaloneBuild\

Please try the following after adding the previously mentioned files to the InstallShield X standalone build folder:
1. Close Visual Studio.
2. Add the standalone build folder to the system path environment variable.
3. Reboot the machine.
4. Open Visual Studio and attempt to build your project.
5. If the project does not build the first time, please try building again as I have encountered unexpected behavior when attempting this.
I would have thought that the following article would have been updated with this information by now:

http://support.installshield.com/kb/view.asp?articleid=Q108913

Patrickk
07-28-2005, 02:27 PM
Thanks for your quick response Glen. I tried your suggestions on the 10.5 StandaAlone and was unable to get past the "Could not load library...for the SAAuto1050.dll". I think I will have to forgo using the tools that took me months to perfect until the next issue (Developer 11) as they seem content on not debugging this on a machine that is not theirs (developers machines always work). Apparently, they say the bug goes away if you don't use C++ or C#. Hmmm, interesting business philosophy :-(

Thanks,
Patrick

halciber
03-08-2006, 04:18 PM
By any chance is there a DevStudio 9 version of this example. I really need to get this to work in C++.

Thanks,
Mike Goldweber