473,320 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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:

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

Any help resolving this would be greatly appreciated.

The Code:
Expand|Select|Wrap|Line Numbers
  1. #define _WINVER 0x505
  2. #define _WIN32_WINNT 0x505
  3. #ifdef NOGDI
  4. #undef NOGDI
  5. #endif
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. #include <windows.h>
  9. #include <wingdi.h>
  10. #include <map>
  11. #define ICON_MSG WM_USER+0
  12. #define IDM_MENU0 1000
  13. //Globals
  14. using namespace std;
  15. namespace globe {
  16.     char trayClass[]="ImgMagCls";
  17.     HWND tray;
  18.     HICON tIcon;
  19.     HMENU popup=CreatePopupMenu();
  20.     HMENU* ptr;
  21.     map<int,char*> menu;
  22.     UINT count=0;
  23.     UINT mx,my;
  24. }
  25. //Custom Functions
  26. int scanDir(char* Path){
  27.     char wPath[strlen(Path)+1];
  28.     strcpy(wPath,Path);strcat(wPath,"*");
  29.     printf("%s\r\n",wPath);
  30.     WIN32_FIND_DATA fd;
  31.     HANDLE file = FindFirstFile(wPath,&fd);
  32.     if(file==INVALID_HANDLE_VALUE){
  33.         printf("ERR!!\r\n");
  34.         return -1;
  35.     }
  36.     do{
  37.         if((fd.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_ENCRYPTED)) || strlen(fd.cFileName)<3)
  38.             continue;
  39.         if(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY){
  40.             HMENU newMenu=CreateMenu();
  41.             HMENU* tmp=globe::ptr;
  42.             globe::ptr = &newMenu;
  43.             char newPath[strlen(Path)+strlen(fd.cFileName)];
  44.             strcpy(newPath,Path);
  45.             strcat(newPath,fd.cFileName);
  46.             strcat(newPath,"\\");
  47.             scanDir(newPath);
  48.             globe::ptr=tmp;
  49.             AppendMenu(*(globe::ptr),MF_ENABLED|MF_POPUP|MF_STRING,(UINT)newMenu,fd.cFileName);
  50.         }else if(~FILE_ATTRIBUTE_HIDDEN & ~ FILE_ATTRIBUTE_SYSTEM){
  51.             AppendMenu(*(globe::ptr),MF_ENABLED|MF_STRING,IDM_MENU0+globe::count,fd.cFileName);
  52.             globe::menu[IDM_MENU0+globe::count]=(char*)&fd.cFileName;
  53.             printf("%u: %s\r\n",IDM_MENU0+globe::count,fd.cFileName);
  54.             globe::count++;
  55.         }
  56.     }while(FindNextFile(file,&fd));
  57. }
  58.  
  59. //API Functions
  60. LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam){
  61.     switch(msg){
  62.         case WM_CREATE:{
  63.             //Load Image
  64.             globe::tIcon=(HICON) LoadImage(NULL,"ImgMag.ico",IMAGE_ICON,SM_CXSMICON,SM_CYSMICON,LR_LOADFROMFILE);
  65.             NOTIFYICONDATA nid;
  66.             nid.cbSize=sizeof(nid);
  67.             nid.hIcon=globe::tIcon;
  68.             nid.hWnd=hwnd;
  69.             strcpy(nid.szTip,"Disc Image Magazine");
  70.             nid.uCallbackMessage=ICON_MSG;
  71.             nid.uFlags=NIF_ICON|NIF_MESSAGE|NIF_TIP;
  72.             nid.uID=0;
  73.             globe::ptr=&(globe::popup);
  74.             scanDir("I:\\");
  75.             Shell_NotifyIcon(NIM_ADD,&nid);
  76.             printf("let's go...\r\n");
  77.         }break;
  78.         case ICON_MSG:{
  79.             //printf("ICON_MSG:{%u,%u}\r\n",wParam,lParam);
  80.             switch(lParam){
  81.                 case WM_CONTEXTMENU:
  82.                 case WM_LBUTTONUP:
  83.                 case WM_RBUTTONUP:{
  84.                     //ShowWindow(globe::tray,SW_SHOW);
  85.                     POINT mp;
  86.                     HDC hdc=GetDC(NULL);
  87.                     GetCurrentPositionEx(hdc,(LPPOINT)&mp);
  88.                     SetForegroundWindow(hwnd);
  89.                     TrackPopupMenu(globe::popup,TPM_LEFTALIGN|TPM_TOPALIGN|TPM_RETURNCMD|TPM_RIGHTBUTTON,(int)mp.x,(int)mp.y,0,globe::tray,NULL);
  90.                 }break;
  91.             }
  92.         }break;
  93.         case WM_DESTROY:
  94.             PostQuitMessage(0);
  95.             break;
  96.         default:
  97.             //printf("MSG:%u\r\n",msg);
  98.             return DefWindowProc(hwnd,msg,wParam,lParam);
  99.     }
  100.     return 0;
  101. }
  102. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
  103.     WNDCLASSEX wc;
  104.     MSG Msg;
  105.     //<editor-fold defaultstate="collapsed" desc="Window Class Definition">
  106.     wc.cbSize = sizeof (WNDCLASSEX);
  107.     wc.style = 0;
  108.     wc.lpfnWndProc = WndProc;
  109.     wc.cbClsExtra = 0;
  110.     wc.cbWndExtra = 0;
  111.     wc.hInstance = hInstance;
  112.     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  113.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  114.     wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
  115.     wc.lpszMenuName = NULL;
  116.     wc.lpszClassName = globe::trayClass;
  117.     wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  118.     if (!RegisterClassEx(&wc)) {
  119.         MessageBox(NULL, "Window Registration Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
  120.         return 1;
  121.     }
  122.     //</editor-fold>
  123.     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);
  124.     if (globe::tray == NULL) {
  125.         MessageBox(NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
  126.         return 2;
  127.     }
  128.     while (GetMessage(&Msg, NULL, 0, 0) > 0) {
  129.         TranslateMessage(&Msg);
  130.         DispatchMessage(&Msg);
  131.     }
  132.  
  133.     return (EXIT_SUCCESS);
  134. }
Aug 16 '08 #1
5 2513
weaknessforcats
9,208 Expert Mod 8TB
I'd like to help but this code uses non-ANS C++ features like this:
Expand|Select|Wrap|Line Numbers
  1.  char wPath[strlen(Path)+1];
  2.  
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.
Aug 16 '08 #2
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.
Aug 16 '08 #3
Studlyami
464 Expert 256MB
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 GetCurrentPositionEX. 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.
Aug 16 '08 #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 GetCurrentPositionEX. 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.
Aug 16 '08 #5
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 discombobulating compilerators never working for me :'( )

[This thread can now be closed - i don't know how to though :(]
Aug 16 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: runes | last post by:
Hi, I'm trying to set the title of the console window (CMD.EXE) in Windows. I want it set to the basename of the current directory and it should stay after the script has finished. Now, the...
4
by: ZhangZQ | last post by:
Is it possible to dynamicaly to local and call a function in Win32 dll(not a ..net assembly dll) in C# at run time, for example, a C# program popup a dialogbox to let use input which Win32 dll to...
1
by: Avery Fong | last post by:
The following program will result in a compile error when building under Debug but will compile under Release. Why does is work under Release mode but not under Debug This program is developed...
14
by: vittorio | last post by:
While I can compile the program below under freebsd via a simple: gcc prog1.c -o prog1 and it runs smoothly, I'm experiencing annoying problems with lcc-win32 under windows xp pro. In fact, under...
0
by: =?Utf-8?B?Q29saXZpZXI=?= | last post by:
If anyone can help me with this I would really appreciate it: I have an assembly into which I have linked a manifest file as a Win32 resource. This is necessary since I want to use a class in this...
6
by: R.Kaiser | last post by:
I know that I can call Win32 API functions in a Windows forms application by specifying each function header individually like in using namespace System; using namespace...
3
by: Kevin | last post by:
Hi guys, I am a beginner for QT, and I installed the free qt 2.3 under windows (XP), as well as the MS's free VC expression edition (for their compilers, linkers, etc), and the SDK tool. My...
166
by: Nimmi Srivastav | last post by:
Apologies if my cross posting has offended anyone.... For a pure hobbyist C/C++ programmer, who wants to develop applications to run on Windows, what would be a better choice to install: Visual...
5
by: The Lord of the Strings | last post by:
I used to write in Turbo C++ 3 for DOS waaaay back, then moved to writing C in 32 bit windows using the standard windows api. I took a many years off to pursue my musical career and now I'm...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.