cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
cwilliamsson
Level 3

External C# dll to validate serial number

Please help me with this, I am fumbling in the dark trying to solve my problem using this community and knowledge base, but it certainly is not logical to figure this stuff out.

I am trying to include .dll file written in C# in a basic MSI project to validate serial number.

My method is called "validateSN" and has a string parameter and returns an int (0 or 1). I want to pass the ISX_SERIALNUM value to my method/function.


Here are my steps and questions:

1. When adding a custom action do I use standard dll or managed code?
a. Here is what I get when custom action is managed code:
Class1.validateSN(...)
b. Here is what I get when custom action is standard dll:
NUMBER=[LICENCE_OK]stskv2::validateSN(in STRING=[ISX_SERIALNUM]

2. Do I need to do anythinge else than in all the other options?
3. These are the events I am doing in the CustomerInformation Dialog:
- DoAction LicenceCheck 1
- NewDialog SetupType LICENSE_OK
- EndDialog Exit not LICENSE_OK

Does this look right? I am just returning 0 or 1 so honestly I dont understand where LICENSE_OK comes in, but I read it somewhere in this forum. Am I going in the right direction? Is this supposed to work? What might be wrong becuase it is just exiting out before really doing anything. I put a messagebox.show in my dll to see if it even enters the method, but it seems it is not.
Labels (1)
0 Kudos
(11) Replies
TsungH
Level 12

Custom actions have to return 0 (zero) for success (please see Custom Action Return Values). Hence, the return value of your custom action wouldn't be the most appropriate for LICENSE_OK property. There should be a separate out variable for LICENSE_OK property.

You can refer to "C:\Program Files\InstallShield\2011\Samples\WindowsInstaller\Managed Custom Actions" for an example.
0 Kudos
cwilliamsson
Level 3

OK....I got my code to run!!! YAYYYY!!! Thank you so much for pointing me in right direction for me to get some clues.

I seem to only have one issue left now, it is not exiting when serial number is unsuccessfule. I'm not sure what you mean by "separate out". Can you elaborate?

This is my C# method:

public int validateSN(string SN)
{
string serialmac = "";
string readmac = "";

serialmac = createMac(SN);
readmac = GetMacAddress();

if (serialmac == readmac)
{
return 0;
}
else
{
MessageBox.Show("Serialnumber is incorrect. Please try again or call support and provide this information for a new serial number: " + readmac);

return 1;
}


}
0 Kudos
cwilliamsson
Level 3

Actually, let me refrase that, I want the NewDialog to trigger only if it is successful. If unsuccessful I want it to do nothing. I guess I could have exit after a certain amount of tries, but that's secondary.

Right now NewDialog trigger all the time weather it is successful or not.

I've tried to set condition LICENSE_OK, LICENSE_OK="0", LICENSE_OK="1" and not LICENSE_OK, but none of those conditions makes a difference.
0 Kudos
TsungH
Level 12

I don't have VS and IS IDE at home, so hopefully I get the syntax correct.
public int validateSN(string SN, out string licenseOK)
{
string serialmac = "";
string readmac = "";

serialmac = createMac(SN);
readmac = GetMacAddress();

if (serialmac == readmac)
{
licenseOK = "0";
}
else
{
// Can do this with SpawnDialog ControlEvent
// personally, i will recommend against displaying literal string message inside a custom action.
// It makes localization, L10N, impossible.
MessageBox.Show("Serialnumber is incorrect. Please try again or call support and provide this information for a new serial number: " + readmac);

licenseOK = "1";
}
// return other value when an exception occurs or something.
// unless you are ignoring return code in your custom action, a non-zero return code indicates an installation error, and will stop installation.
return ERROR_SUCCESS;
}
In your 1b, it may look something like below. LICENSE_OK can then be used to control ControlEvents.[code]NUMBER=[SOME_RC]stskv2::validateSN(in STRING=[ISX_SERIALNUM], out STRING=[LICENSE_OK])[/code]As for why NewDialog ControlEvent keeps firing, check the value of LICENSE_OK property in Property table and also (more reliably) in verbose installation log, and refer to Condition column in ControlEvent Table. According to your 1b, you appear to be setting LICENCE_OK property.
0 Kudos
cwilliamsson
Level 3

Where can I find installation log?
0 Kudos
jwallenstein
Level 4

%temp% .
0 Kudos
TsungH
Level 12

Microsoft Windows Installer does not generate log by default. It can be turned on from inside the MSI file (MsiLogging Property, requiring Windows Installer 4.0 and later) , with Command-Line Options to msiexec.exe or by setting system Logging policy.
cwilliamsson wrote:
Where can I find installation log?
0 Kudos
erperez
Level 2

I have a custom DLL that validates the serial number entered by the user. I have set conditions on the Customer Information dialog to spawn a dialog on validation fail and to proceed to next screen on validation success. My problem is that I have to click the Next button twice in order for conditions to work properly. For example, on a fail serial clicking Next does nothing but clicking Next a second time launches the spawn dialog. Same thing with a valid serial, on first click nothing happens but clicking Next again proceeds to next screen. What gives?

Thanks in advance.
0 Kudos
TsungH
Level 12

My first guess is the sequence of ControlEvents may be off.
0 Kudos
erperez
Level 2

Yes, that was the issue. Thank you.
0 Kudos
Christopher_Pai
Level 16

Now that you have the basic pattern working, I'd just looking at WiX DTF CA's.
0 Kudos