Example

The following example shows how to use the COM interface for the GPReg.dll. This example was created with Microsoft Visual Studio 2008 and written in Visual Basic. A COM reference was added to the project to provide access to the GPReg.dll. Text boxes were added to the main form of the sample to allow the user to enter the Microsoft Dynamics GP registration key information.

The following code was added to the form class. This code creates an instance of the GPRegKey object, sets the properties of this object based on the registration key information the user supplied, and then validates the registration keys. If they are valid, the total number of users allowed and the registration status of the Human Resources module are retrieved.

Public Class Form1
	Dim RegKey As New GPRegKey

	Private Sub Button1_Click(ByVal sender As System.Object, _
		ByVal e As System.EventArgs) Handles Button1.Click

		Dim numUsers As String
		Dim hrRegistered As String

		'Load the properties of the GPRegKey object with the registration
		'key values. For this example, the values come from text boxes
		'on a window.
		RegKey.CompanyName = txtCompanyName.Text
		RegKey.KeySeg1 = txtKey1.Text
		RegKey.KeySeg2 = txtKey2.Text
		RegKey.KeySeg3 = txtKey3.Text
		RegKey.KeySeg4 = txtKey4.Text
		RegKey.KeySeg5 = txtKey5.Text

		'After the properties have been set, the methods on the object
		'can be used. First, the registration keys should be verified
		'to see if they are valid. If they are, the other methods
		'can be used to retrieve information.
		If RegKey.IsValid() = True Then

			'Retrieve the number of users
			numUsers = RegKey.NumUsers().ToString()

			'Is the Human Resource module registered?
			If RegKey.IsModuleRegistered(43) = True Then
				hrRegistered = "Yes"
			Else
				hrRegistered = "No"
			End If

			'Dislay the results
			MsgBox("Number of users: " & numUsers & vbCrLf & _
			"Human Resources registered: " & hrRegistered)

		Else
			MsgBox("Registration keys are not valid.")
		End If

	End Sub
End Class