Ooops
January 16, 2021, 09:48:13 PM

Author Topic: Closing DLL LIB  (Read 914 times)

Offline Derron

  • Hero Member
  • *****
  • Posts: 3331
Re: Closing DLL LIB
« Reply #15 on: December 29, 2020, 07:59:06 PM »
Reading your code I assume you compile with "legacy" ?

Asking as you return something in a function without defining the return type.


@ DLL
Yes it is executing everything in the file ... this is why you need to wrap stuff in functions.

Also something of importance is that (at least in NG) the GC will not work within the DLL code until you called "InitBRL()" once.

So my BlitzMax-DLL (which controls a 3rd party DLL and wraps stuff for a example client written in BlitzMax NG) uses stuff like this:
Code: BlitzMax
  1. SuperStrict
  2.  
  3. Framework brl.standardIO
  4.  
  5. Global versionPtr:Byte Ptr = "My DLL. Version 0.1 [2020/12/29]".ToCString()
  6.  
  7. 'Retrieve string with name, version and build date
  8. 'returns: Pointer to a constant string
  9. Function MyDLL_GetVersion:Byte Ptr() Export "Win32"
  10.         InitDLL()
  11.         Return versionPtr
  12. End Function
  13.  
  14.  
  15. Global dllInitDone:Int = False
  16. Function InitDLL:Int()
  17.         If dllInitDone Then Return True
  18.        
  19.         InitBRL()
  20.         dllInitDone = True
  21.         Return True
  22. End Function
  23.  

Using the DLL:
Code: BlitzMax
  1. SuperStrict
  2.  
  3. Framework Brl.StandardIO
  4. Import pub.win32
  5.  
  6. Function LoadLib:Byte Ptr(url:String)
  7.         Local handle:Byte Ptr = LoadLibraryW(url)
  8.         If Not handle
  9.                 Print "Failed to load library ~q"+url+"~q"
  10.                 'Notify "Failed to load library ~q"+url+"~q"
  11.                 End
  12.         Else
  13.                 Print "Loaded library ~q"+url+"~q"
  14.         EndIf
  15.         Return handle
  16. End Function
  17.  
  18. Print "Loading DLLs"
  19. Global dllHandle:Byte Ptr = LoadLib("mydll.dll")
  20.  
  21. Global MyDLL_GetVersion$z() = GetProcAddress(dllHandle, "MyDLL_GetVersion")
  22.  
  23. Print "myDLL version: " + MyDLL_GetVersion()
  24.  

This also shows how to transport a string from the DLL to the client in a way that the (BlitzMax) client does the necessary memfree of this string afterwards.


I do not have to "close" the file - but of course I need to handle closing stuff like open device connections (my DLL controls a DLL which communicates with some hardware, a second DLL I wrote communicates directly with some hardware to set it up and run measurements).

Instead of replacing DLLs when doing mockups I have my DLL do the mockup stuff for me - so I cannot say if replacing the DLLs works flawlessly or needs some additional steps not done yet in NG for you.


bye
Ron

Offline col

  • Sr. Member
  • ****
  • Posts: 474
Re: Closing DLL LIB
« Reply #16 on: December 30, 2020, 01:06:19 AM »
@Hardcoal
For clarity... what language is the dll written in?
To be is to be perceived.

https://github.com/davecamp

Offline Hardcoal

  • Hero Member
  • *****
  • Posts: 531
  • nothing is personal
Re: Closing DLL LIB
« Reply #17 on: December 30, 2020, 02:16:02 AM »
this is a dll made on blitzmax.. i thought its clear :)
Lets make the world a better place

Offline Hardcoal

  • Hero Member
  • *****
  • Posts: 531
  • nothing is personal
Re: Closing DLL LIB
« Reply #18 on: December 30, 2020, 02:20:44 AM »
The reason i want to close the library is because i want to reload it after making changes..
none of the examples above worked.. its still gets stuck..

ill keep trying to figure it out lol :)
Lets make the world a better place

Offline Hardcoal

  • Hero Member
  • *****
  • Posts: 531
  • nothing is personal
Re: Closing DLL LIB
« Reply #19 on: December 30, 2020, 02:26:17 AM »
Ok i just realized that it doesnt crash, it keeps playing the code.. until it reaches the command Until... which suppose to make it loop
and than it ignores it lol..

but only in my Dll Case.. not on external dlls.. which is not made with blitzmax

Code: [Select]

Strict

Import pub.Win32

?Win32

'Import "-lshell32"
   
Extern "Win32"
Function FreeLibrary:Int(hModule:Int)
End Extern

?



Graphics (800, 600)

Global WantedLib:String = "DllsToBeCompiled/MyDllLib.dll"

Local CurrentText:String

#danny
Repeat

     Cls
 
Local A

If KeyHit(KEY_1) Then
  Local Library
 
  DrawText ("Reading Lib", 50, 50)

Library = LoadLibraryA (WantedLib)
If Not Library Then LibError(WantedLib)

'Local PrintSomething:String() = GetProcAddress (Library, "PrintSomething")
'Print PrintSomething()
'PrintSomething = Null

FreeLibrary(Library)

Delay (100)

Print "DoneFree"

A = 1

  End If

  DrawText("Press 1 to load Lib", 10, 10)
  DrawText(CurrentText, 10, 30)
 
  If A = 1 Then Print "A=1"
 
  Flip
 
Until KeyDown(KEY_ESCAPE)

'--------------------------------'

Function LibError(LibURL:String)
Notify "Library not Loaded or not Found:   " + LibURL
End Function

Lets make the world a better place

Offline Hardcoal

  • Hero Member
  • *****
  • Posts: 531
  • nothing is personal
Re: Closing DLL LIB
« Reply #20 on: December 30, 2020, 03:40:13 AM »
Ok i managed to make it work.. after i do freelibrary i just load it again..
but before loading i did a compile function so.. it compiles the dll and when i reload it, its already modified..

so now i can modify a dll while the program is running and get different outcome.

lets see if i can put it into a good use
Lets make the world a better place

Offline DruggedBunny

  • Jr. Member
  • **
  • Posts: 65
Re: Closing DLL LIB
« Reply #21 on: December 30, 2020, 04:09:08 AM »
You can navigate around this by ending your declaration with  ! . This means 'use this above all else'
Ohhh, that's interesting!

I've run into this Win32 duplicate definition error so many times in NG and never worked out how to get around it! Seems like a bug that it has the Win32 defines but doesn't let you use them.

Offline Henri

  • Sr. Member
  • ****
  • Posts: 288
Re: Closing DLL LIB
« Reply #22 on: December 30, 2020, 12:15:29 PM »
Its not a bug as such but a consequence of transpiling BMax code to C code as I understand it (in C those definitions are in a header file that are then included in the c-file where they are needed). In order for external function to be available in the scope of your app it needs to be included/imported or defined in your app file. Some of the Windows API function are already defined in Blitzmax modules like LoadLibraryW, which is why you do not have to define again (in my example I use it but do not define it as the Framework keyword is omitted thereby all modules are imported).

If I need external Windows function I usually define them in a file and import that file in my main app file (or whatever file needs to use them) and sometimes you may find the needed function in pub.mod/win32.mod - folder and you just need to import one of those.

-Henri
- Got 01100011 problems, but the bit ain't 00000001

Offline Hardcoal

  • Hero Member
  • *****
  • Posts: 531
  • nothing is personal
Re: Closing DLL LIB
« Reply #23 on: December 30, 2020, 01:38:52 PM »
Henry..

like i said im making my own dll's and i needed to solve the problem which i have..
and thats all what matters to me..

maybe you didnt understand what i was trying to do..

ill post the code in the future when its ready
Lets make the world a better place

Offline Henri

  • Sr. Member
  • ****
  • Posts: 288
Re: Closing DLL LIB
« Reply #24 on: December 30, 2020, 01:53:14 PM »
Its okay, I was just answering to DruggedBunny.

-Henri
- Got 01100011 problems, but the bit ain't 00000001

Offline Hardcoal

  • Hero Member
  • *****
  • Posts: 531
  • nothing is personal
Re: Closing DLL LIB
« Reply #25 on: December 30, 2020, 03:34:46 PM »
ah lol. sorry :)
Lets make the world a better place

Offline Hardcoal

  • Hero Member
  • *****
  • Posts: 531
  • nothing is personal
Re: Closing DLL LIB
« Reply #26 on: December 30, 2020, 05:22:41 PM »
Ok Ive managed to recompile a Type while the program is running..
and reuse it. making changes.. to it.. without stopping the run process.

but I need one more step to make it what i really desire..
Ill be surprised if it actually works..

Code: [Select]
Type Example_Type

    Method Play()
        Print "Testing"
    End Method

End Type
Lets make the world a better place

Offline Hardcoal

  • Hero Member
  • *****
  • Posts: 531
  • nothing is personal
Re: Closing DLL LIB
« Reply #27 on: January 05, 2021, 09:26:50 PM »
I made a little DLL Maker..
Its basic.. so dont expect too much

https://1drv.ms/u/s!ArSvOuhm7L3kr5c-rKPPA2hc7miivw?e=VaP2vl
Lets make the world a better place

Offline Dabz

  • Sr. Member
  • ****
  • Posts: 348
  • Is it cos I is ginger?
    • dabzy.co.uk
Re: Closing DLL LIB
« Reply #28 on: January 05, 2021, 11:31:23 PM »
Seems to work! :)

Though, for anyone else that wonders why a DLL doesnt turn up and only a def file, after first run, you'll need to change the "D:\PORTABLE\BlitzMax\bin" bit in the Compiler.bat file that appears, to the path to the blitzmax/bin folder on your machine, then, execute the bat file as normal and everything will appear.

Dabz
Intel Core i5 6400 2.7GHz, NVIDIA GeForce GTX 1070 (8GB), 16Gig DDR4 RAM, 256GB SSD, 1TB HDD, Windows 10 64bit

Offline Hardcoal

  • Hero Member
  • *****
  • Posts: 531
  • nothing is personal
Re: Closing DLL LIB
« Reply #29 on: January 06, 2021, 03:06:30 AM »
ah lol right I forgot about that TY Dabz..

I still didnt implement a process to ignore Remarks when reading the Source BMX File. for example.. ( ' or Rem, End Rem )
and other types of parsing error preventers are still not Added..

but by the complaints ill get ill fix errors and make improvements..

Thats why I called it version 0.1

much easier than actually thinking :)

[Hour Later] Ok I fixed it and improved it..
 waiting for more remarks..
 If you like what I did, Ive got more surprises
Lets make the world a better place

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal