Code::Blocks 10.05
I'm a hobbist programmer, and I'm relatively new to C++. I started with Dev-CPP sometimes ago. Although I was able to write small programs with it I couldn't get its debugger to stop at breakpoints. I discovered Code::Blocks by accident and I like it. Its intellisense feature is a lot faster than the one in Dev-CPP and I don't have any trouble with breakpoints.
I spent almost a week trying to get some DLLs I wrote and compiled with Code::Blocks to work in Code::Blocks but I failed. Even the code generated by Code::Blocks template DLL (accessible through File -> New -> Project -> Projects -> Dynamic Link Library) doesn't work. It complies fine but when I link it to another project, Code::Blocks' linker generates an error. Below is the code for test.h and test.cpp:
(TEST.H)
#ifndef __TEST_H__
#define __TEST_H__
#include <windows.h>
/* To use this exported function of dll, include this header
* in your project.
*/
#ifdef BUILD_DLL
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT __declspec(dllimport)
#endif
#ifdef __cplusplus
extern "C"
{
#endif
void DLL_EXPORT SomeFunction(const LPCSTR sometext);
#ifdef __cplusplus
}
#endif
#endif // __TEST_H__
(TEST.CPP)
#include "test.h"
#include <iostream>
using namespace std;
// a sample exported function
void DLL_EXPORT SomeFunction(const LPCSTR sometext)
{
MessageBoxA(0, sometext, "DLL Message", MB_OK | MB_ICONINFORMATION);
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
// attach to process
// return FALSE to fail DLL load
break;
case DLL_PROCESS_DETACH:
// detach from process
break;
case DLL_THREAD_ATTACH:
// attach to thread
break;
case DLL_THREAD_DETACH:
// detach from thread
break;
}
return TRUE; // succesful
}
The above compiles without errors and generates three files: test.dll.def, test.dll, and test.dll.a.
I tried to use the function SomeFunction() in a main.cpp file. I implicity loaded the dll file.
Questions:
1- Why does Code::Blocks generate the following error: 'cannot find -ltest.dll' when I include test.h and link to test.dll.a?
I don't understand why Code::Blocks is adding the prefix '-l' to the dll file's name.
2- I tested the dll generated by Code::Blocks in Dev-CPP and it worked.
Why does it work in Dev-CPP and doesn't work in Code::Blocks?
3- This is slightly off topic. My access to the internet is limited. Is there something downloadable like microsoft MSDN but for MinGW library that I can install in my computer?
4- Last, MSDN defines _WIN32_WINNT = 600h for Vista. I have Vista with SP2. When i use _WIN32_WINNT in VC6 the returned value is 601h. That's still ok . When I try it in Code::Blocks or Dev_CPP the returned value is 400h, and as a result the gcc compliler failes to load most of the libraries defined in MingW\ windows.h.
Can someone shade some light on this.
thanks