1. Olan Knight
  2. PowerBuilder
  3. Thursday, 13 February 2020 16:28 PM UTC

PB v12.1 b7055
Client/Server app
Windows 7 64 bit SP 1

Is there a way to get a unique ID for my current app?

Ideally I'l liketo get a unique LONG of STRING value that uniquely identifies the current instance of the app. That way if I have 3 instances of the same app running, I can tell the difference between them.

BTW:
   Handle(0) and FindWindowA() both return zero when APP_1 is running in a single instance.


Thanks,

Olan

Accepted Answer
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Thursday, 13 February 2020 19:35 PM UTC
  2. PowerBuilder
  3. # Permalink

Hi Olan;

   How about ...


FUNCTION long GetCurrentProcessId  (  )  LIBRARY "kernel32.dll"

long ll_pid
ll_pid = GetCurrentProcessId()

HTH - Regards ... Chris

Comment
  1. Olan Knight
  2. Thursday, 13 February 2020 20:17 PM UTC
Great, I will give it a try! Thank you!

Olan
  1. Helpful
  1. Olan Knight
  2. Thursday, 13 February 2020 20:26 PM UTC
Chris, that is exactly what I was seeking!



I ran multiple instances of the same app and displayed the ll_pid value in a messagebox,: values were different.

I then started and stopped the module that was getting the ll_pid, and for the same instance of the app the same ll_PID was displayed each time.



Perfect! Thank youfor sharing this!





Later -

Olan
  1. Helpful
  1. Chris Pollach @Appeon
  2. Friday, 14 February 2020 17:19 PM UTC
Hi Olan;

That is excellent news! :-)+

This is what I have used in my STD frameworks for ages to resolve this run-time unique instance aspect .

Regards ... Chris
  1. Helpful
There are no comments made yet.
Michael Kramer Accepted Answer Pending Moderation
  1. Thursday, 13 February 2020 19:02 PM UTC
  2. PowerBuilder
  3. # 1

Hi Olan,

Handle(GetApplication( ))  -- or in app's Open event -- Handle(this)

That function returns zero when you run your app from PB IDE (it runs subordinate to the PB IDE process).

However, run as separate executable it returns non-zero value!

Unfortunately, it returns the SAME non-zero value at each "Run" no matter how I start the .EXE.

HTH /Michael

Comment
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Thursday, 13 February 2020 17:50 PM UTC
  2. PowerBuilder
  3. # 2

Use the handle of an Application object when passing to GetProcessID:

Application la_app
Long ll_handle


la_app = GetApplication()

ll_handle = Handle(la_app)

 

Comment
  1. Olan Knight
  2. Thursday, 13 February 2020 18:43 PM UTC
Lovely! Thank you, Roland!
  1. Helpful
  1. Olan Knight
  2. Thursday, 13 February 2020 18:46 PM UTC
I just tested the code above. The la_app object is populated correctly, but the call to HANDLE returns a zero.

:(
  1. Helpful
  1. Roland Smith
  2. Thursday, 13 February 2020 19:05 PM UTC
It will be ZERO when run from the IDE. It will return a value only when run from an EXE.
  1. Helpful
There are no comments made yet.
Olan Knight Accepted Answer Pending Moderation
  1. Thursday, 13 February 2020 17:24 PM UTC
  2. PowerBuilder
  3. # 3

Update:
   The GetProcessID API requires a HANDLE, which is fine except that my problem is that the HANDLE I get from the PB function HANDLE and from the FindWindowA API is always zero. That's not going to work for me.  :/

   Heck, if the HANDLE returned a non-zero number that's what I would use.

   Ah well, back to Google....

~~~~~~~~~~~~~~~~~~~~~~~~~~

 

Thanks, Michael.
Using your tip I found the GetProcessID API:
   https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getprocessid

However, if Roland has already done the work in turning this into PowerBuilder code, I would be more than happy to steal, I mean "borrow", his code!  :)

Thanks Again,
Olan

 

 

Comment
There are no comments made yet.
Michael Kramer Accepted Answer Pending Moderation
  1. Thursday, 13 February 2020 17:03 PM UTC
  2. PowerBuilder
  3. # 4

Each app process has a unique process ID. Alternative if you want uniqueness also across VMs on same machine and across machines in general you could create new GUID value each time an app starts.

I don't remember the WIN API call to get process ID - but I expect you can find it between free code samples at TopWiz Programming.

I have C# assembly that calls the get new GUID. Many databases also have a GUID generator function. I'm sure WIN API also has a CreateNewGuid( ) function. I can post my C# code if relevant.

HTH /Michael

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.