Win Api fenster problem
-
hi leute ich versuche mit der Winapi ein Fenster zu erstellen ... klappt aber leider nicht
/* * File: main.cpp * Author: hohlfeli * * Created on 23. September 2013, 08:25 */ #include <cstdlib> #include <windows.h> #include <stdlib.h> #include <stdio.h> #include <conio.h> #include <iostream> #include "SuperProMakeKey.h" #include "USDLL.H" #include "DSDLL.H" #include <ctype.h> // Window LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); const char szAppName[] = "Ein eigenes Fenster"; // Sentinel Infos #define HDR_DEMO_PROG_STR "\n %s %s\n Demonstration Program for DSAFE APIs\n" #define PROD_NAME_STR "SuperPro" #define VERSION_STR "7.1" #define COPYRIGHT_STR " Copyright (C) 2009 SafeNet, Inc." using namespace std; unsigned char GlobalBlock[5000] = { 0 }; PROD_LIST_PTR product_list_ptr = NULL; PROD_LIST product_list = { 0 } ; HINSTANCE hDSafeDLL = NULL; TSafeInitGlobalFnPtr SafeInitGlobalFnPtr = NULL; TDecodeLockingCodeFnPtr DecodeLockingCodeFnPtr = NULL; TGenerateUpdateStrFnPtr GenerateUpdateStrFnPtr = NULL; TGetTrustedActivationInfoFnPtr GetTrustedActivationInfoFnPtr = NULL; TGetDistributedActivationInfoFnPtr GetDistributedActivationInfoFnPtr = NULL; //For unidirectional update TSetUnidirectionalUpdateInfoFnPtr SetUnidirectionalUpdateInfoFnPtr = NULL; TSetDeveloperCodeFileFnPtr SetDeveloperCodeFileFnPtr = NULL; unsigned long SN = 0; #if _MSC_VER < 1400 #define scanf_s scanf #define gets_s(a, b) gets(a) #endif int InitDLL (){ //load DSAFE DLL hDSafeDLL = LoadLibrary ("DSAFE32.DLL"); if ( hDSafeDLL == NULL) { return -1; } //Get Addresses of export functions DecodeLockingCodeFnPtr = (TDecodeLockingCodeFnPtr)GetProcAddress(hDSafeDLL,"_DecodeLockingCode@16"); GenerateUpdateStrFnPtr = (TGenerateUpdateStrFnPtr)GetProcAddress(hDSafeDLL,"_GenerateUpdateStr@24"); SafeInitGlobalFnPtr = (TSafeInitGlobalFnPtr)GetProcAddress(hDSafeDLL,"_SAFEInitGlobal@4"); GetTrustedActivationInfoFnPtr = (TGetTrustedActivationInfoFnPtr)GetProcAddress(hDSafeDLL,"_GetTrustedActivationInfo@28"); GetDistributedActivationInfoFnPtr = (TGetDistributedActivationInfoFnPtr)GetProcAddress(hDSafeDLL,"_GetDistributedActivationInfo@28" ); //for unidirectional Update SetUnidirectionalUpdateInfoFnPtr = (TSetUnidirectionalUpdateInfoFnPtr)GetProcAddress(hDSafeDLL,"_SetUnidirectionalUpdateInfo@12"); SetDeveloperCodeFileFnPtr = (TSetDeveloperCodeFileFnPtr)GetProcAddress(hDSafeDLL,"_SetDeveloperCodeFile@24"); //check validation of the function pointer if (!SafeInitGlobalFnPtr || !GenerateUpdateStrFnPtr || !DecodeLockingCodeFnPtr ||!GetTrustedActivationInfoFnPtr || !GetDistributedActivationInfoFnPtr ||!SetDeveloperCodeFileFnPtr ||!SetUnidirectionalUpdateInfoFnPtr){ return -1; } return 0; } /*! \fn int InitDLL() \brief loading DSAFE64 DLL and initializing the function pointer \param none \return none */ int InitDLL64 (){ hDSafeDLL = LoadLibrary ("DSAFE64.DLL"); if ( hDSafeDLL == NULL) { return -1; } //Get Addresses of export functions DecodeLockingCodeFnPtr = (TDecodeLockingCodeFnPtr)GetProcAddress(hDSafeDLL,"DecodeLockingCode"); GenerateUpdateStrFnPtr = (TGenerateUpdateStrFnPtr)GetProcAddress(hDSafeDLL,"GenerateUpdateStr"); SafeInitGlobalFnPtr = (TSafeInitGlobalFnPtr)GetProcAddress(hDSafeDLL,"SAFEInitGlobal"); GetTrustedActivationInfoFnPtr = (TGetTrustedActivationInfoFnPtr)GetProcAddress(hDSafeDLL,"GetTrustedActivationInfo"); GetDistributedActivationInfoFnPtr = (TGetDistributedActivationInfoFnPtr)GetProcAddress(hDSafeDLL,"GetDistributedActivationInfo" ); //for unidirectional Update SetUnidirectionalUpdateInfoFnPtr = (TSetUnidirectionalUpdateInfoFnPtr)GetProcAddress(hDSafeDLL,"SetUnidirectionalUpdateInfo"); SetDeveloperCodeFileFnPtr = (TSetDeveloperCodeFileFnPtr)GetProcAddress(hDSafeDLL,"SetDeveloperCodeFile"); //check validation of the function pointer if (!SafeInitGlobalFnPtr || !GenerateUpdateStrFnPtr || !DecodeLockingCodeFnPtr || !GetTrustedActivationInfoFnPtr || !GetDistributedActivationInfoFnPtr||!SetDeveloperCodeFileFnPtr ||!SetUnidirectionalUpdateInfoFnPtr){ return -1; } return 0; } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ switch (message){ case WM_DESTROY: { PostQuitMessage(0); return 0; } } return DefWindowProc(hWnd, message, wParam, lParam); } /**/ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow){ HWND hWnd; MSG msg; WNDCLASS wc; wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hCursor = LoadCursor(NULL,IDC_ARROW); wc.hIcon = LoadIcon(NULL,IDI_APPLICATION); wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wc.lpszClassName = szAppName; wc.lpszMenuName = NULL; RegisterClass(&wc); hWnd = CreateWindow(szAppName, "Titelleiste", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, /* X-Position auf dem Monitor */ CW_USEDEFAULT, /* Y-Position auf dem Monitor */ CW_USEDEFAULT, /* Fensterbreite */ CW_USEDEFAULT, /* Fensterhoehe */ NULL, NULL, hInstance, NULL); ShowWindow(hWnd, iCmdShow); UpdateWindow(hWnd); while (GetMessage(&msg, NULL, 0, 0)){ TranslateMessage(&msg); DispatchMessage(&msg); } // DLL Initialisieren int check = InitDLL(); if (check != 0){ cout << endl << "ERROR while INIT DLL" << endl; } else { cout << endl << "DLL erfolgreich geladen" << endl; } MessageBox(NULL, "Goodbye, cruel world!", "Note", MB_OK); return 0; }
fehler:
"/C/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make.exe[1]: Entering directory/t/QuellP/Entwicklung/LCI_Player/Dongle/DongleWriter' "/C/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/donglewriter.exe make.exe[2]: Entering directory
/t/QuellP/Entwicklung/LCI_Player/Dongle/DongleWriter'
mkdir -p build/Debug/MinGW-Windows
rm -f build/Debug/MinGW-Windows/main.o.d
g++ -c -g -MMD -MP -MF build/Debug/MinGW-Windows/main.o.d -o build/Debug/MinGW-Windows/main.o main.cpp
mkdir -p dist/Debug/MinGW-Windows
g++ -o dist/Debug/MinGW-Windows/donglewriter build/Debug/MinGW-Windows/main.o
build/Debug/MinGW-Windows/main.o: In functionWinMain@16': T:\\QuellP\\Entwicklung\\LCI_Player\\Dongle\\DongleWriter/main.cpp:127: undefined reference to
GetStockObject@4'
collect2.exe: error: ld returned 1 exit status
make.exe[2]: *** [dist/Debug/MinGW-Windows/donglewriter.exe] Error 1
make.exe[2]: Leaving directory/t/QuellP/Entwicklung/LCI_Player/Dongle/DongleWriter' make.exe[1]: *** [.build-conf] Error 2 make.exe[1]: Leaving directory
/t/QuellP/Entwicklung/LCI_Player/Dongle/DongleWriter'
make.exe": *** [.build-impl] Error 2BUILD FAILED (exit value 2, total time: 21s)
kann mir jemand eventuell helfen?
-
du brauchst zum linken die Gdi32.lib
außerdem solltest du mal die implementation von InitDLL/64 ändern. immer weiter GetProcAddress aufrufen obwohl schon der erste aufruf failen könnte (was ja nicht sein dürfte) ist unsinnig. sprich: nach jedem aufruf den return wert checken (dafür lässt sich auch ein bequemes makro schreiben).