Solved

SendMessage to another application having trouble.

Posted on 2004-10-30
165 Views
Last Modified: 2010-04-05
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).
0
Question by:Chesso
    15 Comments
     
    LVL 7

    Expert Comment

    by:LRHGuy
    This is a guess, but maybe it should be a pointer to the string:

    SendMessage(BBHwnd, BB_SETSTYLE, 0, LPARAM(@FileN));
    0
     
    LVL 7

    Expert Comment

    by:LRHGuy
    Or maybe a pchar?

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

    Author Comment

    by:Chesso
    Ive already tryed both using pointer gets the same error and PChar crashes blackbox.
    0
     
    LVL 12

    Assisted Solution

    by:esoftbg
    May be:
      SendMessage(BBHwnd, BB_SETSTYLE, Longint(Handle), Longint(@FileN));
    0
     

    Author Comment

    by:Chesso
    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
     
    LVL 7

    Expert Comment

    by:LRHGuy
    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
     
    LVL 12

    Expert Comment

    by:esoftbg
    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
     

    Author Comment

    by:Chesso
    LRHGuy delphi says incompatible types: 'String' and 'PAnsiChar'

    FileN does contain a filename and it is a string.
    0
     
    LVL 17

    Accepted Solution

    by:
    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
     
    LVL 7

    Expert Comment

    by:LRHGuy
    Sorry, should be:

    P:pAnsiChar;
    0
     

    Author Comment

    by:Chesso
    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
     
    LVL 7

    Assisted Solution

    by:LRHGuy
    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
     

    Author Comment

    by:Chesso
    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
     

    Author Comment

    by:Chesso
    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
     

    Author Comment

    by:Chesso
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: From Zero to Hero with Nodejs & MongoDB

    Interested in Node.js, but don't know where to start or how to learn it properly? Confused about how the MEAN stack pieces of MongoDB, Expressjs, Angularjs, and Nodejs fit together? Or how it's even possible to run JavaScript outside of the browser?

    Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
    Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
    This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    913 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now