Latest News
Showing posts with label function. Show all posts
Showing posts with label function. Show all posts

Recursive File Search in C | Source Code

Posted by genesisdatabase on Saturday, 5 March 2011 , under , , , , , , , , , , , , , , | comments (2)



This source code below is written by se7en from LeetCoders.  It is capable of running through the enter C drive in 8 seconds on my computer finding more than 230,000 files.  Although the downside of it is that it costs quite an amount of CPU usage during its process.  You might try to optimize it by placing Sleep function or something that is possible in reducing the CPU usage.

Auto Updater

Posted by genesisdatabase on Friday, 18 June 2010 , under , , , , , , , | comments (0)



I came across a question today and i find it very interesting.  I never thought of this back then when i haven't tested C's .dll and VB .NET together.  This post would more be of a theory and it's pretty simple.  By the way, "Auto Updater" do mean that the program is capable of updating the version itself.

Howto


If you already know how to create a dynamic link library file, i think it's pretty easy for you to do it.  There is alot of method to do so but what i am suggesting here is to use 2 files.  1 would be your .exe file and the other would be your .dll file.  I'll assume that you're building everything in C/++ because i am.

In your main program, you'll have to decide when you're going to check for updates and you'll have to provide the if-else yourself.  I'm only guiding on how will you perform the update for the function.

Now, the idea is to build your functions in a .dll form and your .exe file would execute them.  So whenever a bug occurs it would occur in the .dll file.  And when that happens you could send a trigger to your .exe file maybe by having them check your website whether there is a need for it to do so.  When it does need to update, it performs the update function and it will download automatically from your website (probably a link that you've provided) and replace it with the .dll that you previously have.  VoilĂ !

How do you call a function in a .dll in C/++


Let's assume the .dll file is called "math.dll" and the function is called "Addition" as below

[code]
__declspec(dllexport) short Addition(short num1, short num2)
[/code]

In order to call the function from the library, we have to first specify the function in our .exe.  The codes below shows the full syntax for what is required.

[code]
typedef short (__stdcall *fAddition)(short num1, short num2);
HINSTANCE math = LoadLibrary("math.dll");

fAddition ptAddition = (fAddition)GetProcAddress(math, "Addition");

printf("%d", ptAddition(1, 2));

FreeLibrary(math);
[/code]

As you can see,
line 1 is used to define the function and its parameters
line 2 is used to load the library into an HINSTANCE variable so that we could free it later
line 4 is used to get the address of the function from the library by using GetProcAddress
line 6 as you can see is to show you that it works
line 8 is used to free the library once we're done using it

Other information on C/++ calling dynamic link library - http://goffconcepts.com/techarticles/development/cpp/calldll.html

Alternatives


If you think that this is pretty silly for a small program (or some other reason), you might just want to build it in a single executable file.  Have it check when to update and when it does, download the updated executable (the new version) from your website or somewhere and replace it with the original file.  Produce creative ideas and you'll be able to solve it in your own way.