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

Unknown Name error when accessing .NET dll

Hello, Macrovision Community! I need your help on a very frustrating issue.

I need to call a DLL to validate a license key during my installation. I'm writing a TEST installscript to prove the concept.

I am able to load the dll successfully with DotNetCoCreateObject but am receiving an 'Unknown Name' error with an error number of -2147352570 when attempting to access a public function.

My support files make it into the specified directory successfully. I've also written a C# test project to call the dll and pass a key and it works just fine.

Code snippets below:

Visual Studio AssemblyInfo.cs file:
[CODE]using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

//
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(true)]
ETC...[/CODE]

Visual Studio Validation.cs file:
using System;
using System.Collections;
using System.Text.RegularExpressions;
using ServerIdentifier;

namespace ServerValidation
{

///
/// Summary description for Validation.
///

public class Validation
{
//
// Member variables and constants
private static bool m_blnUseMachineIdentifier = true;

#region Public Interface

public static bool ValidateKey(string strKey)
{
if(ValidateMachineKey(strKey))
{
return true;
}
else
{
if(ValidateTimeKey(strKey))
{
return true;
}
else
{
return false;
}
}
}
ETC...


Installscript Code:
#define DLL_NAME "ServerValidation.dll" 
// Include Ifx.h for built-in InstallScript function prototypes.
#include "Ifx.h"
// Prototype MydllReturn in Mydll.dll.
//prototype BOOL ServerValidation.ValidateKey (BYVAL STRING);
//prototype BOOL ServerValidation.VerifyLoading ();
export prototype ExFn_UseDLL(HWND);

function ExFn_UseDLL(hMSI)
STRING svString;
INT nValue;
POINTER psvString;
NUMBER nResult;
BOOL bValidKey;
STRING szMSISUPPORTDIR;
STRING szPathCompletDll;
NUMBER nTemp;
OBJECT objValidateKey;
begin
//Get the path to the MSI SUPPORTDIR
MsiGetProperty(hMSI, "SUPPORTDIR", szMSISUPPORTDIR, nResult);
szPathCompletDll = szMSISUPPORTDIR ^ DLL_NAME;

// Load the .dll file into memory.
set objValidateKey = DotNetCoCreateObject( szPathCompletDll, "ServerValidation.Validation", "");

// bValidKey controls the following while loop.
bValidKey = FALSE;

// Loop while bValidKey is FALSE.
while (bValidKey = FALSE)

try
// Call ValidateKey .
bValidKey = objValidateKey.ValidateKey("0000-1111-2222-3333");
catch
/* Exception handler. */
//nTemp = Err.Number;
//svString = Err.Description;
/* Handle the exception based on its cause. */
SprintfBox (INFORMATION, "Error","Error occured: %i\n\n%s\n\n%s",
Err.Number, Err.Description, Err.LastDllError);
abort;
endcatch;

// Display the string to observe how it was altered by MydllReturn.
if (bValidKey) then
MessageBox ("Valid Key", INFORMATION);
else
MessageBox ("Invalid Key", INFORMATION);
endif;

endwhile;

end;


Thank you for your help!
Len
Labels (1)
0 Kudos
(4) Replies
RobertDickau
Flexera Alumni

One quick thing to test: in your InstallScript, does szPathCompletDll have the correct value? Your MsiGetProperty call to get SUPPORTDIR might fail if you haven't set the buffer-size variable nResult to a large enough value (say, MAX_PATH+1) before calling MsiGetProperty...
0 Kudos
ljfrench
Level 3

RobertDickau wrote:
One quick thing to test: in your InstallScript, does szPathCompletDll have the correct value? Your MsiGetProperty call to get SUPPORTDIR might fail if you haven't set the buffer-size variable nResult to a large enough value (say, MAX_PATH+1) before calling MsiGetProperty...


Robert,
I believe I have the correct value. I added a SprintfBox statement to check. szPathCompletDll is correct. I can leave the installer open and verify the DLL's presence in the temp folder.

I also placed the DLL in a static location and directed the installer to use that. Same problem.

Code snippet of my SprintfBox statement:

//Get the path to the MSI SUPPORTDIR
MsiGetProperty(hMSI, "SUPPORTDIR", szMSISUPPORTDIR, nResult);
SprintfBox(INFORMATION, "nResult", "%s\n\n%s\n\n%d\n\n%d", szMSISUPPORTDIR ^ DLL_NAME, szMSISUPPORTDIR, nResult, StrLength(szMSISUPPORTDIR));
0 Kudos
MichaelU
Level 12 Flexeran
Level 12 Flexeran

Might it help to remove static from public static bool ValidateKey(string strKey)? It strikes me as odd that one would try to call a static method from an object instance, COM or otherwise.
0 Kudos
ljfrench
Level 3

MichaelU wrote:
Might it help to remove static from public static bool ValidateKey(string strKey)? It strikes me as odd that one would try to call a static method from an object instance, COM or otherwise.


Right on, Michael! I thought about it after your post and I realized that the class methods would not be available to my instantiation of the class into my object in the installer.

I added a non-static method to the class and called the validation method from there. Works like a charm!

Quite a 'duh' moment.

Thank you again!

Len

😄 😄
0 Kudos