|
Joined: Oct 2005
Posts: 827
Hoopy frood
|
OP
Hoopy frood
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
|
|
|
|
Joined: Sep 2005
Posts: 2,881
Hoopy frood
|
Hoopy frood
Joined: Sep 2005
Posts: 2,881 |
The dll will be unloaded when mIRC closes so you will lose them.
|
|
|
|
Joined: Dec 2002
Posts: 580
Fjord artisan
|
Fjord artisan
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); }
|
|
|
|
Joined: Dec 2002
Posts: 580
Fjord artisan
|
Fjord artisan
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")....
|
|
|
|
Joined: Jan 2003
Posts: 249
Fjord artisan
|
Fjord artisan
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 );
|
|
|
|
Joined: Oct 2005
Posts: 827
Hoopy frood
|
OP
Hoopy frood
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
|
|
|
|
Joined: Jan 2003
Posts: 249
Fjord artisan
|
Fjord artisan
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.
|
|
|
|
Joined: Oct 2005
Posts: 827
Hoopy frood
|
OP
Hoopy frood
Joined: Oct 2005
Posts: 827 |
ah ok thanks, Im just asking for testing purposes etc
|
|
|
|
Joined: Jan 2003
Posts: 1,063
Hoopy frood
|
Hoopy frood
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!
|
|
|
|
Joined: Oct 2005
Posts: 827
Hoopy frood
|
OP
Hoopy frood
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!
|
|
|
|
Joined: Sep 2005
Posts: 2,881
Hoopy frood
|
Hoopy frood
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.
|
|
|
|
Joined: Oct 2005
Posts: 827
Hoopy frood
|
OP
Hoopy frood
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.
|
|
|
|
Joined: Sep 2005
Posts: 2,881
Hoopy frood
|
Hoopy frood
Joined: Sep 2005
Posts: 2,881 |
No. That's done by the system.
|
|
|
|
Joined: Jan 2003
Posts: 249
Fjord artisan
|
Fjord artisan
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)
|
|
|
|
Joined: Sep 2005
Posts: 2,881
Hoopy frood
|
Hoopy frood
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;
|
|
|
|
Joined: Oct 2005
Posts: 827
Hoopy frood
|
OP
Hoopy frood
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?
|
|
|
|
Joined: Oct 2005
Posts: 827
Hoopy frood
|
OP
Hoopy frood
Joined: Oct 2005
Posts: 827 |
ok well ive had a crack at it...
//declarations at the top
#include <map>
#include <string>
using namespace std;
typedef map<string, string> 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.
|
|
|
|
Joined: Jan 2003
Posts: 249
Fjord artisan
|
Fjord artisan
Joined: Jan 2003
Posts: 249 |
first thing http://www.sgi.com/tech/stl/table_of_contents.htmlNext
typedef std::map<std::string, std::string> 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).
|
|
|
|
Joined: Oct 2005
Posts: 827
Hoopy frood
|
OP
Hoopy frood
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!!
|
|
|
|
Joined: Oct 2005
Posts: 827
Hoopy frood
|
OP
Hoopy frood
Joined: Oct 2005
Posts: 827 |
i got this code, with a little problem
// hhh.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <map>
#include <string>
using namespace std;
typedef std::map<std::string, std::string> 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.
|
|
|
|
|