Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Prevent duplicate loading of compiled C# DLL components.
#1
I've compiled some commonly used C# functions into a DLL. When I want to use them, I need to call static functions from the DLL using the code below.
Code:
Copy      Help
CsScript x.SetOptions("inMemoryAsm=false"); x.Load(":12 $qm$\pyn.dll")

However, if I want to use functions from the DLL in multiple places, I have to run the same loading code each time, which increases resource overhead.
 
Is it possible to implement logic similar to how native DLLs are loaded — that is, load the DLL only once in the main function, and then directly call its functions in other parts without reloading it?

Macro Todo2
Code:
Copy      Help
#sub ExeQmPlusDll
function!

;Use for qmplus.dll like ExeQmGridDll for qmgrid.dll.

#if EXE=1
#exe addfile "$qm$\qmplus.dll" 21089
int+ ___eqpd
if !___eqpd
,lock
,if !___eqpd
,,if !GetModuleHandle("qmplus.dll")
,,,_s.expandpath(F"$temp qm$\ver 0x{QMVER}\qmplus.dll")
,,,if !FileExists(_s)
,,,,if(!ExeExtractFile(21089 _s)) ret ;;also creates folders.
,,,if(!LoadLibraryW(@_s)) ret
,,___eqpd=1
#endif
ret 1
#2
Without installing VS or VSC, I’d like to use the following approach: compile the code of several classes into a single DLL, then load it once in a main function. After that, I want to call its functions from other functions or subfunctions associated with the main one, without reloading the DLL each time.

Is this possible to achieve? Thank you very much.

compileFiles=a.cs; b.cs; c.cs

Macro Macro4
Code:
Copy      Help
CsScript x
str Opt=
;searchDirs=$qm$
;references=System.Core;Microsoft.CSharp;netstandard
;compilerOptions=/warn:1
;compileFiles=a.cs;b.cs;c.cs
x.SetOptions(Opt)

str _="$qm$\all.dll"; x.Compile("" _)
#3
The following code has also been tested and works. If we use code similar to #2 above to compile multiple code files into a single DLL, and then share it among multiple functions associated with the main function, it becomes incredibly convenient.
 
How can we determine whether the DLL is already loaded? Is that possible?
Could you provide a sample reference code?

CsScript x.SetOptions("inMemoryAsm=true"); x.Load(":12 $qm$\pyn.dll")


Forum Jump:


Users browsing this thread: 1 Guest(s)