mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Feb 2003
Posts: 30
A
Ameglian cow
OP Offline
Ameglian cow
A
Joined: Feb 2003
Posts: 30
I did a little workup on how to create a mIRC DLL while having access to the .NET API, would this be a proper place to post this? Just want to check first before I get stoned.

Thanks.


Bluesock - Better than a redhat.
http://www.bluesock.com
Joined: Dec 2002
Posts: 3,127
P
Hoopy frood
Offline
Hoopy frood
P
Joined: Dec 2002
Posts: 3,127
In general, we dont object to, and in fact welcome, posts with, or links to, tutorials/howtos.

<insert standard warning about clicking on every url you see everywhere and using things you dont understand here> even tho i know Algorithms is relatively harmless grin





ParaBrat @#mIRCAide DALnet
Joined: Feb 2003
Posts: 30
A
Ameglian cow
OP Offline
Ameglian cow
A
Joined: Feb 2003
Posts: 30
[ XP Pro, VS.NET 7.0 & VS.NET 7.1, mIRC 6.0.3 ]

Well I have seen alot of people wanting to create DLLs with the ability to have access to the .NET Framework hopfully this little bit of code will help give you a skeleton to build on. Note: This example does not use garbage collection. So if you new something, delete it before you return.

I plan on coming up with a "COOL" example that will include garbage collection for your managed code and will implement Load and Unload methods, just don't have any ideas of what to do with a DLL.

This text makes some assumptions. It assumes you know how to use your compiler and how to properly compile the code below. This also assumes you know how to properly use the /dll and $dll() commands in mIRC. Also make note that the code in this document is provided as is and comes with no warranty, support, or garuantee to work.

I didn't think of anything "COOL" to use, so I just used .NET DateTime library and grabed the values for use in a $dll() call.

Below is your basic header, notice the extern "C" wrap.
Code:
// mIRC_DLL.h

#ifndef MIRC_DLL
#define MIRC_DLL
#endif // MIRC_DLL

extern "C"
{
    int __stdcall Hello(HWND mWnd, HWND aWnd,
        char* data, char* params, bool show, bool nopause);
}


Now we move to the source itself.
Code:
#include "stdafx.h"
#include &lt;cstring&gt;

// Include windows.h
#define WIN32_LEAN_AND_MEAN
#include &lt;windows.h&gt;

// .NET Framework goo
#using &lt;mscorlib.dll&gt;
using namespace System;

// DLL Project specific goo
#define MIRC_DLL 
#include "mIRC_DLL.h"

extern "C"
{
    namespace ax
    {
        char* StringToChar(String* s, char buf[255])
        {
            IntPtr p = Runtime::InteropServices::Marshal::StringToHGlobalAnsi(s);
            strcpy(buf, ((const char*) p.ToPointer()));
            Runtime::InteropServices::Marshal::FreeHGlobal(p);
            return buf;
        }
    }

    int __stdcall date_time(HWND mWnd, HWND aWnd, char* data,
                    char* params, bool show, bool nopause)
    {
        DateTime dt;
        char copy[255];
        char* _result = "\0";
        char* _tmp    = "\0";

        _tmp = ax::StringToChar(dt.Now.ToLongDateString(),copy);
        strcpy(_result, _tmp);
        
        lstrcpy(data, _result);
        return 3;
    }
}


And now finally the DEF file.
Code:
LIBRARY	mIRC_DLL
EXPORTS
    date_time @1


Now you can go in to mIRC and, //echo -a $dll(mirc_dll.dll,date_time,0). Not very useful, not the greatest tutorial, but great for those looking for a little nudge, enjoy.

This isn't to teach you how to create DLLs or how to program or managed C++ this is to show people coming from other languages who understand what is going on here a simple example to get them headed in the right direction.

If you have any general questions (please do not ask me things like "How do I make my DLL do <insert>") or comments please feel free, flames need not apply smirk


Bluesock - Better than a redhat.
http://www.bluesock.com
Joined: Feb 2003
Posts: 30
A
Ameglian cow
OP Offline
Ameglian cow
A
Joined: Feb 2003
Posts: 30
Code:
// mIRC_DLL.h
#ifndef MIRC_DLL
#define MIRC_DLL
#endif // MIRC_DLL
extern "C"
{
    int __stdcall date_time(HWND mWnd, HWND aWnd,
          char* data, char* params, bool show, bool nopause);
}


I used the old Hello example, sorry.


Bluesock - Better than a redhat.
http://www.bluesock.com

Link Copied to Clipboard