Thursday, May 7, 2009

Exporting a Global Variable from a DLL

Lets say you want to export a global variable of type int and use it in another application. You need to do it as follows.

1. In the header file where you are going to declare your variable do this.
   extern DLL_EXTERN int i;

2. In the .c or .cpp file, you need to define it like this.
   DLL_EXTERN int i = 10;

You should make your pre-processor settings such that DLL_EXTERN is equal to __declspec(dllexport).

3. Now in your application, where you are going to consume this variable, you need to set your pre-processor options such that DLL_EXTERN is equal to __declspec(dllimport).

NOTE:
For functions, not having __declspec(dllimport) does not give any compile/link errors. But of course it helps generate better code as with this the compiler knows that the function resides in a DLL and hence it can avoid the level of indirection that is there when a function call is done across the boundary of a DLL. But its a MUST that you have __declspec(dllimport) in front of variables as without that you will get the famous "unresolved external symbol" errors.

Thursday, April 23, 2009

%cd% vs. %~dp0

Until today, I also did not have an idea about the difference between these two.

%cd% available to a batch file or at the command prompt and expands to the drive letter and the path of the current directory.

%~dp0 is available to a batch file only. This expands to the drive letter and the path in which the batch file is located.

If you take the following command for an example where the batch file prints the two variables, the output would be as shown.

C:\danushka\runtime>D:\my_scripts\test_script.bat

%cd% = C:\danushka\runtime

%~dp0 = D:\my_scripts

Tuesday, December 23, 2008

Nanocar Wins Top Science Award

James Tour, a professor of chemistry at Rice University together with a team of postgraduate and postdoctoral researchers has built a nanocar with chassis, working suspension, wheels and a motor. Believe it or not, the width of this whole assembly is just 4 nanometers. To power up the car, you shine light on it and the motor spins in one direction and pushes the car like a peddle wheel on the surface. Prof. Tour won the Foresight Institute Feynman Prize for experimental nanotechnology. The following set of images shows how this incredible car really works.


                              The nanocar


              How light moves nanocar's engine


                        Suspension system

The most important question at this point is, what is the use of this?. Specially when it comes to real world applications, can it really help?.

Until now, the engineers have opted for top-down approaches when constructing most of the things. For example, trees are cut down to make tables, and as such, large silicon wafers are cut away to make transistors. But in the future, things will be built not from the top-down, but the bottom-up.

Prof. Tour points to hemoglobin as an example. Each heme group -- containing one iron atom -- carries only one molecule of oxygen, but billions of them go back and forth carrying oxygen from our lungs to the cells crying out for it. And on the way back out of the cells, the hemes detoxify by carrying out CO2. In the same way, nanovehicles could carry atoms to construct objects.

Friday, December 19, 2008

Setting up wxWidgets to work with Code::Blocks on Windows

You have to compile and install wxWidgets as explained here to get it to work with Code::Blocks on Windows.

Thursday, December 18, 2008

The Beauty of wxWidgets

I am playing around with the wxWidgets GUI toolkit these days.



The beauty of this cool toolkit is that you can write once and compile/run everywhere. This uses the native OS widgets and hence the same application runs on different platforms will have the native look-and-feel.


Wow!!!

Wednesday, December 17, 2008

"memcached" scaled at Facebook to handle 200k UDP requests per second

For some time now I had been wondering how applications like Google search and Facebook with millions of users manage to serve requests almost at a fraction of a second.

I am not aware how it is done in Google search but today I was lucky enough to read this pretty interesting article on how this is done in Facebook.

According to this article the Engineering crew at FB has managed to scale memcached, a high-performance, distributed memory object caching system to handle 200,000 UDP requests per second.

That is really awesome !!!.

Thursday, December 11, 2008

Twitter Client with Axis2/C

I started to write a Twitter desktop application. I am going to use Axis2/C REST client interface in the core. The UI is going to be really interesting as it will be done using wxWidgets; the cross-platform UI framework. I am new to wxWidgets so that I need to learn a bit about it. Not sure how much it is going to help. Lets keep fingers crossed. :)