Constructor in dll

General FreeBASIC programming questions.
deltarho[1859]
Posts: 1765
Joined: Jan 02, 2017 0:34
Location: UK

Re: Constructor in dll

Postby deltarho[1859] » May 04, 2019 7:55

I did some further work on this.

Case 1:
dll was originally a bas to be included with some main code. The included code called InitializeCryptoBuffers and that worked OK.

Case 2:
On conversion to a dll I reckoned that calling InitializeCryptoBuffers from within a dll would not work, assuming that a dll was passive, so exported it and called it from a PB program. That worked OK.

Case 3:
On realizing FB dlls are not passive InitializeCryptoBuffers was returned to being just a Sub to be called from within the dll. That did not work.

I then put ' Print "Init" ' at the head of InitializeCryptoBuffers and the print worked. ' Print "Init" ' was moved line by line until a failure. Here is where the failure occurred.

Code: Select all

  WaitForThreadpoolWorkCallbacks(Work0,FALSE)
  Print "Init"                                    ' <--- Print did not happen and code just stops
  WaitForThreadpoolWorkCallbacks(Work0plus,FALSE)
  ' We don't need Work0 related objects again.
  CloseThreadpoolWork(Work0)
  CloseThreadpoolWork(Work0plus)
End Sub

So, WaitForThreadpoolWorkCallbacks(Work0,FALSE) is the issue.

This does not make sense bearing in mind that Case 2 works.
dodicat
Posts: 5774
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Constructor in dll

Postby dodicat » May 04, 2019 11:07

I don't think running a function from within it's own dll is satisfactory as a rule of thumb.
You are too kind to your prospective PowerBASIC users, let them initialise things themselves.
External libs (gmp for example) require you to set up things yourself, nothing is automated there.
deltarho[1859]
Posts: 1765
Joined: Jan 02, 2017 0:34
Location: UK

Re: Constructor in dll

Postby deltarho[1859] » May 04, 2019 16:17

dodicat wrote:let them initialise things themselves.

It is not the end of the world. <smile>

Anyway, what I have learned from this is that dropping some executable code into a dll will see it get executed, and we don't need to mess about with Constructors. Seasoned FB users, or even seasoned dll writers for that matter, may think that obvious but I didn't.
fxm
Posts: 8975
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Constructor in dll

Postby fxm » May 04, 2019 17:45

The constructor/destructor and main code of a module are always executed, even if it is compiled as secondary module or static library or dynamic library (dll).

I think that with Quick Basic, only the main code of the main module was executed.

Return to “General”

Who is online

Users browsing this forum: No registered users and 2 guests