Author Topic: Linking Kernel32.DLL  (Read 5861 times)

Offline lmsmi1

  • Multiple posting newcomer
  • *
  • Posts: 11
Linking Kernel32.DLL
« on: December 04, 2012, 02:45:26 am »
I have a project that needs to be linked to Kernel32.dll. For some reason, even after I link libkernel32.a in "Build Options" < "Linker" it still gives me the same errors. Here's the project code:

Code
#include <windows.h>
#include <string>
#include "resource.h"

using namespace std;

LRESULT CALLBACK WinProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);

HINSTANCE   hInstance;
HWND        Label1;
HANDLE      Label1Handle;


int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, PSTR lpCmdLine, int nCmdShow) {

MSG msg;
WNDCLASS wc;
HWND hwnd = NULL;
hInstance       = hThisInstance;

wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = CreateSolidBrush(RGB(241, 241, 241));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hIcon            = LoadIcon(hInstance, MAKEINTRESOURCE(MAIN_ICON));
wc.hInstance      = hThisInstance;
wc.lpfnWndProc = WinProc;
wc.lpszClassName = "Window";
wc.lpszMenuName = NULL;
wc.style = CS_HREDRAW | CS_VREDRAW;

  if (!RegisterClass(&wc)) {
MessageBox(NULL, "Error registering class", "ERROR", MB_OK);
return 0;
}

hwnd = CreateWindow("Window",
"Window",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
640,
400,
NULL,
NULL,
hThisInstance,
NULL);

ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);

while (GetMessage(&msg, (HWND)NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}

return msg.wParam;
}

LRESULT CALLBACK WinProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {

switch (msg) {

        case WM_CREATE: {

        string LabelText1 = "Hello";

        Label1 = CreateWindowEx(0,
            "STATIC",
            "Some static text",
            WS_CHILD | WS_VISIBLE,
            25,
            125,
            150,
            20,
            hwnd,
            (HMENU)static_1,
            hInstance,
            0);

            SendDlgItemMessage(hwnd, static_1, WM_SETFONT, (WPARAM)CreateFont(12, 10, 0, 0, 500, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, TEXT("Terminal")), MAKELPARAM(TRUE, 0));

        } break;

        case WM_DESTROY: {
    PostQuitMessage(0);
            return 0;
        } break;

        case WM_CLOSE: {
    DestroyWindow(hwnd);
        } break;
    }

    return DefWindowProc(hwnd, msg, wParam, lParam);
}

Here's the project error list:

Code
..\..\MinGW\lib\libmingw32.a(tlsthrd.o):tlsthrd.c|| undefined reference to `EnterCriticalSection@4'|
..\..\MinGW\lib\libmingw32.a(tlsthrd.o):tlsthrd.c|| undefined reference to `LeaveCriticalSection@4'|
..\..\MinGW\lib\libmingw32.a(tlsthrd.o):tlsthrd.c|| undefined reference to `EnterCriticalSection@4'|
..\..\MinGW\lib\libmingw32.a(tlsthrd.o):tlsthrd.c|| undefined reference to `LeaveCriticalSection@4'|
..\..\MinGW\lib\libmingw32.a(tlsthrd.o):tlsthrd.c|| undefined reference to `EnterCriticalSection@4'|
..\..\MinGW\lib\libmingw32.a(tlsthrd.o):tlsthrd.c|| undefined reference to `LeaveCriticalSection@4'|
..\..\MinGW\lib\libmingw32.a(tlsthrd.o):tlsthrd.c|| undefined reference to `LeaveCriticalSection@4'|
..\..\MinGW\lib\libmingw32.a(tlsthrd.o):tlsthrd.c|| undefined reference to `DeleteCriticalSection@4'|
..\..\MinGW\lib\libmingw32.a(tlsthrd.o):tlsthrd.c|| undefined reference to `InitializeCriticalSection@4'|
||=== Build finished: 9 errors, 0 warnings ===|

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: Linking Kernel32.DLL
« Reply #1 on: December 04, 2012, 04:47:52 am »
You likely made a mistake; look at the full compiler log. See if something is wrong or missing.

http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F

FYI: In linking the order of the object file(s) and libraries matter.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline comsytec

  • Multiple posting newcomer
  • *
  • Posts: 58
    • www.comsytec.com
Re: Linking Kernel32.DLL
« Reply #2 on: December 04, 2012, 05:57:44 pm »
To me this obviously happens when when I forgot to rename c:\MinGW\lib to e.g. c:\MinGW\libX
This is while linker looks for startup files and libraries first in c:\MinGW\lib - some built in feature of the linker
I havent tried this on system where mingw is not installed

This is my simple but stupid method of quick fix

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Linking Kernel32.DLL
« Reply #3 on: December 04, 2012, 09:50:08 pm »
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ