mIRC Home    About    Download    Register    News    Help

Print Thread
Page 3 of 3 1 2 3
#139773 25/01/06 01:31 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
but it works like this...

Code:
extern "C" int WINAPI StoreKey(HWND, HWND, char *data, char *parms, BOOL, BOOL) {

	string channel = GetTok(data, 1, 32);
	string key = GetTok(data, 2, 32);

	KeyStorer.insert(MapFunction::value_type(channel, key));

	MapFunction::iterator it = KeyStorer.find( channel );

	if ( it != KeyStorer.end( ) ) 
		lstrcpy( data, (*it).second.c_str( ) );
	else  
		lstrcpy( data, "Key Not Found" );
	
	return 3;
}


//echo -a $dll(Test.dll, StoreKey, #channel key) echos key

but it just doesnt return the key from a seperate function :S

Last edited by pouncer; 25/01/06 02:31 PM.
#139774 26/01/06 12:03 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
seeing as im having problems with using the .insert and .find in seperate functions (and it works when i put both in 1 function) could the problem be the loading and unloading of the dll?

if i call the storekey function to store the key for the specified channel, and the dll unloads, would the dll loose all its contents?

its the only reason i can think of, why the getkey doesnt return the value, maybe because the dll is unloading?

#139775 26/01/06 01:01 PM
Joined: Jan 2003
Posts: 249
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Jan 2003
Posts: 249
yes it would

you can force mIRC to keep the DLL loaded all the time, in the unload function

// mIRC wants to close the DLL because /dll -u was called or mIRC exits
if ( timeout == 1 ) {

//clean your stuff here
return 1; // <-- tell mIRC it's ok to unload
}
else
return 0; // <-- tell mIRc we don't want to unload due to idling DLL usage (we want to keep it in memory until it's forced to unload or mIRC's exits)

Now I would really recommend that you build yourself functions to echo some debug messages to mIRC while you develop your stuff. You can take a look in the DCX package for something like mIRCError which will send the contents to mIRC via an //echo -s so I can see stuff that is going on inside the DLL during operations and manipulations to anticipate problems with data structure, invalid params, etc.

us it with the combination of wsprintf() or lstrcpy()

I would suggest you stick with the lstr* functions because they are natively included in the windows API base stuff. Using strcpy or any other variant not lstr* will only add to the size of your DLL as this extra code will be packaged with it. wsprintf() is part of the lstr* functions included.

char error[900]; // <-- no more than 900 because mIRC's data parameter which you will copy the value to send it to mIRC is limited to 900 chars.

int param1 = 12;
char [] blah = "Error occured";
wsprintf( error, "%s : %d", blah, param1 );

mIRCError( error ); // <-- assuming you use the same function is use

Debugging tools are your best bet to help you understand what is going on.

Secondly, I developped a small string library which might interest you, it's in the DCX source code if you can find that online. It's called TString which basically replicates what string does, but it adds the *tok functionality to it so it is easier to parse the parameters passed to a function. You can look into the DCX source code for examples on how to use it.

If you want, I can send you the latest version of that TString library which has quirks fixed (maintained by a friend Ook on IRC). I'm usually online at night or send me a pmsg with your e-mail and I'll send over the library.

#139776 26/01/06 08:55 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
thanks alot david, I've sent you a private message, hopefully I can use your tsring library for parsing now.

also, about this unload function

Code:
extern "C" int WINAPI UnloadDll(int timeout) {
	if ( timeout == 1 ) {
		return 1;
	}
	else return 0;
}


so mIRC wil always call this function when unloading the dll, and instead, keep the dll loaded?

another thing, i download your dcx dll stuff from mircscipts.org, the source folder seems to be empty though, i'll talk to you online, maybe soon, thanks!!

i just tried it, and after i made a call to the dll, i did this

//echo -a $dll(0) which echos 2 (2 other dlls loaded with my script)

it should be 3, which means the dll is unloading :S

(I did also put UnloadDll in exports file)

Last edited by pouncer; 26/01/06 10:34 PM.
#139777 26/01/06 10:47 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
never mind, ive fixed..
the problem is now about 99.9% sorted

the dll now doesnt unload so it stores all the info so this works

//.dll Test.dll StoreKey #channel David

//echo -a $dll(Test.dll, GetKey, #channel) echos david

but something strange happens when i do this.. :S

//echo -a $dll(Test.dll, GetKey, hello) = hello
//echo -a $dll(Test.dll, GetKey, #hello) = #hello

whatever i put there, it echos the param i put in, but these params dont even exist in a map :S

i only added '#channel' to the map

Last edited by pouncer; 26/01/06 10:50 PM.
#139778 26/01/06 10:59 PM
Joined: Jan 2003
Posts: 249
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Jan 2003
Posts: 249
it's because mIRC's data parameter in the function is used for input and also output.

Once you have finished garnishing the data you need in data, reset it simply by doing

data[0] = 0;

then proceed with your normal stuff, if a match is found in the DLL your copy functions will overide this, else, the dll will return an empty string which is equivalent to $null in mIRC.

#139779 26/01/06 11:05 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
thanks very much david.

#139780 27/01/06 12:00 AM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
just another quick question mate,

Code:
	int __stdcall StoreKey(HWND, HWND, char *data, char *parms, BOOL, BOOL) {

		string channel = GetTok(data, 1, 32);
		string key = GetTok(data, 2, 32);

		KeyStorer.insert(MapFunction::value_type(channel, key));

		return 3;
	}


is there a way to clear that channels value? instead of doing something like

KeyStorer.clear() //removes all the map keys

problem i have is this:

//.dll Test.dll StoreKey #mIRC coolchannel
//echo -a $dll(Test.dll, GetKey, #mIRC) = coolchannel
//.dll Test.dll StoreKey #mIRC nicechan
//echo -a $dl(Test.dll, GetKey, #mIRC) = coolchannel

it isnt replacing the original value for the channel, in the map

Last edited by pouncer; 27/01/06 12:00 AM.
#139781 27/01/06 12:16 AM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Code:
KeyStorer.erase(channel);
KeyStorer.insert(MapFunction::value_type(channel, key));

#139782 27/01/06 12:53 AM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
thanks hixxy, tried it, still the same problem

//.dll Test.dll StoreKey #mIRC coolchannel
//echo -a $dll(Test.dll, GetKey, #mIRC) = coolchannel
//.dll Test.dll StoreKey #mIRC nicechan
//echo -a $dl(Test.dll, GetKey, #mIRC) = coolchannel

Last edited by pouncer; 27/01/06 12:53 AM.
#139783 27/01/06 03:54 AM
Joined: Jan 2003
Posts: 249
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Jan 2003
Posts: 249
MapFunction::iterator it = KeyStorer.find( channel );

if ( it != KeyStorer.end( ) )
KeyStorer.erase( it );

#139784 27/01/06 09:19 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
nice one david

Page 3 of 3 1 2 3

Link Copied to Clipboard