Common Language Runtime (CLR) in PB

Share your advanced PureBasic knowledge/code with the community.
User avatar
CELTIC88
Enthusiast
Enthusiast
Posts: 154
Joined: Thu Sep 17, 2015 3:39 pm

Common Language Runtime (CLR) in PB

Post by CELTIC88 »

hi all :D ,

Common Language Runtime (CLR) :
The Common Language Runtime (CLR), the virtual machine component of Microsoft's .NET framework, manages the execution of .NET programs. Just-in-time compilation converts the managed code (compiled intermediate language code), into machine instructions which are then executed on the CPU of the computer.[1] The CLR provides additional services including memory management, type safety, exception handling, garbage collection, security and thread management. All programs written for the .NET framework, regardless of programming language, are executed by the CLR. All versions of the .NET framework include CLR. The CLR team was started June 13, 1998.

CLR implements the Virtual Execution System (VES) as defined in the Common Language Infrastructure (CLI) standard, initially developed by Microsoft itself. A public standard defines the Common Language Infrastructure specification.[2]

With Microsoft's move to .NET Core, the CLI VES implementation is known as CoreCLR instead of CLR.

from https://en.wikipedia.org/wiki/Common_Language_Runtime


references :
https://code.msdn.microsoft.com/CppHostCLR-e6581ee0
https://www.codeproject.com/Articles/60 ... -Processes
https://www.ownedcore.com/forums/world- ... 0-clr.html
[....]

procedure :

load .net dll :
__CLR_Load_Dll(NetDllPath.s, ;full path to dll
RuntimeVersion.s = "v4.0.30319")


RuntimeVersion.s
The .NET Framework compilation version stored in the metadata, in the format "vA.B[.X]". A, B, and X are decimal numbers that correspond to the major version, the minor version, and the build number.

Note

This parameter must match the directory name for the .NET Framework version, as it appears under C:\Windows\Microsoft.NET\Framework or C:\Windows\Microsoft.NET\Framework64.

Example values are "v1.0.3705", "v1.1.4322", "v2.0.50727", and "v4.0.X", where X depends on the build number installed. The "v" prefix is required.

get Class
__CLR_GetClass(pdllAssembly.IAssembly, ; pdllAssembly returned by __CLR_Load_Dll
Class.s); class name to load


__CLR_Free_Inteface(pinterface.IUnknown) ; free interface

get object to use with COMatePLUS.pbi..... TODO
__CRL_GetObject(pdllAssembly.IAssembly, object.s)


call Member
__CLR_InvokeMember(pAssemblyIType.IType, ; class returned by __CLR_GetClass
Member.s, ; Member of class to call
psa) ; safe array for call Arguments.


*Tested on win7 x32

example code:

Code: Select all

IncludeFile "CLR.PBI"

;c# code
; using System.Windows.Forms;
; 
; namespace purebasic
; {
;     public class test
;     {
; 
; 		public Static string MsgBox(string message, string message2)
; 		{
; 			MessageBox.Show(message, message2);
; 			Return "By celtic88";
; 		}
; 
; 
; 	}
; }


Dim call_Arguments.Var(2) ; two Argument
call_Arguments(1)\type = #PB_String
call_Arguments(1)\STR = "test" ; first parameter type string
call_Arguments(2)\type = #PB_String
call_Arguments(2)\STR = "C# library" ; second parameter type string
psa = __CLR_CreateArguments(call_Arguments()) ; create safe array

dllAssembly = __CLR_Load_Dll("purebasic.net.dll") ; load c# library
class = __CLR_GetClass(dllAssembly, "purebasic.test") ; get class purebasic.test
Returnstring = __CLR_InvokeMember(class, "MsgBox", psa) ; call Member MsgBox with two Argument
Debug PeekS(Returnstring) ; return is string
__CLR_FreeArguments(call_Arguments()) ; free
__CLR_Free_Inteface(class); free
__CLR_Free_Inteface(dllAssembly); free
library used in example : https://www.mediafire.com/file/alz6n7g2 ... t.dll/file

CLR.PBI

Code: Select all

EnableExplicit

Interface ICLRMetaHost Extends IUnknown
  GetRuntime.l(wstr,struct,ptr)
  GetVersionFromFile.l(ptr,ptr,ptr)
  EnumerateInstalledRuntimes.l(ptr)
  EnumerateLoadedRuntimes.l(ptr,ptr)
  RequestRuntimeLoadedNotification.l(ptr,ptr,ptr)
  QueryLegacyV2RuntimeBinding.l(ptr,ptr)
  ExitProcess.l(INT.l)
EndInterface

Interface ICLRRuntimeInfo Extends IUnknown
  GetVersionString.l(ptr,ptr)
  GetRuntimeDirectory.l(ptr,ptr)
  IsLoaded.l(ptr,ptr)
  LoadErrorString.l(ptr,ptr,ptr,ptr)
  LoadLibrary.l(ptr,ptr)
  GetProcAddress.l(ptr,ptr)
  GetInterface.l(ptr,ptr,ptr)
  IsLoadable.l(*Bool)
  SetDefaultStartupFlags.l(ptr,ptr)
  GetDefaultStartupFlags.l(ptr,ptr,ptr)
  BindAsLegacyV2Runtime.l()
  IsStarted.l(ptr,ptr)
EndInterface

Interface ICLRRuntimeHost Extends IUnknown
  Start.l()
  Stop.l()
  SetHostControl.l(ptr)
  GetCLRControl.l(*ptr)
  UnloadAppDomain.l(ptr,ptr)
  ExecuteInAppDomain.l(ptr,ptr,ptr)
  GetCurrentAppDomainId.l(ptr)
  ExecuteApplication.l(ptr,ptr,ptr,ptr,ptr,ptr)
  ExecuteInDefaultAppDomain.l(wstr,wstr,wstr,wstr,*ptr)
EndInterface

Interface ICorRuntimeHost Extends IUnknown
  CreateLogicalThreadState.l()
  DeleteLogicalThreadState.l()
  SwitchInLogicalThreadState.l()
  SwitchOutLogicalThreadState.l()
  LocksHeldByLogicalThread.l()
  MapFile.l()
  GetConfiguration.l()
  Start.l()
  Stop.l()
  CreateDomain.l()
  GetDefaultDomain.l(*ptr)
  EnumDomains.l()
  NextDomain.l()
  CloseEnum.l()
  CreateDomainEx.l()
  CreateDomainSetup.l()
  CreateEvidence.l()
  UnloadDomain.l()
  CurrentDomain.l()
EndInterface

Interface AppDomain Extends IDispatch
  get_ToString.l()
  Equals.l()
  GetHashCode.l()
  GetType.l(ptr)
  InitializeLifetimeService.l()
  GetLifetimeService.l()
  get_Evidence.l()
  add_DomainUnload.l()
  remove_DomainUnload.l()
  add_AssemblyLoad.l()
  remove_AssemblyLoad.l()
  add_ProcessExit.l()
  remove_ProcessExit.l()
  add_TypeResolve.l()
  remove_TypeResolve.l()
  add_ResourceResolve.l()
  remove_ResourceResolve.l()
  add_AssemblyResolve.l()
  remove_AssemblyResolve.l()
  add_UnhandledException.l()
  remove_UnhandledException.l()
  DefineDynamicAssembly.l()
  DefineDynamicAssembly_2.l()
  DefineDynamicAssembly_3.l()
  DefineDynamicAssembly_4.l()
  DefineDynamicAssembly_5.l()
  DefineDynamicAssembly_6.l()
  DefineDynamicAssembly_7.l()
  DefineDynamicAssembly_8.l()
  DefineDynamicAssembly_9.l()
  CreateInstance.l()
  CreateInstanceFrom.l()
  CreateInstance_2.l()
  CreateInstanceFrom_2.l()
  CreateInstance_3.l()
  CreateInstanceFrom_3.l()
  Load.l()
  Load_2.l(bstr,*ptr)
  Load_3.l(ptr,*ptr)
  Load_4.l()
  Load_5.l()
  Load_6.l()
  Load_7.l()
  ExecuteAssembly.l()
  ExecuteAssembly_2.l()
  ExecuteAssembly_3.l()
  get_FriendlyName.l()
  get_BaseDirectory.l()
  get_RelativeSearchPath.l()
  get_ShadowCopyFiles.l()
  GetAssemblies.l()
  AppendPrivatePath.l()
  ClearPrivatePath.l()
  SetShadowCopyPath.l()
  ClearShadowCopyPath.l()
  SetCachePath.l()
  SetData.l()
  GetData.l()
  SetAppDomainPolicy.l()
  SetThreadPrincipal.l()
  SetPrincipalPolicy.l()
  DoCallBack.l()
  get_DynamicDirectory.l()
EndInterface

Interface IAssembly Extends IDispatch
  get_ToString.l(*bstr)
  Equals.l()
  GetHashCode.l()
  GetType.l(*ptr)
  get_CodeBase.l()
  get_EscapedCodeBase.l()
  GetName.l()
  GetName_2.l()
  get_FullName.l(*bstr)
  get_EntryPoint.l(*ptr)
  GetType_2.i(bstr.p-bstr, *type)
  GetType_3.l()
  GetExportedTypes.l()
  GetTypes.l(*ptr)
  GetManifestResourceStream.l()
  GetManifestResourceStream_2.l()
  GetFile.l()
  GetFiles.l()
  GetFiles_2.l()
  GetManifestResourceNames.l()
  GetManifestResourceInfo.l()
  get_Location.l()
  get_Evidence.l()
  GetCustomAttributes.l()
  GetCustomAttributes_2.l()
  IsDefined.l()
  GetObjectData.l()
  add_ModuleResolve.l()
  remove_ModuleResolve.l()
  GetType_4.l()
  GetSatelliteAssembly.l()
  GetSatelliteAssembly_2.l()
  LoadModule.l()
  LoadModule_2.l()
  CreateInstance.l(bstr,*variant)
  CreateInstance_2.l(bstr.p-bstr,bool.l,*variant)
  CreateInstance_3.l(bstr,bool.l,INT.l,ptr,ptr,ptr,ptr,*variant)
  GetLoadedModules.l()
  GetLoadedModules_2.l()
  GetModules.l()
  GetModules_2.l()
  GetModule.l()
  GetReferencedAssemblies.l()
  get_GlobalAssemblyCache.l()
EndInterface

Interface IMethodInfo Extends IDispatch
  ToString.l()
  Equals.l()
  GetHashCode.l()
  GetType.l()
  MemberType.l()
  name.l(*bstr)
  DeclaringType.l()
  ReflectedType.l()
  GetCustomAttributes.l()
  GetCustomAttributes_2.l()
  IsDefined.l()
  GetParameters.l()
  GetMethodImplementationFlags.l()
  MethodHandle.l()
  Attributes.l()
  CallingConvention.l()
  Invoke_2.l()
  IsPublic.l()
  IsPrivate.l()
  IsFamily.l()
  IsAssembly.l()
  IsFamilyAndAssembly.l()
  IsFamilyOrAssembly.l()
  IsStatic.l()
  IsFinal.l()
  IsVirtual.l()
  IsHideBySig.l()
  IsAbstract.l()
  IsSpecialName.l()
  IsConstructor.l()
  Invoke_3.l(ptr,ptr,ptr,ptr,ptr,ptr)
  returnType.l()
  ReturnTypeCustomAttributes.l()
  GetBaseDefinition.l()
EndInterface

Interface IType  Extends IDispatch
  get_ToString(bstr)
  Equals(variant,short)
  GetHashCode(INT)
  GetType(ptr)
  get_MemberType(ptr)
  get_name(bstr)
  get_DeclaringType(ptr)
  get_ReflectedType(ptr)
  GetCustomAttributes(ptr,short,ptr)
  GetCustomAttributes_2(short,ptr)
  IsDefined(ptr,short,short)
  get_Guid(ptr)
  get_Module(ptr)
  get_Assembly(ptr)
  get_TypeHandle(ptr)
  get_FullName(bstr)
  get_Namespace(bstr)
  get_AssemblyQualifiedName(bstr)
  GetArrayRank(INT)
  get_BaseType(ptr)
  GetConstructors(ptr,ptr)
  GetInterface(bstr,short,ptr)
  GetInterfaces(ptr)
  FindInterfaces(ptr,variant,ptr)
  GetEvent(bstr,ptr,ptr)
  GetEvents(ptr)
  GetEvents_2(INT,ptr)
  GetNestedTypes(INT,ptr)
  GetNestedType(bstr,ptr,ptr)
  GetMember(bstr,ptr,ptr,ptr)
  GetDefaultMembers(ptr)
  FindMembers(ptr,ptr,ptr,variant,ptr)
  GetElementType(ptr)
  IsSubclassOf(ptr,short)
  IsInstanceOfType(variant,short)
  IsAssignableFrom(ptr,short)
  GetInterfaceMap(ptr,ptr)
  GetMethod(bstr,ptr,ptr,ptr,ptr,ptr)
  GetMethod_2(bstr,ptr,ptr)
  GetMethods(INT,ptr)
  GetField(bstr,ptr,ptr)
  GetFields(INT,ptr)
  GetProperty(bstr,ptr,ptr)
  GetProperty_2(bstr,ptr,ptr,ptr,ptr,ptr,ptr)
  GetProperties(ptr,ptr)
  GetMember_2(bstr,ptr,ptr)
  GetMembers(INT,ptr)
  InvokeMember(bstr,ptr,ptr,variant,ptr,ptr,ptr,ptr,variant)
  get_UnderlyingSystemType(ptr)
  InvokeMember_2(bstr,INT,ptr,variant,ptr,ptr,variant)
  InvokeMember_3(bstr.p-bstr,INT,ptr,ptr,ptr,ptr,ptr,ptr,variant)
  
  GetConstructor(ptr,ptr,ptr,ptr,ptr,ptr)
  GetConstructor_2(ptr,ptr,ptr,ptr,ptr)
  GetConstructor_3(ptr,ptr)
  GetConstructors_2(ptr)
  get_TypeInitializer(ptr)
  GetMethod_3(bstr,ptr,ptr,ptr,ptr,ptr,ptr)
  GetMethod_4(bstr,ptr,ptr,ptr)
  GetMethod_5(bstr,ptr,ptr)
  GetMethod_6(bstr,ptr)
  GetMethods_2(ptr)
  GetField_2(bstr,ptr)
  GetFields_2(ptr)
  GetInterface_2(bstr,ptr)
  GetEvent_2(bstr,ptr)
  GetProperty_3(bstr,ptr,ptr,ptr,ptr)
  GetProperty_4(bstr,ptr,ptr,ptr)
  GetProperty_5(bstr,ptr,ptr)
  GetProperty_6(bstr,ptr,ptr)
  GetProperty_7(bstr,ptr)
  GetProperties_2(ptr)
  GetNestedTypes_2(ptr)
  GetNestedType_2(bstr,ptr)
  GetMember_3(bstr,ptr)
  GetMembers_2(ptr)
  get_Attributes(ptr)
  get_IsNotPublic(short)
  get_IsPublic(short)
  get_IsNestedPublic(short)
  get_IsNestedPrivate(short)
  get_IsNestedFamily(short)
  get_IsNestedAssembly(short)
  get_IsNestedFamANDAssem(short)
  get_IsNestedFamORAssem(short)
  get_IsAutoLayout(short)
  get_IsLayoutSequential(short)
  get_IsExplicitLayout(short)
  get_IsClass(short)
  get_IsInterface(short)
  get_IsValueType(short)
  get_IsAbstract(short)
  get_IsSealed(short)
  get_IsEnum(short)
  get_IsSpecialName(short)
  get_IsImport(short)
  get_IsSerializable(short)
  get_IsAnsiClass(short)
  get_IsUnicodeClass(short)
  get_IsAutoClass(short)
  get_IsArray(short)
  get_IsByRef(short)
  get_IsPointer(short)
  get_IsPrimitive(short)
  get_IsCOMObject(short)
  get_HasElementType(short)
  get_IsContextful(short)
  get_IsMarshalByRef(short)
  Equals_2(ptr,short)
EndInterface

Prototype.i CLRCreateInstance(*CLSID, *IID, *Inter)
Global mscoree_dll = OpenLibrary(#PB_Any, "mscoree.dll")
Global CLRCreateInstance.CLRCreateInstance = GetFunction(mscoree_dll, "CLRCreateInstance")

Prototype SafeArrayCreate(a,b,c)
Prototype SafeArrayAccessData(a,b)
Prototype SafeArrayUnaccessData(a)
Prototype SafeArrayDestroy(a)
Global OleAut32 = OpenLibrary(#PB_Any, "OleAut32.dll")
Global SafeArrayCreate.SafeArrayCreate = GetFunction(OleAut32, "SafeArrayCreate")
Global SafeArrayAccessData.SafeArrayAccessData = GetFunction(OleAut32, "SafeArrayAccessData")
Global SafeArrayUnaccessData.SafeArrayUnaccessData = GetFunction(OleAut32, "SafeArrayUnaccessData")
Global SafeArrayDestroy.SafeArrayDestroy = GetFunction(OleAut32, "SafeArrayDestroy")

Procedure __CLR_InvokeMember(pAssemblyIType.IType, Member.s, psa)
  If pAssemblyIType
    Protected pObject.VARIANT
    If pAssemblyIType\InvokeMember_3(Member,$158,0,0,0,0,0,psa,@pObject) = 0
      ProcedureReturn pObject\byref
    EndIf
  EndIf
EndProcedure

Procedure __CLR_GetClass(pdllAssembly.IAssembly, Class.s)
  If pdllAssembly
    Protected.IType gpAssemblyType, pAssemblyIType
    If pdllAssembly\GetType_2(Class,@gpAssemblyType) = 0
      gpAssemblyType\QueryInterface(?IID_IType,@pAssemblyIType)
      gpAssemblyType\Release()
    EndIf
  EndIf
  ProcedureReturn pAssemblyIType
EndProcedure

Procedure __CLR_Free_Inteface(pinterface.IUnknown)
  If pinterface <> 0 : pinterface\Release() : EndIf
EndProcedure

Procedure __CLR_Load_Dll(NetDllPath.s,RuntimeVersion.s = "v4.0.30319")
  Macro OnErrorGo(V,erp)
    If V <> 0 : errorpos = erp: Goto __Error : EndIf
  EndMacro
  Protected pClrHost.ICLRMetaHost
  Protected pRunInfo.ICLRRuntimeInfo
  Protected pRuntimeHost.ICLRRuntimeHost
  Protected pCorRuntimeHost.ICorRuntimeHost
  Protected.AppDomain gpAppDomain,pAppDomain
  Protected pMethodInfo.IMethodInfo
  Protected.IType gpType, pIType
  Protected IsLoadable
  Protected.IAssembly gpIAssembly,pAssembly
  Protected.IType gpAssemblyType, pAssemblyIType
  Protected.IAssembly gpdllAssembly,pdllAssembly
  Protected psa,ppData.i,*v.VARIANT,rgsabound.SAFEARRAYBOUND,pObject.VARIANT
  Protected errorpos
  
  OnErrorGo(CLRCreateInstance(?CLSID_CLRMetaHost,?IID_ICLRMetaHost,@pClrHost), 1)
  OnErrorGo(pClrHost\GetRuntime(@RuntimeVersion,?IID_ICLRRuntimeInfo,@pRunInfo), 2)
  OnErrorGo(pRunInfo\IsLoadable(@IsLoadable), 3)
  OnErrorGo(IsLoadable-1, 3)
  OnErrorGo(pRunInfo\GetInterface(?CLSID_CLRRuntimeHost,?IID_ICLRRuntimeHost,@pRuntimeHost), 4)
  OnErrorGo(pRuntimeHost\Start(), 5)
  OnErrorGo(pRunInfo\GetInterface(?CLSID_CorRuntimeHost,?IID_ICorRuntimeHost,@pCorRuntimeHost), 6)
  OnErrorGo(pCorRuntimeHost\Start(), 7)
  OnErrorGo(pCorRuntimeHost\GetDefaultDomain(@gpAppDomain), 8)
  OnErrorGo(gpAppDomain\QueryInterface(?IID_AppDomain,@pAppDomain), 9)
  OnErrorGo(pAppDomain\GetType(@gpType), 10)
  OnErrorGo(gpType\QueryInterface(?IID_IType,@pIType), 11)
  OnErrorGo(gpType\get_Assembly(@gpIAssembly), 12)
  OnErrorGo(gpIAssembly\QueryInterface(?IID_IAssembly,@pAssembly), 13)
  OnErrorGo(pAssembly\GetType(@gpAssemblyType), 14)
  OnErrorGo(gpAssemblyType\QueryInterface(?IID_IType,@pAssemblyIType), 15)
  
  rgsabound\lLBound = 0
  rgsabound\cElements = 1
  psa = SafeArrayCreate(#VT_VARIANT, 1, @rgsabound)
  If psa
    SafeArrayAccessData(psa, @ppData)
    *v = ppData
    *v\vt = #VT_BSTR
    *v\byref = SysAllocString_(NetDllPath)
    SafeArrayUnaccessData(psa)
  Else
    OnErrorGo(0, 16)
  EndIf
  If pAssemblyIType\InvokeMember_3("LoadFrom",$158,0,0,0,0,0,psa,pObject) <> 0
    OnErrorGo(pAssemblyIType\InvokeMember_3("LoadWithPartialName",$158,0,0,0,0,0,psa,pObject), 17)
  EndIf
  gpdllAssembly = pObject\byref
  OnErrorGo(gpdllAssembly\QueryInterface(?IID_IAssembly,@pdllAssembly), 18)
  
  __Error:
  
  If errorpos 
    Debug "error line : " + errorpos
  EndIf
  
  __CLR_Free_Inteface(pClrHost)
  __CLR_Free_Inteface(pRunInfo)
  __CLR_Free_Inteface(pRuntimeHost)
  __CLR_Free_Inteface(pCorRuntimeHost)
  __CLR_Free_Inteface(gpAppDomain)
  __CLR_Free_Inteface(pAppDomain)
  __CLR_Free_Inteface(pMethodInfo)
  __CLR_Free_Inteface(gpType)
  __CLR_Free_Inteface(pIType)
  __CLR_Free_Inteface(gpIAssembly)
  __CLR_Free_Inteface(pAssembly)
  __CLR_Free_Inteface(gpAssemblyType)
  __CLR_Free_Inteface(pAssemblyIType)
  __CLR_Free_Inteface(gpdllAssembly)
  
  If psa
    SafeArrayDestroy(psa)
  EndIf
  
  ProcedureReturn pdllAssembly
EndProcedure

Procedure __CRL_GetObject(pdllAssembly.IAssembly, object.s)
  Protected pObject.VARIANT
  If pdllAssembly
    pdllAssembly\CreateInstance_2(object,1,pObject)
  EndIf
  ProcedureReturn pObject\byref
EndProcedure

Structure Var
  SafeArray.i
  type.l
  STR.s
  *SystemStr
  INT.l
  double.d
  quad.q
  float.f
  word.w
EndStructure

Procedure __CLR_FreeArguments(Array Arguments.Var(1))
  Protected arsize = ArraySize(Arguments()), i
  If Arguments(0)\SafeArray
    SafeArrayDestroy(Arguments(0)\SafeArray)
  EndIf
  For i = 1 To arsize
    If Arguments(i)\type = #PB_String
      If Arguments(i)\SystemStr
        SysFreeString_(Arguments(i)\SystemStr)
      EndIf
    EndIf
  Next
EndProcedure

Procedure __CLR_CreateArguments(Array Arguments.Var(1)) 
  Protected psa,ppData.i,*v.VARIANT,rgsabound.SAFEARRAYBOUND,pObject.VARIANT, i
  Protected arsize = ArraySize(Arguments())
  rgsabound\lLBound = 0
  rgsabound\cElements = arsize
  psa = SafeArrayCreate(#VT_VARIANT, 1, @rgsabound)
  Arguments(0)\SafeArray = psa
  If psa
    SafeArrayAccessData(psa, @ppData)
    *v = ppData
    For i = 1 To arsize
      Select Arguments(i)\type
        Case #PB_String
          *v\vt = #VT_BSTR
          Arguments(i)\SystemStr = SysAllocString_(Arguments(i)\STR)
          *v\byref = Arguments(i)\SystemStr
        Case #PB_Long
          *v\vt = #VT_I4
          *v\byref = Arguments(i)\INT
        Case #PB_Double
          *v\vt = #VT_R8
          *v\byref = Arguments(i)\double
        Case #PB_Quad
          *v\vt = #VT_I8
          *v\byref = Arguments(i)\quad
        Case #PB_Float
          *v\vt = #VT_R4
          *v\byref = Arguments(i)\float
        Case #PB_Word
          *v\vt = #VT_I2
          *v\byref = Arguments(i)\word
      EndSelect
      *v + SizeOf(VARIANT)
    Next
    SafeArrayUnaccessData(psa)
  EndIf
  ProcedureReturn psa
EndProcedure
DisableExplicit


DataSection
  IID_ICLRMetaHost:
  Data.l $D332DB9E
  Data.w $B9B3, $4125
  Data.b $82, $07, $A1, $48, $84, $F5, $32, $16 
  
  CLSID_CLRMetaHost: 
  Data.l $9280188d
  Data.w $e8e, $4867
  Data.b $b3, $c, $7f, $a8, $38, $84, $e8, $de
  
  IID_ICLRRuntimeInfo:
  Data.l $BD39D1D2
  Data.w $BA2F, $486a
  Data.b $89, $B0, $B4, $B0, $CB, $46, $68, $91
  
  CLSID_CLRRuntimeHost:
  Data.l $90F1A06E
  Data.w $7712,$4762
  Data.b $86,$B5,$7A,$5E,$BA,$6B,$DB,$02
  
  IID_ICLRRuntimeHost:
  Data.l $90F1A06C
  Data.w $7712,$4762
  Data.b $86,$B5,$7A,$5E,$BA,$6B,$DB,$02
  
  CLSID_CorRuntimeHost:
  Data.l $cb2f6723
  Data.w $ab3a, $11d2
  Data.b $9c, $40, $00, $c0, $4f, $a3, $0a, $3e 
  
  IID_ICorRuntimeHost:
  Data.l $CB2F6722
  Data.w $AB3A,$11D2
  Data.b $9C,$40,$0,$C0,$4F,$A3,$A,$3E
  
  IID_AppDomain:
  Data.l $05F696DC
  Data.w $2B29,$3663
  Data.b $AD,$8B,$C4,$38,$9C,$F2,$A7,$13
  
  IID_IAssembly:
  Data.l $17156360
  Data.w $2F1A
  Data.w $384A
  Data.b $BC,$52,$FD,$E9,$3C,$21,$5C,$5B
  
  IID_MethodInfo:
  Data.l $FFCC1B5D
  Data.w $ECB8,$38DD
  Data.b $9B,$01,$3D,$C8,$AB,$C2,$AA,$5F
  
  IID_IType:
  Data.l $BCA8B44D
  Data.w $AAD6,$3A86
  Data.b $8A,$B7,$03,$34,$9F,$4F,$2D,$A2
EndDataSection
interested in Cybersecurity..
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: Common Language Runtime (CLR) in PB

Post by RSBasic »

Image
Image
Image
User avatar
CELTIC88
Enthusiast
Enthusiast
Posts: 154
Joined: Thu Sep 17, 2015 3:39 pm

Re: Common Language Runtime (CLR) in PB

Post by CELTIC88 »

RSBasic wrote:Image
:D you have tested?
interested in Cybersecurity..
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: Common Language Runtime (CLR) in PB

Post by RSBasic »

No, not yet. Its very interesting. Tonight I have time for testing.
Image
Image
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: Common Language Runtime (CLR) in PB

Post by RSBasic »

Hello CELTIC88

I tested your DLL but I get this error:
error line : 17
Tested with Windows 10 x64 and PB 5.70 LTS x86.

Do you need more information?
Image
Image
User avatar
CELTIC88
Enthusiast
Enthusiast
Posts: 154
Joined: Thu Sep 17, 2015 3:39 pm

Re: Common Language Runtime (CLR) in PB

Post by CELTIC88 »

stranger??? it's working !!!

Image

Make sure you use x86 pb
and call the library with the same class and method
interested in Cybersecurity..
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Common Language Runtime (CLR) in PB

Post by Kwai chang caine »

Hello CELTIC :wink:
I have an error at this line :|

Code: Select all

Procedure __CLR_Load_Dll(NetDllPath.s,RuntimeVersion.s = "v4.0.30319")
...
...
...

OnErrorGo(gpdllAssembly\QueryInterface(?IID_IAssembly,@pdllAssembly), 18) < ===== Error
I use W10 X64 / V5.70 X86
ImageThe happiness is a road...
Not a destination
User avatar
SnowyDog
User
User
Posts: 21
Joined: Tue Jun 10, 2014 8:18 pm

Re: Common Language Runtime (CLR) in PB

Post by SnowyDog »

Kwai chang caine wrote: Sat Aug 10, 2019 2:55 pm Hello CELTIC :wink:
I have an error at this line :|

Code: Select all

Procedure __CLR_Load_Dll(NetDllPath.s,RuntimeVersion.s = "v4.0.30319")
...
...
...

OnErrorGo(gpdllAssembly\QueryInterface(?IID_IAssembly,@pdllAssembly), 18) < ===== Error
I use W10 X64 / V5.70 X86
Ensure that in the first PureBasic line above you have specified the correct .NET Runtime version to match that used when the .NET library (DLL) you're trying to use was compiled (this must include the 'v' prefix) and also that the same .NET framework is installed on your machine. You can find out what .NET framework(s) you have installed by referring to one of the methods given here:-

https://docs.microsoft.com/en-us/dotnet ... -installed

SD
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Common Language Runtime (CLR) in PB

Post by Kwai chang caine »

Thanks for your help
I have try like you say, modify the version found on the registry "3.5.30729.5003" or "4.8.04084"
Anf this time i have an error "error line : 2" in debugger and an IMA line 608

Code: Select all

Debug PeekS(Returnstring) ; return is string
:|
But thanks when even to your help 8)
ImageThe happiness is a road...
Not a destination
User avatar
SnowyDog
User
User
Posts: 21
Joined: Tue Jun 10, 2014 8:18 pm

Re: Common Language Runtime (CLR) in PB

Post by SnowyDog »

Kwai chang caine wrote: Sun Jul 31, 2022 8:44 pm Thanks for your help
I have try like you say, modify the version found on the registry "3.5.30729.5003" or "4.8.04084"
Anf this time i have an error "error line : 2" in debugger and an IMA line 608

Code: Select all

Debug PeekS(Returnstring) ; return is string
:|
But thanks when even to your help 8)
Actually perhaps a better way to find the .NET runtime versions installed on your machine is to look in C:\Windows\Microsoft.NET\Framework and you'll see folders named with the versions. When specifying a version, use the exact folder name, for example "v2.0.50727" or "v4.0.30319" in PB with celtic88's code.

To resolve your problem, try changing the .NET runtime version requested (the second, optional call argument) when you load the DLL to "v2.0.50727", so the call to load the dll should now look like this:-

Code: Select all

dllAssembly = __CLR_Load_Dll("purebasic.net.dll","v2.0.50727") ; load c# library
This should hopefully solve both the errors you're getting. I just tested this using the original code provided by celtic88 with 6.00 LTS (Windows - x86) and it works fine. Before I made this change, I was also getting IMA error in __CLR_Load_Dll().
Post Reply