Using/Compiling SQLite with Dev-C++ for c project and cpp project

Win32 API No Comments »

How to compile sqlite with c or c++ project in DEV-C++ IDE?

That was my question when i wanted to use sqlite in my c and cpp program.

I searched the internet for sqlite library for dev c++ and used some which worked for me.

For all the options include sqlite3.h


OPTION 1:
To compile sqlite3.c with a C project

Download http://www.sqlite.org/sqlite-amalgamation-3071502.zip which can be found in http://www.sqlite.org/download.html - the amalgamation.

Open the zip and copy sqlite3.c to your project folder.

I assume that you have created a c project(for cpp i have mentioned below)

In dev c++ ide right click the project name which is listed in the project explorer pane at the left side and select ‘Add to Project’. Choose the sqlite3.c file and after that you can see sqlite3.c listed in project explorer with other files.

Press F9 to check whether it is compiling or not. It should.

By doing this all the functions of sqlite3 are statically included in the final executable executable.


OPTION 2:
To compile sqlite3.c with a C++ project

now we need to create a cpp program which uses sqlite3.

Do as mentioned in STEP 1 and …

Go to Project >> Project Options >> Files.

Select sqlite3.c and untick the “Compile file as C++” option. (If we do not do this step then we get invalid conversion errors)

This should inform Dev-C++ that it should invoke gcc.exe, and not g++.exe cause gcc is for c files and g++ for cpp and since sqlite3.c is a c file we have to compile with a c compiler.

The reason for doing these i want to know how to include a source file into a project instead of using a .lib file or a .dll file


OPTION 3
using sqlite DEVPAK in dev C++

This option works for both c project and cpp project.

Download sqlite devpak from
http://www.ce.unipr.it/people/medici/DevPak/sqlite-3.6.22-2pm.DevPak which is present in devpak site http://devpaks.org/details.php?devpak=281

(OR)

http://sourceforge.net/projects/devpaks/files/SQLite/sqlite%203.5.6/

In dev c++ ide select Tools >> Package Manager

The package manager window will open. In that select Install and it will show a dialog box to select the *.devpak file.
Now select the devpak file you downloaded from the above links. Done.

You can compile sqlite with a c project or cpp project… it worked for me with c++ project and home it will work for a c project as well. i haven’t checked for the latter.


References


—-

That is all folks. Enjoy.

using timers in win32api windowless application

Win32 API No Comments »

I wanted to write a windowless win32 program with timers. It will run in the background and will trigger some functions at specific time intervals. so followed the following conditions. Which would not consume more cpu time.

  • No Window
  • No Window Class defined
  • It should not be a console application.
  • Is should be a kind of background process yet not a windows service
  • It should not contain while loops and sleep functions which shall overloads the CPU
  • It will have timers

I had been reading discussions which discouraged the use of while loops and sleep functions if you are not going to have a windowed application. I too felt the same cause that will consume more of the CPU usage were as there should be a way to make the instance wait for a message. and at this point i thought of using only the message loop as suggested by experts and it worked.

The code below works well if you are not going to have threads and other stuff.

If you program is going to be standalone and if it is simple then you can go for this. I have provided reference links at the bottom of this post.

Here is the code i used. I used Dev-C++ IDE to compile.

The following code will call the function timerfunc every 20 seconds.

#include <windows.h>
 
void timerfunc();
 
int main()
{
 
    SetTimer(NULL, 1, 20000, (TIMERPROC) timerfunc);
    MSG msg;
 
 
    while (GetMessage (&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
 
    return 0;
}
 
 
void timerfunc()
{                      
 
//some code here
 
}

Here i tested by giving void main instead of some thing like the following and it works. I have to do another discussion related to this cause it had been a long time since i did win32 api programming.

int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)

Besides, the above is what i researched and did for the least. I will have to explore more and would be updating this page.
so, this is all i have for now.

References:

http://stackoverflow.com/questions/13233084/win32-windowless-application-using-timer-using-message-loop-and-without-using-cp

http://forums.codeguru.com/showthread.php?398186-windowless-timers

http://stackoverflow.com/questions/4487038/win32-windowless-application-wait-for-program-exit

Entries RSS