Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct DLLFunc{
- private{
- field funchandle:i32;
- field dllhandle:i32;
- }
- function load(dllname:string, funcname:string):Bar{
- let dllhandle = load_dll(dllname);
- return Bar {
- dllhandle = dllhandle,
- funchandle = get_proc_by_addr(dllhandle, funcname)
- };
- }
- method invoke(self:ref DLLFunc, data:ref[] u8){
- dll_invoke(self->dllhandle, self->funchandle, data);
- }
- }
- instance Drop DLLFunc {
- function drop(val:in Bar){
- close_handle(val->funchandle);
- close_dll(val->dllhandle);
- }
- }
- instance Copy DLLFunc {
- function copy(target:out Bar, source:ref Bar){
- target->dllhandle = dup_dll(source->dllhandle);
- log("DLL Handle duped");
- target->funchandle = dup_funchandle(
- source->dllhandle,
- source->funchandle,
- target->dllhandle
- );
- log("Func Handle duped");
- }
- }
- global var logfunc:DLLFunc = DLLFunc::load("stdio", "_print");
- function log(message:string){
- logfunc->invoke(message.get_data());
- }
- function update_logger(func:ref DLLFunc){
- logfunc = *func;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement