1. C K
  2. PowerBuilder
  3. Sunday, 22 October 2023 09:16 AM UTC

Hello,

I have to send a text(string) message from C# application to PowerBuilder application via SendMessage function.

When i sent as a followinf code, Powerbulder's Message object doesnt got the stringparam' only long param

C# code: SendMessageW(long.Parse(args[0]), 7000000, 0, "k");

Thanks,

Chava.

 

John Fauss Accepted Answer Pending Moderation
  1. Sunday, 22 October 2023 15:10 PM UTC
  2. PowerBuilder
  3. # 1

Hi, Chava -

Is the C# code sending the address of an ANSI string or a Unicode 16LE (Little Endian) string? The SendMessageW WinAPI function is for “Wide” (i.e., Unicode) strings. Try using SendMessageA if sending the address of an ANSI-encoded string.

Also, if the PB app will be compiled to run as 64-bit, use Longptr data type instead of Long. 

Finally, I suggest you test with a small string first and verify the exchange works as intended, then scale up to larger-length values. 

Best regards, John

Comment
  1. Andreas Mykonios
  2. Monday, 23 October 2023 12:31 PM UTC
Then the longptr and x64 compilation that mentions John is irrelevant in your case.

Andreas.
  1. Helpful
  1. Roland Smith
  2. Monday, 23 October 2023 14:20 PM UTC
Message.StringParm is only for internal PowerBuilder object interactions. The SendMessage function will have the string memory address in the lparam event argument. To convert to a string in PB, do this: ls_msg = String(lparam, "address")

That being said, the PB app may not have access to the C# app's memory space. It might be better to use Winsock to send the message. I have a good example here: https://www.topwizprogramming.com/freecode_winsock.html
  1. Helpful
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Monday, 23 October 2023 09:03 AM UTC
  2. PowerBuilder
  3. # 2

Hi Chava,

If you are using PB 2022 there's another way of sending a string to PB:

https://docs.appeon.com/pb2022/application_techniques/Triggering_PowerScript_events_from_code.html

regards

Comment
There are no comments made yet.
Andreas Mykonios Accepted Answer Pending Moderation
  1. Monday, 23 October 2023 12:33 PM UTC
  2. PowerBuilder
  3. # 3

Are you sure that 7000000 is a valid value to send (second parameter)?

Andreas.

Comment
There are no comments made yet.
Benjamin Gaesslein Accepted Answer Pending Moderation
  1. Monday, 23 October 2023 13:24 PM UTC
  2. PowerBuilder
  3. # 4

Hi Chava,

SendMessage does not actually send a string but the memory address of a string in LongParm. To read the string from the address in LongParm, use the String() function like this:

string stringParm
stringParm = String(Message.LongParm, "address")
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.