AnyCPU "target platform" for C#/VB.NET and TurboActivate

Is it possible to use turboactivate with AnyCPU? I would prefer not to build/distribute two different versions of my app. If not, can you provide any information on how to dynamically load the correct dll?

Thanks,--Chad

Hey Chad,

Yes you can use TurboActivate with AnyCPU, but if you're making a .NET app we recommend making your app an x86 app. It's far easier and your app will be able to run on both 32-bit and 64-bit versions of Windows.

That being said, it's pretty easy to make your app use the x64 version of TurboActivate on the 64-bit version of Windows and the x86 version of TurboActivate on the 32-bit version of Windows. Here are the steps:

  1. Copy the x86 version of TurboActivate to your folder (both the .dll and .exe).
  2. Rename the x64 version of the TurboActivate.dll to "TurboActivatex64.dll"
  3. Copy the newly renamed dll to your app's folder (don't bother with the exe).
  4. Add the TurboActivate.cs or TurboActivate.vb class to your project.
  5. Make a copy of the internal "Native" class and call the copy "Native64"
  6. Make the Native64 class reference the "TurboActivatex64.dll" file instead of "TurboActivate.dll".
  7. Change the public functions in the main TurboActivate class to call the Native64 functions on x64 machines and the Native functions on x86 machines.

You can do the last step with the following simple code:

if (IntPtr.Size == 4){    //TODO: call the Native.FunctionName()}else // x64 machine{    //TODO: call the Native64.FunctionName()}

Tell me if this helps.

I have a similar need as Chad to compile my VB.NET code as AnyCPU. I have followed the above suggestions for deploying both 32 and 64 bit versions of TurboActivate.dll. It works on my Windows 7 64 bit machine as well as other 32 bit Vista and XP virtual machines I have set up. However, one of our clients in Japan keeps getting a 0x8007000B error on his 64 bit Windows 7 (Japanese) machine. Below are portions from my code (NET 2.0) that were adapted from suggestion in this forum.

Public Shared Sub Activate()

Select Case If(Is64BitProcess, Native64.Activate(), Native32.Activate()) Case 0 Return Case 2 Throw New InvalidProductKeyException Case 4 Throw New InternetException Case 5 Throw New PkeyMaxUsedException Case 6 Throw New PkeyRevokedException Case 8 Throw New ProductDetailsException Case 11 Throw New COMException End Select Throw New GeneralTurboActivateException("Failed to activate.") End Sub

Private Class Native64 <DllImport("TurboActivate64.dll", CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.Cdecl)> _ Public Shared Function Activate() As Integer End Function End Class

Private Class Native32 <DllImport("TurboActivate.dll", CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.Cdecl)> _ Public Shared Function Activate() As Integer End Function End Class

Since I am using NET 2.0, I am detecting 32 or 64 bits using the following routine:

<DllImport("kernel32.dll", SetLastError:=True, CallingConvention:=CallingConvention.Winapi)> _Private Function IsWow64Process(<[In]()> ByVal hProcess As IntPtr, <Out()> ByRef lpSystemInfo As Boolean) As <MarshalAs(UnmanagedType.Bool)> Boolean End Function

Public Function Is64BitProcess() As Boolean If IntPtr.Size = 8 OrElse (IntPtr.Size = 4 AndAlso Is32BitProcessOn64BitProcessor()) Then Return True Else Return False End If End Function

Private Function Is32BitProcessOn64BitProcessor() As Boolean Dim retVal As Boolean

IsWow64Process(Process.GetCurrentProcess().Handle, retVal)

Return retVal End Function

Any suggestions? I am at loss here as to why our Japanese customer is getting a 0x8007000B error and I am not. I hope to work this out so I can migrate all of our product licensing to LimeLM.

Thanks in advance,Garron

I am at loss here as to why our Japanese customer is getting a 0x8007000B error and I am not.

The problem is the 64 bit detection code. You're detecting when the process is 64-bit or the CPU is 64-bit. This will cause the crash on x86 versions of Windows on 64-bit processors. You need to only detect when your app is a 64-bit process.

So you can delete the "Is64BitProcess" and "IsWow64Process" functions and just use "IntPtr.Size = 8". For example:

    Public Shared Sub Activate()


        Select Case If(IntPtr.Size = 8, Native64.Activate(), Native32.Activate())            Case 0                Return            Case 2                Throw New InvalidProductKeyException            Case 4                Throw New InternetException            Case 5                Throw New PkeyMaxUsedException            Case 6                Throw New PkeyRevokedException            Case 8                Throw New ProductDetailsException            Case 11                Throw New COMException        End Select        Throw New GeneralTurboActivateException("Failed to activate.")    End Sub

Thanks for your suggested code modification. Our client in Japan confirmed that it worked. Now we can migrate our licensing to LimeLM.

Regards,Garron