mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 3 1 2 3
#139733 18/01/06 01:56 AM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
if i save stuff to arrays in the dll, is it possible to keep them in the dll even if i close mirc, or will i lose them?

like with hash tables we can write hash entries to text file on EXIT, and load them again in start

#139734 18/01/06 05:35 AM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
The dll will be unloaded when mIRC closes so you will lose them.

#139735 18/01/06 07:17 AM
Joined: Dec 2002
Posts: 580
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 580
look at fopen(), fread(), fwrite(), and fclose() for basic file I/O... For an array you would need to write the number of bytes in the array to a file...

[code]
#define SIZE 50
void Test(void) {
char array[SIZE] = "This is a character array";
FILE *fp
// Modes r=read, w=write, a=append, r+ = read/write existing...
fp = fopen("filename", "r+");
fwrite(array, SIZE, 1, fp);
array[0] = 0;
fread(array, SIZE, 1, fp);
fclose(fp);
}


NaquadaBomb
www.mirc-dll.com
#139736 18/01/06 07:25 AM
Joined: Dec 2002
Posts: 580
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 580
If you want to save dynamically allocated memory between Unload and "Reload" of a DLL without quiting mIRC... Consider saving pointers, to dynamically allocated memory, in a window property, GetProp(hwnd, "PropName") and SetProp(hwnd, "PropName", propValuePtr), there is also a RemoveProp(hwnd, "PropName")....


NaquadaBomb
www.mirc-dll.com
#139737 18/01/06 02:40 PM
Joined: Jan 2003
Posts: 249
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Jan 2003
Posts: 249
fwrite( array, sizeof( item ), number of items, fp );

yes it's 1 for a char, but if you have an array of something else, you won't get what you expect.

fwrite( array, sizeof( char ), strlen( text ), fp );

#139738 18/01/06 06:39 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
thanks a bunch guys, has anyone got any simple tuts or anything on arrays in c++, because what i want to do is create an array so i can store data for different things, e.g..

(#Channel) (Visted)
#hello 7
#mirc 0
#net 9

#139739 18/01/06 06:41 PM
Joined: Jan 2003
Posts: 249
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Jan 2003
Posts: 249
why do you use a DLL to store stuff when mIRC has already the tools for that in INI files, hash tables or plain text files ?

And arrays in C++ are different from other languages like PHP arrays where you can have "keys" to identify an item. There is no such thing natively in C++. But you can use STL containers to achieve a similar result but this is somewhat an advanced topic in C++.

Last edited by ClickHeRe; 18/01/06 06:44 PM.
#139740 18/01/06 07:20 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
ah ok thanks, Im just asking for testing purposes etc

#139741 19/01/06 09:01 AM
Joined: Jan 2003
Posts: 1,063
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2003
Posts: 1,063
because arrays in c have a predefined size it's hard to store dynamic data in it.

I would suggest using c++ and then either a linked list of channel objects, or a vector because both are variable of size


If it ain't broken, don't fix it!
#139742 19/01/06 03:07 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
so something like this

/dll Test.dll TestStore #channel hello

i could make that using linked lists then? to store the data 'hello' into a table/list of somekind called #channel ?

and could i do this to retrieve the data for that channel

//echo -a $dll(Test.dll, getData, #channel)

ill have a look at linked lists then!

#139743 19/01/06 03:09 PM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Linked lists are exactly like hashtables. You specify the type of key you'll be storing and the type of data you'll be storing when you initialise the list.

#139744 19/01/06 03:39 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
thanks, i'll have a crack at it and post back later

but using a link list, if i wanted to say foe e.g, grab the data inside the key called #mirc, would i have to scan through all the nodes in the list?

Last edited by pouncer; 19/01/06 03:40 PM.
#139745 19/01/06 04:10 PM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
No. That's done by the system.

#139746 19/01/06 05:45 PM
Joined: Jan 2003
Posts: 249
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Jan 2003
Posts: 249
use an STL hash map for a key/value relationship like mIRC's hash tables (which I think is implemented using a wrapper around a hash map)

#139747 19/01/06 06:28 PM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Er that's actually what I mean heh. I don't know why I thought of linked lists when I meant maps.

map<keytype,datatype> blah;

#139748 21/01/06 01:37 AM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
ah, maps!

so are hash maps and maps the same thing?

and any of you guys ever used them before for anything?

#139749 21/01/06 03:34 AM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
ok well ive had a crack at it...

Code:
//declarations at the top
#include &lt;map&gt;
#include &lt;string&gt;
using namespace std;

typedef map&lt;string, string&gt; TestMap;

//export function..
extern "C" int WINAPI Test(HWND, HWND, char *data, char *parms, BOOL, BOOL) {
  
	TestMap["#Channel"] = "Mark";

	_fstrcpy(data, TestMap.find("#Channel"));

	return3;
}


but just gives me loads of errors and warnings on the export function, any ideas what im doing wrong guys?

Last edited by pouncer; 21/01/06 03:36 AM.
#139750 21/01/06 11:43 AM
Joined: Jan 2003
Posts: 249
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Jan 2003
Posts: 249
first thing

http://www.sgi.com/tech/stl/table_of_contents.html

Next

Code:
typedef std::map&lt;std::string, std::string&gt; MyMap;
MyMap TestMap;

//export function..

extern "C" int WINAPI Test(HWND, HWND, char *data, char *parms, BOOL, BOOL) {

  std::string chan( "#Channel" );
  std::string mark( "Mark" );

  TestMap.insert( MyMap::value_type( chan, mark ) );

  MyMap::iterator it = TestMap.find( chan );

  if ( it != TestMap.end( ) ) {

    lstrcpy( data, (*it).second.c_str( ) );
  }

  return 3;
}


Little explanation :

You need to have your insert types to be the same as defined in your map. Strings like "blah" are C-Strings and not std::string onjects. Next you insert like demonstrated which adds the item in the map (the map is like a hash table, it's sorted as a binary tree (on the key) for fast access and search, there is no order).

When you use the find method on your map with a std::string as an argument which matches your defined map key type, it will return an iterator to the item. You need to check that this iterator isn't the end of the map (essentially pointing to NULL since it didn't find the item which you get by using .end( ) function to check the condition). An iterator is a pointer to an item. A map item has 2 properties, .first which is the "key" and .second which is the "data" and since these are atd::string, I need to retreive them as a C-String to be able to copy the value into the char * data that mIRC gives.

Note: I'm not a fan of using the "use namespace std;" as I prefer to typedef my items instead as your are sure your "string" or "map" come from STD and not another library.

Last, if you are really interested in STL, you should ditch the DLL for now and concentrate on understanding it with a simple console application to test how it works and be confortable with iterators and the such (the whole STL works in every object the same way).

#139751 21/01/06 12:12 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, im gona do what you said and mess about with things in a console, thanks for the code and explanation, just the kind of reply i needed!!

#139752 21/01/06 12:24 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
i got this code, with a little problem

Code:
// hhh.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include &lt;map&gt;
#include &lt;string&gt;
using namespace std;

typedef std::map&lt;std::string, std::string&gt; MyMap;

// MyMap TestMap; - As soon as i uncomment this line, it compiles fine :S

int main() {

	std::string chan( "#Channel" );
	std::string mark( "Mark" );


	return 0;
}


that MyMap TestMap is causing problems, but when i comment it, it compiles fine, but i need it for this to work right?

Last edited by pouncer; 21/01/06 12:59 PM.
Page 1 of 3 1 2 3

Link Copied to Clipboard