SendMessage to another application having trouble.

SendMessage(BBHwnd, BB_SETSTYLE, 0, LPARAM(FileN));

BBhwnd is set before this BB_SETSTYLE is a constant defined with the correct ID and FileN is a string containing a filename.

Im trying to send this to BlackBox and alt shell for windows made in c++ but it returns the error 'unable to open file "".' as if it is getting nothing.

Ive tryed alot of diff ways to send FileN and they either crash blackbox or get this error(see above).
ChessoAsked:
Who is Participating?
 
Wim ten BrinkSelf-employed developerCommented:
Problem is that you're trying to send an address from process 1 to process 2. The address is located in process 1. In process 2 there's just nothing at that address, thus it just fails. It's a bit similar to the usage of the WM_COPYDATA message. <quote> The data being passed must not contain pointers or other references to objects not accessible to the application receiving the data. While this message is being sent, the referenced data must not be changed by another thread of the sending process. The receiving application should consider the data read-only. The lParam parameter is valid only during the processing of the message. The receiving application should not free the memory referenced by lParam. If the receiving application must access the data after SendMessage returns, it must copy the data into a local buffer. </quote>
Sending data between processes can be a real pain if done through messages. It could well be that you have to use a global variable of type PChar somewhere that will contain the text that you will send over, just so the other process might still be able to process it. But even then there's a lot that could go wrong.
0
 
LRHGuyCommented:
This is a guess, but maybe it should be a pointer to the string:

SendMessage(BBHwnd, BB_SETSTYLE, 0, LPARAM(@FileN));
0
 
LRHGuyCommented:
Or maybe a pchar?

SendMessage(BBHwnd, BB_SETSTYLE, 0, LPARAM(pChar(FileN)));
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
ChessoAuthor Commented:
Ive already tryed both using pointer gets the same error and PChar crashes blackbox.
0
 
esoftbgCommented:
May be:
  SendMessage(BBHwnd, BB_SETSTYLE, Longint(Handle), Longint(@FileN));
0
 
ChessoAuthor Commented:
hmm nop still says unable to open file " " this is very strange ive seen plugins dev for blackbox that manage to succeed with this message but they are made in c++.
0
 
LRHGuyCommented:
Maybe you need to make sure the string is an ASCIIZ string on the heap. I tried this in a delphi pgm, and it works. The c++ program might still not be getting the data. (Also, have you verifyed then FileN is not empty?)

  P:pchar;

  getmem(P,length(FileN)+1);
  SendMessage(BBHwnd,BB_SetStyle,0,LParam(StrPCopy(P,FileN)));
  freemem(P,length(FileN)+1);
0
 
esoftbgCommented:
I have code for sending text between 2 Delphi applications, but both Sender-app and Receiver-app contain specific procedures i.e. it is not a one side process (Sender sends a string, Receiver decides what to do with the string) ....
0
 
ChessoAuthor Commented:
LRHGuy delphi says incompatible types: 'String' and 'PAnsiChar'

FileN does contain a filename and it is a string.
0
 
LRHGuyCommented:
Sorry, should be:

P:pAnsiChar;
0
 
ChessoAuthor Commented:
I think it's complaining about FileN being a string.

PChar? isnt a char a single character how would that work im only used to string/integer and such as i use them regularly.

I don't know if anyone would be interested but Blackbox is open source ive viewed the particular section where it handles BB_SETSTYLE but i dont know much about c++ so alot of it was garble to me lol.
0
 
LRHGuyCommented:
The sample compiled fine here in my D7, and it worked as I said, D7 to D7.

Here's my test routine...

procedure TForm2.Button2Click(Sender: TObject);
var
  P:pAnsiChar;
  FileN:String;
begin
  FileN:='test';

  getmem(P,length(FileN)+1);
  SendMessage(Handle,BB_SetStyle,0,LParam(StrPCopy(P,FileN)));
  freemem(P,length(FileN)+1);

end;
0
 
ChessoAuthor Commented:
Ok i did it right before im sure but it complained so i copied what you just wrote or the parts atleast that apply and it did compile but came up with an error why i tried to use it.

The instruction at "0x77f8ffde" refereced memory at "0x00c5a4dc". The memeory could not be "read".
0
 
ChessoAuthor Commented:
Iv'e just viewed the source for a plugin that switches styles called BBStyle a c++ dll plugin and it works using for example...

SendMessage(BBHwnd, BB_SETSTYLE, 0, (LPARAM)styletoset)

Not sure exactly what type styletoset is though but it works as a loaded plugin.
0
 
ChessoAuthor Commented:
im not going to bother nemore it just wont work ive managed to almost have the same thing in c++ and it is atleast saing undable to find file "@%#%^$" some characters not what i sent but still almost there. Ill split da points up
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.