From WikiChip
Editing mirc/dynamic-link library

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

This page supports semantic in-text annotations (e.g. "[[Is specified as::World Heritage Site]]") to build structured and queryable content provided by Semantic MediaWiki. For a comprehensive description on how to use annotations or the #ask parser function, please have a look at the getting started, in-text annotation, or inline queries help pages.

Latest revision Your text
Line 21: Line 21:
 
=== Parameters ===
 
=== Parameters ===
 
* '''<filename>''' - The filename for the dll you wish to use.
 
* '''<filename>''' - The filename for the dll you wish to use.
* '''<procname>''' - The case-sensitive name of the function/procedure you wish to call.
+
* '''<procname>''' - The name of the function/procedure you wish to call.
* '''[data]''' - The optional parameters for the function/procedure, used by the procname as input and as return =2 command or =3 return string.
+
* '''[data]''' - The optional parameters for the function/procedure.
 
* '''<alias>''' - If you use {{mIRC|$dllcall}}, it calls the function asynchronously, meaning that the code won't stop processing until the dll function finishes, $dllcall won't return a value. Instead, mIRC calls the specified <alias> when the function finishes.
 
* '''<alias>''' - If you use {{mIRC|$dllcall}}, it calls the function asynchronously, meaning that the code won't stop processing until the dll function finishes, $dllcall won't return a value. Instead, mIRC calls the specified <alias> when the function finishes.
  
Line 29: Line 29:
 
'''Note''': We won't deal with how to create a dll in details, the scripter here must be familiar with dll creation already.
 
'''Note''': We won't deal with how to create a dll in details, the scripter here must be familiar with dll creation already.
  
Because mIRC wasn't unicode before, the exported functions used to be the following function prototype:
+
The exported functions must have the following function prototype:
 
 
<source lang="c">int __stdcall funcName(HWND mWnd, HWND aWnd, char *data, char *parms, BOOL show, BOOL nopause);</source>
 
 
 
With mIRC being unicode, the new prototype is:
 
 
 
<source lang="c">int __stdcall funcName(HWND mWnd, HWND aWnd, TCHAR *data, TCHAR *parms, BOOL show, BOOL nopause);</source>
 
  
 +
<source lang="c">#include <windows.h>
 +
int __stdcall funcName(HWND mWnd, HWND aWnd, char *data, char *parms, BOOL show, BOOL nopause);</source>
 
* '''mWnd''' - The handle of the main mIRC window.
 
* '''mWnd''' - The handle of the main mIRC window.
 
* '''aWnd''' - 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.
 
* '''aWnd''' - 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''' - This is a buffer you can write to if you want mIRC to perform a command or to return a value from a {{mIRC|$dll}} call (remember that {{mIRC|$dllcall}} do not return a value by design even if you fill this buffer)
+
* '''data''' - This is a buffer you can write to if you want mIRC to perform a command or to return a value from a {{mIRC|$dll}} call (remember that {{mIRC|$dllcall}} do not return a value by design even if you fill this buffer),
 
* '''parms''' - For a better handling of command execution, this is a buffer which can be filled if you are filling the 'data' buffer with a command. mIRC will fill the variable $1- with this value, which you can include in the command in 'data'. The examples shows how to use it.
 
* '''parms''' - For a better handling of command execution, this is a buffer which can be filled if you are filling the 'data' buffer with a command. mIRC will fill the variable $1- with this value, which you can include in the command in 'data'. The examples shows how to use it.
 +
 +
'''Note''': Both 'data' and 'params' are allocated with the Line Length Limit of mIRC, 4150 characters on mIRC 7.34 at the time of writting this (edit: 8292 chars on 7.55).
 +
 
* '''show''' - This Bool value is FALSE if a dot '.' has been used to make the command (/.dll) quiet.
 
* '''show''' - This Bool value is FALSE if a dot '.' has been used to make the command (/.dll) quiet.
 
* '''nopause''' - This Bool value is TRUE if mIRC is in a critical routine, meaning that you must not stop the processing in mIRC (long while loop for example).
 
* '''nopause''' - This Bool value is TRUE if mIRC is in a critical routine, meaning that you must not stop the processing in mIRC (long while loop for example).
 
 
If you call a non unicode dll with mIRC being unicode, mIRC must call the prototype with a char * and will convert its utf16 to utf8, and whenever this happens in mIRC, the data is chopped at $maxlenl+100 bytes.
 
 
Both 'data' and 'params' are allocated with a number of bytes that is close to ($maxlenl+100)*2+N where N is 100 or a bit more, and this is true both unicode and non unicode mode. This effectively mean that you can write that many bytes into the buffer yourself in both mode.
 
  
 
These functions must use the [[stdcall calling convention]]. (This is also the standard calling convention for all other [[Microsoft]] [[Win32 API]] functions.)
 
These functions must use the [[stdcall calling convention]]. (This is also the standard calling convention for all other [[Microsoft]] [[Win32 API]] functions.)
Line 72: Line 66:
  
 
* '''0''' - Means that mIRC should /halt processing.
 
* '''0''' - Means that mIRC should /halt processing.
* '''1''' - Means that mIRC should continue processing without returning the contents of the DATA buffer.
+
* '''1''' - Means that mIRC should continue processing.
 
* '''2''' - Means that you have filled the 'data' variable with a command which mIRC should perform, you can also fill the "parms" variable with the parameters to use, if any.
 
* '''2''' - Means that you have filled the 'data' variable with a command which mIRC should perform, you can also fill the "parms" variable with the parameters to use, if any.
 
* '''3''' - Means that the DLL has filled the data variable with the result that $dll() as an identifier should return.
 
* '''3''' - Means that the DLL has filled the data variable with the result that $dll() as an identifier should return.
Line 94: Line 88:
 
   BOOL  mKeep;
 
   BOOL  mKeep;
 
   BOOL  mUnicode;
 
   BOOL  mUnicode;
   DWORD mBeta;
+
   DWORD mBeta;
  DWORD  mBytes;
 
 
  } LOADINFO;</source>
 
  } LOADINFO;</source>
  
* '''mVersion''' - Contains the mIRC version number in the low and high words. i.e. version 7.55 fills this with 0x00370007
+
* '''mVersion''' - Contains the mIRC version number in the low and high words.
 
* '''mHwnd''' - Contains the window handle to the main mIRC window.
 
* '''mHwnd''' - Contains the window handle to the main mIRC window.
 
* '''mKeep''' - Is set to TRUE by default, indicating that mIRC will keep the DLL loaded after the call. You can set mKeep to FALSE to make mIRC unload the DLL after the call
 
* '''mKeep''' - Is set to TRUE by default, indicating that mIRC will keep the DLL loaded after the call. You can set mKeep to FALSE to make mIRC unload the DLL after the call
* '''mUnicode''' - If set to true, indicates that the dll is using unicode as opposed to ansi (default). This means the data passed from/to the dll is in UTF16 (see above with TCHAR type instead of CHAR). If set to false, mIRC will convert utf16 to utf8 to comply with the CHAR type prototype of the function
+
* '''mBeta''' - contains the mIRC beta version number, for public betas.
* '''mBeta''' - contains the mIRC $beta version number, for public betas.
+
* '''mUnicode''' - If set to true, indicates that text is in unicode as opposed to ansi (default). This means the data passed from/to the dll is in utf16, the prototype of the function becomes:
* '''mBytes''' - as of v7.64 contains the max safe byte length that can be placed into the 'data' and 'parms' buffers. This is always the double of the line length limit even when converting to utf8 with non unicode dll.
+
<source lang="c">int __stdcall funcName(HWND mWnd, HWND aWnd, wchar *data, wchar *parms, BOOL show, BOOL nopause);</source>Notice the difference for data and parms, which are now of the type wchar instead of char
  
 
== Unloading the Dll ==
 
== Unloading the Dll ==
Line 159: Line 152:
 
{
 
{
 
         //we fill data with a command we want mirc to execute
 
         //we fill data with a command we want mirc to execute
strcpy(data,"/echo -a è");
+
strcpy(data,"/echo -a é");
 
//we return 2 indicating mIRC should execute the command in 'data'.
 
//we return 2 indicating mIRC should execute the command in 'data'.
 
return 2;
 
return 2;
 
}
 
}
 +
  
 
extern "C" int __stdcall more_example(HWND mWnd, HWND aWnd, CHAR *data, char *parms, BOOL show, BOOL nopause)
 
extern "C" int __stdcall more_example(HWND mWnd, HWND aWnd, CHAR *data, char *parms, BOOL show, BOOL nopause)
Line 200: Line 194:
 
   BOOL  mKeep;
 
   BOOL  mKeep;
 
   BOOL  mUnicode;
 
   BOOL  mUnicode;
  DWORD  mBeta;
 
  DWORD  mBytes;
 
 
  } LOADINFO;
 
  } LOADINFO;
  
Line 212: Line 204:
 
extern "C" int __stdcall  UnloadDll(int mTimeout) {
 
extern "C" int __stdcall  UnloadDll(int mTimeout) {
 
//if dll is unloaded because mIRC exit or dll -u is used, we clean up, otherwise we prevent the unloading by returning 0.
 
//if dll is unloaded because mIRC exit or dll -u is used, we clean up, otherwise we prevent the unloading by returning 0.
if (mTimeout != 1)  
+
if (mTimeout != 1) CloseHandle(file);
        {
 
        UnmapViewOfFile(str);
 
        CloseHandle(file);
 
        }
 
 
return 0;
 
return 0;
 
}
 
}
 
</source>
 
</source>
  
Use $dll(yourdll.dll,simple_example,) which will return "simple string".
+
Use $dll(yourdll.dll,simple_example), which will return "simple string".
  
Use $dll(yourdll.dll,average_example,) or '/dll yourdll.dll average_example', this will execute "/echo -a è" in mIRC 7.x, because the project is not unicode, the two bytes è are sent as ascii, mIRC 7.x will correctly decode that as utf8. On mIRC 6.x (you would need to remove the mUnicode to mBytes variable in the LOADINFO structure), this would display the two bytes.
+
Use $dll(yourdll.dll,average_example) or /dll yourdll.dll average_example, this will execute "/echo -a é" in mIRC 7.x, because the project is not unicode, the two bytes é are sent as ascii, mIRC 7.x will correctly decode that as utf8. On mIRC 6.x (you would need to remove the mUnicode variable in the LOADINFO structure), this would display the two bytes.
  
 
If you set the mUnicode variable to TRUE on mIRC 7.x in the LoadDll function and if you set your project to use unicode (in visual studio: project properties > configuration properties > general > character set), this would correctly show the two bytes as well.
 
If you set the mUnicode variable to TRUE on mIRC 7.x in the LoadDll function and if you set your project to use unicode (in visual studio: project properties > configuration properties > general > character set), this would correctly show the two bytes as well.
  
Use $dll(yourdll.dll,more_example,) or '/dll yourdll.dll more_example' ;this will fill $1- from data with the value from parms and execute the final "//echo -a test".
+
Use $dll(yourdll.dll,more_example) or /dll yourdll.dll more_example, this will fill $1- from data with the value from parms and execute the final "//echo -a test".
  
 
Use $dll(yourdll.dll,from_event,$eventid) inside an event where $nick exists, this will use SendMessage() to evaluate $nick from the event context and fill data with that value, returned by $dll.
 
Use $dll(yourdll.dll,from_event,$eventid) inside an event where $nick exists, this will use SendMessage() to evaluate $nick from the event context and fill data with that value, returned by $dll.
  
Use $dll(yourdll.dll,usingSM,) which will use SendMessage() to execute a command in mIRC, it will also evaluate a line of code and return the result in $dll().
+
Use $dll(yourdll.dll,usingSM), which will use SendMessage() to execute a command in mIRC, it will also evaluate a line of code and return the result in $dll().
  
 
== Example 2 : Using GNU GCC on Windows (C) ==
 
== Example 2 : Using GNU GCC on Windows (C) ==

Please note that all contributions to WikiChip may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see WikiChip:Copyrights for details). Do not submit copyrighted work without permission!

Cancel | Editing help (opens in new window)