Leaderboard
Popular Content
Showing content with the highest reputation on 02/24/2013 in all areas
-
One of the main issues AutoIt coder could have is lack of built-in data compression mechanism. Doing it "manually" is not an option because of the slowness of the interpretter. So, it's either using third party dlls (whatever) or some Windows API that exposes the funcionality. In this post I will compress data using well known GDI+. That's graphical library, so it's not straightforward approach. First I'm making BITMAP out of data and then convert that image into a PNG. PNG format includes form of compression, so at the end what's get is compressed data. Compression level is not very high compared to other methods, but considering everything - who cares . Of course that compressing string "ABC" will not make much sense and will result in, IDK 150 bytes of output because PNG includes metadata that take space, but for data in sizes of more than few KB you will see the difference. Besides you will see how your data looks if it's taken to be a picture. Script will create PNG out of itself called Test_Image.png and then read it and print to console: GDIP_Compress.au32 points
-
If you use SciTE Jump, then right click on a function will allow you to open the script's directory too.1 point
-
BrewManNH, I had forgotten that thread - at least I am consistent in my proposed solutions! M231 point
-
MouseHoverCallTips [11/24/2023]
Sunaj reacted to jaberwacky for a topic
OK, here is what _ArrayDisplay's calltip looks like when I use the native intellisense: _ArrayDisplay (Const ByRef $avArray [, $sTitle = "Array: ListView Display" [, $iItemLimit = -1 [, $iTranspose = 0 [, $sSeparator = "" [, $sReplace = "|" [, $sHeader = ""]]]]]]) Displays given 1D or 2D array array in a listview. (Requires: #include <Array.au3>) And here is what it looks like when I use Mousehover --> Calltip: _ArrayDisplay (Const ByRef $avArray [, $sTitle = "Array: ListView Display" [, $iItemLimit = -1 [, $iTranspose = 0 [, $sSeparator = "" [, $sReplace = "|" [, $sHeader = ""]]]]]]) Displays given 1D or 2D array array in a listview. (Requires: #include <Array.au3>) I did decide to put the (requires:... section on its own line. Are you referring to when you have a func definition with a comment on the same line?Func my_awesome_function() ; this is my awesome function.If so then you shouldn't have to put two semi colons. So I will look into that. Edit: OK, if you want an extra line feed then yes just put two semi colons. Thank you. I will look into this some more. Edit: Ok, I don't experience the issue that you describe. Maybe I have misunderstood?1 point -
Funny this comes up after using SciTE for this long. One option I use all the time too and never added to the standard setup is a shortcut Ctrl+E to start Explorer with the filename being edited selected: #x 40 Open Explorer with file selected $(FilePath) command.40.*=Explorer.exe /e,/select,"$(FilePath)" command.name.40.*=Open Explorer in Sourcedir command.shortcut.40.*=Ctrl+E command.subsystem.40.*=2 command.save.before.40.*=2 command.replace.selection.40.*=0 command.quiet.40.*=1 Jos1 point
-
EXT --> Exit ?My solution to enter Start avoids this problem. A new command window will be opened.1 point
-
1 point
-
C++ basic question (heap - stack)
jaberwacky reacted to Ascend4nt for a topic
While its most convenient to think of local variables as stored on the stack, there's no guarantees that a variable will be stored there, or even created. Compiler optimizations can completely optimize out a variable, or place it in a processor register. Usually, the only way to be sure that it's going to land on the stack is to somewhere take the address of that variable. But even then, optimizations could get rid of it. Also, anything declared 'static' inside a function, or any variables outside of a function won't be stored on the stack. They'll be stored in the data segment, which is loaded up along with the executable. Heaps are resources that are allocated by the runtime library, or some overloaded functions. Heaps don't have to exist in memory, nor do they have to be allocated using specific structures. As others have pointed out, typically the amount of memory available to the O/S doesn't limit the amount of memory you can allocate for each process. But thats all irrelevant if your focus is on what is keeping track of those resources. Any pointer to a resource must be known by the running code, so if something is allocated, there's a guarantee that something 'concrete' locally will contain a pointer to it (whether its the stack, a register, or a place in the data segment). P.S. Since you're compiling using VC++2010, I suggest learning Modern C++ style. shared_ptr's, weak_ptr's, and unique_ptrs are your friend.1 point -
No, you create a reference / pointer on the stack, whoose value is the pointer to a new object, which is allocated on the heap. Goes for both cases. I guess you figured this out by now, but it's on the stack. Not quite, the heap of the program is a kinda like a memory-rental store. If you need memory extra memory, a large amount of memory (can create stack overflow on the stack) or a variable amount of memory, you go ask the store to rent some. If they have some available in your size, you borrow it, but you have to give it back. In practice, it's usually implemented as an expandable, indexed buffer, that allows you to do what i said earlier. If the heap is getting near empty, it asks the OS for some more virtual memory in form of pages (-> virtualalloc on msdn), therefore it's process specific. Think of it as an array you can redim. A cool way to really understand it is to write your own1 point
-
Close. About as close as you really need to be in order to program, any more specific and you begin to enter the territory of implementation dependant stuff, and the whole idea of languages like C++ is that you don't need to worry about that "stuff". A heap is a block of memory. You shouldn't think of the heap as being system wide, more like individual heaps allocated to processes. A process has its system provided heap. Local variables are on the stack. There is a register (ebp) that is used to define where the stack frame for the current function is. Since the number of locals is always known, your int* value is always at a specified position relative to ebp. I really recommend compiling the code, setting a breakpoint then looking at the disassembly. Even if you don't understand assembler you'll get the rough gist of what is going on. Something like: int* pNum; pNum = new int(); Would be something like: push ebp mov ebp,esp add esp,4 ; int* pNum; push 4 call malloc ; new int() mov [ebp+4],eax ; pNum =1 point
-
Ok, so I never got the changing values in your different class, but the app was just crashing. Try this. #include <iostream> #include "windows.h" class TestClass { private: __int64 var1; // I need to monitor this value __int64 var2; __int64 var3; __int64 var4; __int64 var5; __int64 instance; public: void SetVar1(__int64 var){ var1 = var; } void SetVar2(__int64 var){ var2 = var; } void SetVar3(__int64 var){ var3 = var; } void SetVar4(__int64 var){ var4 = var; } void SetVar5(__int64 var){ var5 = var; } __int64 GetVar1(){ return var1; } __int64 GetVar2(){ return var2; } __int64 GetVar3(){ return var3; } __int64 GetVar4(){ return var4; } __int64 GetVar5(){ return var5; } void PrintAll(){ std::cout << "Instance: " << instance << "nn"; std::cout << "var1: " << var1 << "n"; // This var1 is displaying something other than it's initial value (-1) std::cout << "var2: " << var2 << "n"; std::cout << "var3: " << var3 << "n"; std::cout << "var4: " << var4 << "n"; std::cout << "var5: " << var5 << "n"; } TestClass (__int64 var) : var1(-1), var2(-1), var3(-1), var4(-1), var5(-1) { instance = var; } }; class DifferentClass { private: bool inuse; bool relevant; __int64 value1; __int64 value2; __int64 lastvalue; __int64 instance; public: //default constructor DifferentClass (__int64 num) : inuse(false), relevant(false), value1(0), value2(0), lastvalue(0) { instance = num; } //setters void Sinuse(bool var); void Srelevant(bool var); void Svalue1(__int64 var); void Svalue2(__int64 var); void Slastvalue(__int64 var); void Sinstance(__int64 var); //getters bool Ginuse(void); bool Grelevant(void); __int64 Gvalue1(void); __int64 Gvalue2(void); __int64 Glastvalue(void); __int64 Ginstance(void); //Destructor ~DifferentClass () { } }; //Setters void DifferentClass::Sinuse(bool var) { inuse = var; } void DifferentClass::Srelevant(bool var) { relevant = var; } void DifferentClass::Svalue1(__int64 var){ value1 = var; } void DifferentClass::Svalue2(__int64 var){ value2 = var; } void DifferentClass::Slastvalue(__int64 var){ lastvalue = var; } void DifferentClass::Sinstance(__int64 var){ instance = var; } //Getters bool DifferentClass::Ginuse() { return inuse; } bool DifferentClass::Grelevant() { return relevant; } __int64 DifferentClass::Gvalue1(){ return value1; } __int64 DifferentClass::Gvalue2(){ return value2; } __int64 DifferentClass::Glastvalue(){ return lastvalue; } __int64 DifferentClass::Ginstance(){ return instance; } // Where DifferentClass values are being changed void _func(DifferentClass * atest[]){ // I believe the problem lies in this piece of code // because this is always the executed before the culprit value changes for (int i = 0; i < 5; i++) { atest[i]->Svalue1(i+100000); atest[i]->Svalue2(i+200000); atest[i]->Slastvalue(i+300000); } } int main () { TestClass mtest(1); // mtest in main DifferentClass test0(0); DifferentClass test1(1); DifferentClass test2(2); DifferentClass test3(3); DifferentClass test4(4); DifferentClass * atest[5]; atest[0] = &test0; atest[1] = &test1; atest[2] = &test2; atest[3] = &test3; atest[4] = &test4; for (int n = 0; n < 20; n++) { //func changes values in DifferentClass instance _func(atest); //Print values in TestClass mtest.PrintAll(); } std::cin.get(); } atest is an array of pointers, so you pass the array (a pointer itself) to _func, and the parameter is an array of pointers to your class. This runs with no crash for me. Be careful in _func... there's nothing to stop you from going out of bound on the array and crashing from a memory access error (which was my first crash, as your code increments i to 19, when you only have a 5 element array). It might be better to use something with a known capacity here, a vector or something (I'm sure others could suggest better container classes to you, my knowledge is admittedly limited).1 point
-
No need to apologize and say thankyou 10 times, twice is enough. I like helping old people. Who knows, maybe you die tomorrow. It would break my heart knowing you went not knowing how to replace bitmap resource.1 point
-
Language John, you have to match the language identifier if you want to replace the resource. I told you that already.1 point
-
I did tell you to read the documentation. ... Don't FreeLibrary handle get by GetModuleHandle. Read, read, read.1 point
-
Second argument for BeginUpdateResource should be FALSE if you want to keep existing resources.1 point
-
API you use takes care of everything for you as far as the size is concerned, don't worry about that, just carefully read and follow MSDN documentation. As for the language, normally you would use neutral identifier or the one module uses for the rest of the resources (if any there). In case of wrong "location" the only one existing gets loaded. Besides that, resource language idenifier is really only imporant for string resources. On the other hand, if you are replacing, then of course you will use the same idenifiers for new bitmap as they are for the old one, including language.1 point
-
It's fairly easy to do that. Considering you are updaing bitmap resource it's even easier copying from one place to another than it would be to do it from a bitmap file. First you have to lock(ate) the original resource in your executable. You do that in few easy steps, ::GetModuleHandle(NULL) -> ::FindResourceEx -> ::LoadResource -> ::LockResource + ::SizeofResource Now you have the data to write. All you do then is ::BeginUpdateResource -> ::UpdateResource(locked_data, size_of_that_data) -> ::EndUpdateResource ... on target module. In C++ you would write nice simple class with two constructors (default and with the file name of the target), locking method, writing method. Then you would do something like this (boring details omitted for brevity): SuperEasyThing oMGEasyIndeed(szDest); DWORD dwSize = 0; LPVOID pData = oMGEasyIndeed.LockResData(MY_RES_NAME, RT_BITMAP, &dwSize); oMGEasyIndeed.Write(pData, dwSize, RT_BITMAP, RES_NAME_BY_YOUR_CHOICE);1 point
-
If you are using Windows XP+, or Win 2K w/IE 5.5, you can skip C++ regular expressions and use the Visual Basic RegExp library which is on every system post WinXP. There's a few articles about using it, but I decided to write my own C/C++ version. Here's two places you can look: http://www.codeproject.com/Articles/4594/Use-regular-expression-in-your-C-program http://www.codeproject.com/Articles/6274/Convenient-wrapper-of-VBScript-RegExp-for-VC Note that the VB RegExp library doesn't allow lookbehind assertions, just as Visual C++ doesn't. I'd instead recommend the same library that AutoIt uses, PCRE (http://www.pcre.org/). And just in case someone complains, I'll state the obvious here: the VB RegExp library is not portable to other O/S's, of course.1 point
-
You shouldn't be - theyre there to help you. And, no it isn't. but im pretty sure it's the easiest - you dont wanna handle dynamic memory yourself, unless it's absolutely necessary. Firstly, you choose a container - a list, map or vector would be ideal for this type of job. Any would do, but here's a quick example using a map: #include <map> #include <string> int main() { ... hotel.AddGuest("john"); hotel.RemoveGuest("john"); ... } class BBHouse { .... std::map<std::string, Guest> guests; // maps provide an easy interface to look up an guest using a string like an array. //consider adding rooms as a map/list or something too, so you can have an expandable hotel. seems nice public: void AddGuest(string name, int room = -1) { //this assumes a design where this class autofits a guest into a room, unless a specific room number is given // snip: this is the room our algorithm gives us. maybe add errorchecking here if house is full // not quite sure how you want room & guest relationship - but use references so rooms and guests have relationships Room & assigned_room = get_first_avaible_room(); Guest new_guest; //new_quest.name = name; optional: see further down guests[name] = guest; //should room be selfaware? assigned_room.add(guest); } public: void RemoveGuest(string name) { //do billing here //now erase entry guests.erase(guests.find(name)); } private: Room & get_first_avaible_room(); // returns a reference to a room, that is empty .... } class Guest { ... //this is optional, but it might be nice to have the guest name stored public: string name; ... }1 point
-
More accurately the C++11 standard includes a regex library. Have you looked at sregex_iterator?? Should mean only one call and then a for loop, but I have never actually used that library.1 point
-
You have a horrible design actually that is wasting more CPU cycles than you ever will with a polling solution. Thread creation and destruction is expensive. Besides, a quick look at the documentation shows that you can have pcap_next() block until it receives a packet or times out. So no, this isn't really a good use of threading. The program should only have two threads, the first thread would be for the user-interface (This may not be required if you are using a console application). The second thread captures and processes all the packets and sends whatever important information back to the main thread to display. There is no need to add further threads for the pcap stuff.1 point
-
Did you check what that error means? It's not very descriptive, you should try googling.What's with C style casting?1 point