AnsweredAssumed Answered

get automation license in c#

Question asked by andrew_french on Feb 18, 2011
Latest reply on Mar 2, 2011 by mans.joling

this is how I used to do it in vb.net:

 

Private Function MGCPCB_licenseDoc(ByVal docOBJ As MGCPCB.Document) As Boolean

 

Dim licenseServer As Object

 

Dim key As Long

 

Dim licenseToken As Long

 

If Not docOBJ Is Nothing Then

key = docOBJ.Validate(0)

licenseServer = CreateObject("MGCPCBAutomationLicensing.Application")

 

If Not (licenseServer Is Nothing) Then

 

Try

licenseToken = licenseServer.GetToken(key)

docOBJ.Validate(licenseToken)

MGCPCB_licenseDoc =True

 

Catch

MsgBox("Unable to obtain automation license")

MGCPCB_licenseDoc =False

 

End Try

 

End If

licenseServer =Nothing

 

End If

 

End Function

 

This is what I've got in C# so far:

public

 

 

bool getAutomationLic()

{

 

 

object licenseServer;

 

 

long key;

 

 

long licenseToken;

key = ExpDoc.Validate(0);

licenseServer = Microsoft.VisualBasic.

 

Interaction.CreateObject("MGCPCBAutomationLicensing.Application");

 

 

if (licenseServer != null)

{

 

 

try

{

licenseToken = licenseServer.GetToken(key);

ExpDoc.Validate((

 

int)licenseToken);

}

 

 

catch { return false; }

 

 

return true;

}

}

 

The issue I am having is with the GetToken command, it doesn't seem to exist anymore or its not available in C#.  I think one way to solve this is if I used the correct type for the variable licenseServer.  What file do I need to reference to get access to the MGCPCBAutomationLicensing Data Model?  Anyway, I might not be asking the right question so if you know how to license automation in c# please share!

Outcomes