da-hype
22-08-2004, 02:17 PM
This is a DLL i'm trying to complete. It keeps crashing mirc. god know why. anyone know why? need help bad...............
#include <windows.h>
//#include <Richedit.h>
BOOL fCanStop = 0;
//some globals and structs
typedef struct tagLOADINFO
{
DWORD mVersion;
HWND mHwnd;
BOOL mKeep;
}LOADINFO,*LPLOADINFO;
HINSTANCE hInst = 0; //the handle to our dll
HWND hMirc = 0;
HANDLE hThread = 0;
DWORD dwThreadId = 0;
//just having this function and exporting will make mIRC keep the dll loaded
void __stdcall LoadDll(LPLOADINFO li)
{
hMirc = li->mHwnd;
}
//called when the dll is unloaded. Since DllMain is also called when the dll is loaded or unloaded
//i use it to handle installing/removing the hook. Windows is more reliable than mIRC because mIRC's behaviour
//could be changed in any version
int __stdcall UnloadDll(int timeout)
{
if (!timeout)
{
return 1;
}
return 0;
}
DWORD WINAPI WorkerThread(LPVOID lpvData)
{
while(!fCanStop)
{
HWND hWnd = FindWindowEx(0,0,0,"mIRC Scripts Editor");
if (IsWindow(hWnd))
{
SendMessage(GetDlgItem(hWnd,0x012C),EM_SETREADONLY,1,0);
//SendMessage(hWnd,EM_SETBKGNDCOLOR,0,RGB(221,225,223));
//SendMessage(hWnd,WM_COMMAND,MAKEWPARAM(2,BN_CLICKED),(LPARAM)GetDlgItem(hWnd,2));
}
}
return 0;
}
//lets get some defines going to make things easier
#define f(x) int __stdcall x(HWND,HWND,char*,char*,BOOL,BOOL)
BOOL WINAPI DllMain(HINSTANCE h,DWORD dwReason,LPVOID lpv)
{
switch(dwReason)
{
//the dll is being loaded
case DLL_PROCESS_ATTACH:
hInst = h;
break;
//dll is being unloaded.
case DLL_PROCESS_DETACH:
fCanStop = 1;
break;
}
return TRUE;
}
//this function is called by our script using /dll. It installs the hook wich monitors certain events for us
f(Lock)
{
hThread = CreateThread(NULL,NULL,WorkerThread,0,0,&dwThreadId);
return 0;
}
#include <windows.h>
//#include <Richedit.h>
BOOL fCanStop = 0;
//some globals and structs
typedef struct tagLOADINFO
{
DWORD mVersion;
HWND mHwnd;
BOOL mKeep;
}LOADINFO,*LPLOADINFO;
HINSTANCE hInst = 0; //the handle to our dll
HWND hMirc = 0;
HANDLE hThread = 0;
DWORD dwThreadId = 0;
//just having this function and exporting will make mIRC keep the dll loaded
void __stdcall LoadDll(LPLOADINFO li)
{
hMirc = li->mHwnd;
}
//called when the dll is unloaded. Since DllMain is also called when the dll is loaded or unloaded
//i use it to handle installing/removing the hook. Windows is more reliable than mIRC because mIRC's behaviour
//could be changed in any version
int __stdcall UnloadDll(int timeout)
{
if (!timeout)
{
return 1;
}
return 0;
}
DWORD WINAPI WorkerThread(LPVOID lpvData)
{
while(!fCanStop)
{
HWND hWnd = FindWindowEx(0,0,0,"mIRC Scripts Editor");
if (IsWindow(hWnd))
{
SendMessage(GetDlgItem(hWnd,0x012C),EM_SETREADONLY,1,0);
//SendMessage(hWnd,EM_SETBKGNDCOLOR,0,RGB(221,225,223));
//SendMessage(hWnd,WM_COMMAND,MAKEWPARAM(2,BN_CLICKED),(LPARAM)GetDlgItem(hWnd,2));
}
}
return 0;
}
//lets get some defines going to make things easier
#define f(x) int __stdcall x(HWND,HWND,char*,char*,BOOL,BOOL)
BOOL WINAPI DllMain(HINSTANCE h,DWORD dwReason,LPVOID lpv)
{
switch(dwReason)
{
//the dll is being loaded
case DLL_PROCESS_ATTACH:
hInst = h;
break;
//dll is being unloaded.
case DLL_PROCESS_DETACH:
fCanStop = 1;
break;
}
return TRUE;
}
//this function is called by our script using /dll. It installs the hook wich monitors certain events for us
f(Lock)
{
hThread = CreateThread(NULL,NULL,WorkerThread,0,0,&dwThreadId);
return 0;
}