Author Topic: I can compile DLLs but can't used them back in a project  (Read 2462 times)

naton

  • Guest
I can compile DLLs but can't used them back in a project
« on: September 16, 2010, 02:12:40 pm »
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)
Code
#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)
Code
#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


Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: I can compile DLLs but can't used them back in a project
« Reply #1 on: September 16, 2010, 03:41:28 pm »
First read this: http://wiki.codeblocks.org/index.php?title=FAQ#Q:_How_do_I_troubleshoot_an_compiler_problem.3F

1. The above link should explain where to find the needed info.
2. Seems your host project is not configured correctly
4. The default value for _WIN32_WINNT depends on the installed Platform SDK (I think). Mingw "emulates" the SDK and it defaults to NT4.
You can override this value and you'll have the newer features if you need them and they are ported to Mingw.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]