Win32 function compile error (GetCurrentPositionEx)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RomeoPapacy
    New Member
    • Aug 2008
    • 11

    Win32 function compile error (GetCurrentPositionEx)

    I'm trying to write what should be a very simple program - a system tray based menu to allow me to quickly access files in a folder (for me a bunch of disc images). Unfotunately i'm stumped near completion.

    Basically the following code fails to compile with this error:

    Code:
    build/Debug/Cygwin-Windows/ImgMag.o: In function `_Z7WndProcP6HWND__jjl':
    /cygdrive/c/***CENSORED***/ImgMag/ImgMag.cpp:87: undefined reference to `_GetCurrentPositionEx@8'
    collect2: ld returned 1 exit status
    I can see the problem is with me calling GetCurrentPosit ionEx but i can't see what i've done wrong.

    Any help resolving this would be greatly appreciated.

    The Code:
    Code:
    #define _WINVER 0x505
    #define _WIN32_WINNT 0x505
    #ifdef NOGDI
    #undef NOGDI
    #endif
    #include <stdlib.h>
    #include <stdio.h>
    #include <windows.h>
    #include <wingdi.h>
    #include <map>
    #define ICON_MSG WM_USER+0
    #define IDM_MENU0 1000
    //Globals
    using namespace std;
    namespace globe {
        char trayClass[]="ImgMagCls";
        HWND tray;
        HICON tIcon;
        HMENU popup=CreatePopupMenu();
        HMENU* ptr;
        map<int,char*> menu;
        UINT count=0;
        UINT mx,my;
    }
    //Custom Functions
    int scanDir(char* Path){
        char wPath[strlen(Path)+1];
        strcpy(wPath,Path);strcat(wPath,"*");
        printf("%s\r\n",wPath);
        WIN32_FIND_DATA fd;
        HANDLE file = FindFirstFile(wPath,&fd);
        if(file==INVALID_HANDLE_VALUE){
            printf("ERR!!\r\n");
            return -1;
        }
        do{
            if((fd.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_ENCRYPTED)) || strlen(fd.cFileName)<3)
                continue;
            if(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY){
                HMENU newMenu=CreateMenu();
                HMENU* tmp=globe::ptr;
                globe::ptr = &newMenu;
                char newPath[strlen(Path)+strlen(fd.cFileName)];
                strcpy(newPath,Path);
                strcat(newPath,fd.cFileName);
                strcat(newPath,"\\");
                scanDir(newPath);
                globe::ptr=tmp;
                AppendMenu(*(globe::ptr),MF_ENABLED|MF_POPUP|MF_STRING,(UINT)newMenu,fd.cFileName);
            }else if(~FILE_ATTRIBUTE_HIDDEN & ~ FILE_ATTRIBUTE_SYSTEM){
                AppendMenu(*(globe::ptr),MF_ENABLED|MF_STRING,IDM_MENU0+globe::count,fd.cFileName);
                globe::menu[IDM_MENU0+globe::count]=(char*)&fd.cFileName;
                printf("%u: %s\r\n",IDM_MENU0+globe::count,fd.cFileName);
                globe::count++;
            }
        }while(FindNextFile(file,&fd));
    }
    
    //API Functions
    LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam){
        switch(msg){
            case WM_CREATE:{
                //Load Image
                globe::tIcon=(HICON) LoadImage(NULL,"ImgMag.ico",IMAGE_ICON,SM_CXSMICON,SM_CYSMICON,LR_LOADFROMFILE);
                NOTIFYICONDATA nid;
                nid.cbSize=sizeof(nid);
                nid.hIcon=globe::tIcon;
                nid.hWnd=hwnd;
                strcpy(nid.szTip,"Disc Image Magazine");
                nid.uCallbackMessage=ICON_MSG;
                nid.uFlags=NIF_ICON|NIF_MESSAGE|NIF_TIP;
                nid.uID=0;
                globe::ptr=&(globe::popup);
                scanDir("I:\\");
                Shell_NotifyIcon(NIM_ADD,&nid);
                printf("let's go...\r\n");
            }break;
            case ICON_MSG:{
                //printf("ICON_MSG:{%u,%u}\r\n",wParam,lParam);
                switch(lParam){
                    case WM_CONTEXTMENU:
                    case WM_LBUTTONUP:
                    case WM_RBUTTONUP:{
                        //ShowWindow(globe::tray,SW_SHOW);
                        POINT mp;
                        HDC hdc=GetDC(NULL);
                        GetCurrentPositionEx(hdc,(LPPOINT)&mp);
                        SetForegroundWindow(hwnd);
                        TrackPopupMenu(globe::popup,TPM_LEFTALIGN|TPM_TOPALIGN|TPM_RETURNCMD|TPM_RIGHTBUTTON,(int)mp.x,(int)mp.y,0,globe::tray,NULL);
                    }break;
                }
            }break;
            case WM_DESTROY:
                PostQuitMessage(0);
                break;
            default:
                //printf("MSG:%u\r\n",msg);
                return DefWindowProc(hwnd,msg,wParam,lParam);
        }
        return 0;
    }
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
        WNDCLASSEX wc;
        MSG Msg;
        //<editor-fold defaultstate="collapsed" desc="Window Class Definition">
        wc.cbSize = sizeof (WNDCLASSEX);
        wc.style = 0;
        wc.lpfnWndProc = WndProc;
        wc.cbClsExtra = 0;
        wc.cbWndExtra = 0;
        wc.hInstance = hInstance;
        wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
        wc.hCursor = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
        wc.lpszMenuName = NULL;
        wc.lpszClassName = globe::trayClass;
        wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
        if (!RegisterClassEx(&wc)) {
            MessageBox(NULL, "Window Registration Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
            return 1;
        }
        //</editor-fold>
        globe::tray = CreateWindowEx(WS_EX_CLIENTEDGE, globe::trayClass, "Disc Image Magazine", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
        if (globe::tray == NULL) {
            MessageBox(NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
            return 2;
        }
        while (GetMessage(&Msg, NULL, 0, 0) > 0) {
            TranslateMessage(&Msg);
            DispatchMessage(&Msg);
        }
    
        return (EXIT_SUCCESS);
    }
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    I'd like to help but this code uses non-ANS C++ features like this:
    [code=cpp]
    char wPath[strlen(Path)+1];
    [/code]

    I don't have time to fix it.

    Also, Windows code should be using the TCHAR mappings and not refer to char or char* directly.

    Maybe you could compile using the -pedantic switch and re-post incase no one else come forward.

    Comment

    • RomeoPapacy
      New Member
      • Aug 2008
      • 11

      #3
      Thanks for the note on TCHAR (i am quite new to C programming) Have replaced all instances of Char with TCHAR and both variable-length arrays now have array length MAX_PATH;

      Changes:

      27: TCHAR wPath[MAX_PATH];
      43: TCHAR newPath[MAX_PATH];

      However, the original problem still stands.

      Comment

      • Studlyami
        Recognized Expert Contributor
        • Sep 2007
        • 464

        #4
        There are a lot of problems with the code posted above. Are you receiving any others errors or just that one error? What compiler are you using? Verify that you have access to "wingdi.h". I used VS2005 and had no problems with the code you provided in finding GetCurrentPosit ionEX. There were other problems with variable types and non constant sizes of arrays, but i commented those areas out and I was able to compile.

        Comment

        • RomeoPapacy
          New Member
          • Aug 2008
          • 11

          #5
          Originally posted by Studlyami
          There are a lot of problems with the code posted above. Are you receiving any others errors or just that one error? What compiler are you using? Verify that you have access to "wingdi.h". I used VS2005 and had no problems with the code you provided in finding GetCurrentPosit ionEX. There were other problems with variable types and non constant sizes of arrays, but i commented those areas out and I was able to compile.
          I'm using netbeans 6.1 (i'm java at heart) with cygwin. it seems to have wingdi access. i'll have a go at compiling in MVSE.

          Comment

          • RomeoPapacy
            New Member
            • Aug 2008
            • 11

            #6
            Thanks for that it just seems that cygwin has let me down again (it just stopped working last time i gave C a go and MingW wouldn't read the NetBeans-generated make file)
            M$ Visual Studio Express seems to have done the trick (darn discombobulatin g compilerators never working for me :'( )

            [This thread can now be closed - i don't know how to though :(]

            Comment

            Working...