Solved

dll help

Posted on 2002-06-13
3
202 Views
Last Modified: 2010-04-04
Now on to learning about DLLs.  Seems easy enough..
mIRC can use a DLL with this calling convention:

int __stdcall procname(HWND mWnd, HWND aWnd, char *data, char *parms, BOOL show, BOOL nopause)

  mWnd is the handle to the main mIRC window.
  aWnd is the handle of the window in which the command is being issued, this might not be the currently active window if the command is being called by a remote script.
  data is the information that you wish to send to the DLL. On return, the DLL can fill this variable with the command it wants mIRC to perform if any.
  parms is filled by the DLL on return with parameters that it wants mIRC to use when performing the command that it returns in the data variable.
( I'm not going to edit the boolean parameters )
----------------
I wrote this (conversion).  I want to assign a value to the 2 PChar parameters before returning a value of 2.
...
function TestString(mWnd,aWnd: THandle; data, parms: PChar; show,nopause: Boolean): integer; Stdcall;
begin
 data := '/msg $me ';
 parms := 'Successful test!';
 Result := 2;
end;

exports TestString;
begin
end.

----
It seems like I am assigning values to a local copy of the PChars as the caller is using the original default values after the call.  I need to plug the new Char-Strings into the memory slot where the original PChar values are (overwrite).  Am I close?

Don
0
Comment
Question by:d32coder
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 11

Accepted Solution

by:
robert_marquardt earned 200 total points
ID: 7077197
function TestString(mWnd,aWnd: HWND;
// not wrong, but this is better
 data, parms: PChar;
// BOOL is LongBool (program may crash otherwise)
show,nopause: LongBool): integer; Stdcall;

You assign a local variable (pointer) = data and parms to point to a new location (your literal string constants).
On return the parameter is deleted from the stack and you lose it.
You will have to hand in pointers to buffers and copy the data  to the location pointed to by the parameters.
Something like StrCopy.
0
 
LVL 34

Expert Comment

by:Slick812
ID: 7077213
I don't understand your TestString function? ? if you have defined the procname function from the DLL by

procname(mWnd,aWnd: THandle; data, parms: PChar; show,nopause: Boolean): integer; Stdcall;

then you could try to call it with

procedure TForm1.ButtonClick(Sender: TObject);
var
Result: Integer;
Data, Params: PChar;
hMirc: THandle;
begin
data := '/msg $me ';
parms := 'Successful test!';
hMirc := {some fuction to get MIRC handle}
Result := procname(hMirc,Handle, data, parms, True,False);
if Result = 2 then
ShowMessage('I got 2');
end;
0
 

Author Comment

by:d32coder
ID: 7077435
Exactly.  Thanks Robert.

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

734 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