Solved

dll help

Posted on 2002-06-13
3
182 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
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 33

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

18 Experts available now in Live!

Get 1:1 Help Now