Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. macro function definition

macro function definition

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
21 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Mircea NeacsuM Mircea Neacsu

    Honestly, I don't think it's that useful to learn Win32 API. World has moved over to other technologies in the last 20-25 years. Whatever books you find, they are old (not much money to be made by authors writing about a dead subject) and the skills you acquire they are not in high demand.

    Mircea

    C Offline
    C Offline
    coco243
    wrote on last edited by
    #10

    I am feeling too that I am not quite on the right path. I wanted to enter in the world of programming and I started to learn C++. Then I said that C++ is a tool, and I realized that I have to do something with this tool and I have start to learn WINAPI beacause I wanted to be capable to design some interfaces from scrap. This was the path that I choose to walk through and I keept going, good or bad that was what I knew to do. Now I am at the finish of this WINAPI book and I am planning to learn and some data bases. I want to enter in the world of programming and to be able to work on my own, if you have advices for me I am more than glad to count on them. Thank you very much,

    L 1 Reply Last reply
    0
    • C coco243

      Hi, I am trying implementing this function:

      BOOL Dlg_OnInitDialog (HWND hwnd, HWND hwndFocus, LPARAM lParam)
      {
      RECT rect;

      // Associate an icon with the dialog box.
      chSETDLGICONS(hwnd, IDI\_DIRWALK, IDI\_DIRWALK);
      
      
      
      return(TRUE);
      

      }

      But the compiler give me this error: error C2065: 'strucure' : undeclared identifier, suggesting me that the error is at the chSETDLGICONS. The chSETDLGICONS is defined as a macro in a .h file:

      #define chINITSTRUCT(structure, fInitSize) \
      (ZeroMemory(&(strucure), sizeof(structure)), \
      fInitSize ? (*(int*) &(structure) = sizeof(structure)) : 0)

      // Dialog Box Icon Setting Macro

      #define chSETDLGICONS(hwnd, idiLarge, idiSmall) \
      { \
      OSVERSIONINFO VerInfo; \
      chINITSTRUCT(VerInfo, TRUE); \
      GetVersionEx(&VerInfo); \
      if ((VerInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) && \
      (VerInfo.dwMajorVersion <=3 && \
      VerInfo.dwMinorVersion <= 51)) \
      { \
      SetClassLong(hwnd, GCL_HICON, (LONG) \
      LoadIcon(GetWindowInstance(hwnd), \
      MAKEINTRESOURCE(idiLarge))); \
      } \
      else \
      { \
      SendMessage(hwnd, WM_SETICON, TRUE, (LPARAM) \
      LoadIcon(GetWindowInstance(hWnd), \
      MAKEINTRESOURCE(idilarge))); \
      SendMessage(hWnd, WM_SECTION, FALSE, (LPARAM) \
      LoadIcon(GetWindowInstance(hwnd), \
      MAKEINTRESOURCE(idiSmall))); \
      } \
      }

      From what I am seeing, structure is an identifier used in chINITSTRUCT function that is used in chSETDLGICONS, and I don't know how to repair that error. Please help me with this. Thank you in advance.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #11

      Why would you use a macro for something that you only need once? Or even if you need it more than once you should make it a callable function.

      C 1 Reply Last reply
      0
      • L Lost User

        Why would you use a macro for something that you only need once? Or even if you need it more than once you should make it a callable function.

        C Offline
        C Offline
        coco243
        wrote on last edited by
        #12

        I am trying to compile some code from a book to understand what the author wants to transmit. Maybe the book it is a bit old and that's why some tehniques are inappropiate.

        L 1 Reply Last reply
        0
        • C coco243

          I am trying to compile some code from a book to understand what the author wants to transmit. Maybe the book it is a bit old and that's why some tehniques are inappropiate.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #13

          The problem with using that sort of macro is that they are a pain to debug when something goes wrong. All you need to do is copy and paste the actual lines of code into your OnInitDialog function. And remember to remove all those backslashes. You can then easily step through line by line in the debugger if necessary.

          C 1 Reply Last reply
          0
          • L Lost User

            The problem with using that sort of macro is that they are a pain to debug when something goes wrong. All you need to do is copy and paste the actual lines of code into your OnInitDialog function. And remember to remove all those backslashes. You can then easily step through line by line in the debugger if necessary.

            C Offline
            C Offline
            coco243
            wrote on last edited by
            #14

            Yes, I had wondered myself if it is any method to see where is the error in this macro functions because compiler says generally that is an error in a macro function but you have to search through all lines of the code to see where the error could be. And those backslash are very wierd, I don't know what is their role.

            L 1 Reply Last reply
            0
            • C coco243

              I am feeling too that I am not quite on the right path. I wanted to enter in the world of programming and I started to learn C++. Then I said that C++ is a tool, and I realized that I have to do something with this tool and I have start to learn WINAPI beacause I wanted to be capable to design some interfaces from scrap. This was the path that I choose to walk through and I keept going, good or bad that was what I knew to do. Now I am at the finish of this WINAPI book and I am planning to learn and some data bases. I want to enter in the world of programming and to be able to work on my own, if you have advices for me I am more than glad to count on them. Thank you very much,

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #15

              coco243 wrote:

              if you have advices for me I am more than glad to count on them.

              Well, I am sorry to say that you have probably wasted your time learning the Windows API. Especially so if you now want to learn database programming. You really need to move into the .NET field if you expect to make a career in programming. .NET Book Zero by Charles Petzold[^] is an excellent introduction. Beyond that there are plenty of free tutorials online, for advanced C# and database programming. A word of warning: stay clear of youtube tutorials as they tend to be less than good quality.

              C 1 Reply Last reply
              0
              • C coco243

                Yes, I had wondered myself if it is any method to see where is the error in this macro functions because compiler says generally that is an error in a macro function but you have to search through all lines of the code to see where the error could be. And those backslash are very wierd, I don't know what is their role.

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #16

                The backslashes are there to tell the macro processor to include them all until it finds a line that just ends in a newline.

                #define FOO(x) \ // means the definition continues onto the next line
                x *= 25; \ // still more to come
                printf("X = %d\n"); // no backslash so this is the last line to include

                1 Reply Last reply
                0
                • L Lost User

                  coco243 wrote:

                  if you have advices for me I am more than glad to count on them.

                  Well, I am sorry to say that you have probably wasted your time learning the Windows API. Especially so if you now want to learn database programming. You really need to move into the .NET field if you expect to make a career in programming. .NET Book Zero by Charles Petzold[^] is an excellent introduction. Beyond that there are plenty of free tutorials online, for advanced C# and database programming. A word of warning: stay clear of youtube tutorials as they tend to be less than good quality.

                  C Offline
                  C Offline
                  coco243
                  wrote on last edited by
                  #17

                  Richard MacCutchan wrote:

                  Well, I am sorry to say that you have probably wasted your time learning the Windows API

                  I saw in that a possibility to learn making an user interface in my desire to make stand alone applications.

                  Richard MacCutchan wrote:

                  Especially so if you now want to learn database programming

                  I don't necessary want to learn database programming but I consider that when you build applications you would need to use databases at some time.

                  Richard MacCutchan wrote:

                  You really need to move into the .NET field if you expect to make a career in programming. .NET Book Zero by Charles Petzold[^] is an excellent introduction.

                  Thank you for the advice, and for the resource link.

                  L 1 Reply Last reply
                  0
                  • C coco243

                    Richard MacCutchan wrote:

                    Well, I am sorry to say that you have probably wasted your time learning the Windows API

                    I saw in that a possibility to learn making an user interface in my desire to make stand alone applications.

                    Richard MacCutchan wrote:

                    Especially so if you now want to learn database programming

                    I don't necessary want to learn database programming but I consider that when you build applications you would need to use databases at some time.

                    Richard MacCutchan wrote:

                    You really need to move into the .NET field if you expect to make a career in programming. .NET Book Zero by Charles Petzold[^] is an excellent introduction.

                    Thank you for the advice, and for the resource link.

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #18

                    coco243 wrote:

                    I saw in that a possibility to learn making an user interface in my desire to make stand alone applications.

                    Which is so much easier to do in .NET as the framework does all the detailed fiddling about, and leaves you to focus on the actual presentation and business logic.

                    C 1 Reply Last reply
                    0
                    • L Lost User

                      coco243 wrote:

                      I saw in that a possibility to learn making an user interface in my desire to make stand alone applications.

                      Which is so much easier to do in .NET as the framework does all the detailed fiddling about, and leaves you to focus on the actual presentation and business logic.

                      C Offline
                      C Offline
                      coco243
                      wrote on last edited by
                      #19

                      Thank you for your thoughts, I will end this WINAPI subject book because I have a few chapters until the end and I have to finish what I have started and I will start reading your sugested documentation about .NET because, honestly I don't have a clear image about what .NET it is and could de but I think that the fact that I had learned something about WINAPI apps will help me to beter understanding. Thank you.

                      1 Reply Last reply
                      0
                      • Mircea NeacsuM Mircea Neacsu

                        Honestly, I don't think it's that useful to learn Win32 API. World has moved over to other technologies in the last 20-25 years. Whatever books you find, they are old (not much money to be made by authors writing about a dead subject) and the skills you acquire they are not in high demand.

                        Mircea

                        T Offline
                        T Offline
                        trønderen
                        wrote on last edited by
                        #20

                        If you learn something for the intention of making yourself an income, then the Win32 API is not the right choice in the year 2025. On the other hand ... I learned Windows programming before there was a WIN32 API, it was way back in the 16-bit days of the "WIN16 API" (it was never called that). My primary learning was not an API, but event driven programming: Taking your data structures from one consistent state to another consistent state in well defined, atomic steps. Always leaving your data so that it can be properly used by anyone else the next time something happens. No loose ends, no garbage on the floor. Looking upon each event cycle similar to a database transaction. A great philosophy for building robust software. Often, programmers show me code: 'See, I am doing event driven programming too - here is the switch case on the input value!' But even driven is so much more than a switch statement. What I see is a lot of other logic that is not at all related to the state and event, lots of loose ends, lots of garbage variables affecting the state without being treated as state data. The Windows model put a strong pressure on you to do 'clean' event driven coding. Today, working in C#, I still think in event/state terms, taking data structures through well defined, finite processing steps from on consistent state to another. I didn't learn that from any book published this millennium. I didn't learn it from younger coworkers. I didn't learn it from browsing programming forums on the Internet. I learned it from the Windows API. I am really happy to have that background when programming in the year 2022, with the tools of year 2022. Learning the Windows API / event driven programming was certainly no waste of time. It has great value for me, even today.

                        C 1 Reply Last reply
                        0
                        • T trønderen

                          If you learn something for the intention of making yourself an income, then the Win32 API is not the right choice in the year 2025. On the other hand ... I learned Windows programming before there was a WIN32 API, it was way back in the 16-bit days of the "WIN16 API" (it was never called that). My primary learning was not an API, but event driven programming: Taking your data structures from one consistent state to another consistent state in well defined, atomic steps. Always leaving your data so that it can be properly used by anyone else the next time something happens. No loose ends, no garbage on the floor. Looking upon each event cycle similar to a database transaction. A great philosophy for building robust software. Often, programmers show me code: 'See, I am doing event driven programming too - here is the switch case on the input value!' But even driven is so much more than a switch statement. What I see is a lot of other logic that is not at all related to the state and event, lots of loose ends, lots of garbage variables affecting the state without being treated as state data. The Windows model put a strong pressure on you to do 'clean' event driven coding. Today, working in C#, I still think in event/state terms, taking data structures through well defined, finite processing steps from on consistent state to another. I didn't learn that from any book published this millennium. I didn't learn it from younger coworkers. I didn't learn it from browsing programming forums on the Internet. I learned it from the Windows API. I am really happy to have that background when programming in the year 2022, with the tools of year 2022. Learning the Windows API / event driven programming was certainly no waste of time. It has great value for me, even today.

                          C Offline
                          C Offline
                          coco243
                          wrote on last edited by
                          #21

                          Although I am not initiated in programming, I felt it when I started to learn C++ and MFC despite C#, that C++ is more closer to the hardware components, to the heart of the machine, I felt that with C++ I can put my hands and get dirty, and so on that with WINAPI I can comunicate more closer with WINDOWS system, through the windows API functions, I felt that those are the right and honest stpes to get started in programming, I felt that these are the basics that I have to know to start an healty way of programming. But my goal is as you expressed yourself " to make myself an income" and for that appears that I have to learn more tools to be able to deliver a stand alone product. I don't know if my path is the good one but I keep pushing until I will succed. Thank you.

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups