OnlyOne Module Crossplattform

Share your advanced PureBasic knowledge/code with the community.
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Re: OnlyOne Module Crossplattform

Post by electrochrisso »

I get invalid memory access error on line 89, the window will not close - 5.21LTS(x86) - Intel Atom N550 :(
PureBasic! Purely the best 8)
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: OnlyOne Module Crossplattform

Post by ts-soft »

Update:
History wrote:; Version 1.1
; + IsWindow() in CloseWinCB()
; + Compiler OS Directive for PostEvent in CloseWinCB()
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Re: OnlyOne Module Crossplattform

Post by electrochrisso »

Hi ts-soft,
Not sure if the update was a fix to my problem, but I still get a crash when closing the window, perhaps its peculiar to this computer, I will try the code on my other laptops when I get some time.
PureBasic! Purely the best 8)
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: OnlyOne Module Crossplattform

Post by ts-soft »

I can't reproduce it and i miss the Info what OS-Version is used, Compiler-Settings ...
Comes the IMA with the example or with other source?
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: OnlyOne Module Crossplattform

Post by ts-soft »

Update:
History wrote:; Version 1.2
; - Removed the autoclean on #PB_Event_CloseWindow
; + ReleaseOne() to remove Timer and delete LockFile
; + changed Example to reflect the changes
I hope, this solve the problems by electrochrisso
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Poshu
Enthusiast
Enthusiast
Posts: 459
Joined: Tue Jan 25, 2005 7:01 pm
Location: Canada

Re: OnlyOne Module Crossplattform

Post by Poshu »

What if the application crash or is killed? You won't be able to restart it, right?
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: OnlyOne Module Crossplattform

Post by ts-soft »

Poshu wrote:What if the application crash or is killed? You won't be able to restart it, right?
No problem on windows. On other OS you can restart after <5 Minutes!
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Re: OnlyOne Module Crossplattform

Post by electrochrisso »

ts-soft wrote:Update:
History wrote:; Version 1.2
; - Removed the autoclean on #PB_Event_CloseWindow
; + ReleaseOne() to remove Timer and delete LockFile
; + changed Example to reflect the changes
I hope, this solve the problems by electrochrisso
Yes that update fixes the problem ts :)
Being new to modules, I am not sure what situations to use the code. :oops:
PureBasic! Purely the best 8)
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: OnlyOne Module Crossplattform

Post by ts-soft »

electrochrisso wrote:Being new to modules, I am not sure what situations to use the code. :oops:
Example: You have written a tabbed texteditor. You have registered the extension (Mime-Type) *.txt with your program.
With my module, you make sure your program runs only once. If the user open a textfile, you get the message with
the file to open in a new tab. No new instance of your program is started.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Re: OnlyOne Module Crossplattform

Post by electrochrisso »

ts-soft wrote:
electrochrisso wrote:Being new to modules, I am not sure what situations to use the code. :oops:
Example: You have written a tabbed texteditor. You have registered the extension (Mime-Type) *.txt with your program.
With my module, you make sure your program runs only once. If the user open a textfile, you get the message with
the file to open in a new tab. No new instance of your program is started.
Ok, now I see, this code will come in handy for certain types of applications, thanks for sharing. :)
PureBasic! Purely the best 8)
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Re: OnlyOne Module Crossplattform

Post by Foz »

An interesting take - I've always used a temporary port number instead of mutexes or files.

Code: Select all

InitNetwork()

If CreateNetworkServer(#PB_Any, 65000) = 0 ;<-- choose a port number in the range of 50000 - 65000 for an unused temporary port
  End
EndIf

MessageRequester("Yoohoo!", "I'm here!")
Of course in Windows that means you have to allow access to the network, so your code does win here as there is no "oh noes, the application is wanting to do something! It might be naughty!" of the UAC.

On the flipside, there is no file created, so if the application crashes, you can just just up and running again on the Linux and Mac systems.

I have to rethink my windows approach and use yours - cheers!
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: OnlyOne Module Crossplattform

Post by Tenaja »

I have found an annoyance. With Win7, the params, if files, are passed with the 8.3 shorthand...unfortunately, this means if you update the TitleBar with the filename, it is displayed in the truncated format.

Does anybody know how to expand it to the full filename?

thanks...
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: OnlyOne Module Crossplattform

Post by ts-soft »

You should always use #DQUOTE and not shortnames!
http://www.purebasic.fr/english/viewtop ... 24#p342324
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: OnlyOne Module Crossplattform

Post by Tenaja »

ts-soft wrote:You should always use #DQUOTE and not shortnames!
http://www.purebasic.fr/english/viewtop ... 24#p342324
Don't know where you suggest I use the DQ's--I wrapped the param filewrite with them, but that did not help. Then, I implemented your GetLongFromShort() and now it is working.

Thanks for the suggestion!
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: OnlyOne Module Crossplattform

Post by ts-soft »

On many windows-machines shortpathnames no more available. the creation is deactivated for performance reason on:
most server, most pcs using ssd, ...

Use

Code: Select all

param.s = #DQUOTE$ + "c:\Program Files\bla.txt" + #DQUOTE$
and not the shortnames.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Post Reply