Passing pointers to structs as function arguments

This is a discussion on Passing pointers to structs as function arguments within the C++ Programming forums, part of the General Programming Boards category; ...Why doesnt this work? (OPENFILENAME is a common struct in Win32API) Code: void FillInnOpenFileNameStruct(OPENFILENAME* lpofn) { *lpofn.lStructSize=sizeof (OPENFILENAME); *lpofn.hwndOwner=hwnd; *lpofn.hInstance=NULL; ...

  1. #1
    Politics&Cpp geek Da-Nuka's Avatar
    Join Date
    Oct 2004
    Posts
    104

    Passing pointers to structs as function arguments

    ...Why doesnt this work?
    (OPENFILENAME is a common struct in Win32API)

    Code:
    void FillInnOpenFileNameStruct(OPENFILENAME* lpofn) {
      *lpofn.lStructSize=sizeof (OPENFILENAME);
      *lpofn.hwndOwner=hwnd;
      *lpofn.hInstance=NULL;
      *lpofn.lpstrFilter="YAPI Presentations(*YAPI)\0*.YAPI\0All files (*.*)\0*.*\0\0";
      *lpofn.lpstrCustomFilter=NULL;
      *lpofn.nMaxCustFilter=0;
      *lpofn.nFilterIndex=0;
      *lpofn.lpstrFile=szFileName;
      *lpofn.nMaxFile=MAX_PATH;
      *lpofn.lpstrFileTitle=szTitle;
      *lpofn.nMaxFileTitle=MAX_PATH;
      *lpofn.lpstrInitialDir=NULL;
      *lpofn.lpstrTitle="Open file..";
      *lpofn.Flags=0;
      *lpofn.nFileOffset=0;
      *lpofn.nFileExtension=0;
      *lpofn.lpstrDefExt="YAPI";
      *lpofn.lCustData=0;
      *lpofn.lpfnHook=0;
      *lpofn.lpTemplateName=0;
    }

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,319
    The . has higher precedence than the *, so you must use (*lpofn).whatever=whatever or better yet, use lpofn->whatever=whatever.

  3. #3
    Politics&Cpp geek Da-Nuka's Avatar
    Join Date
    Oct 2004
    Posts
    104
    HAHA! Oh my god... thanks man!
    I cant belive i just did that noobish mistake
    Easy to forget, i guess

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. Pointers as function arguments
    By VanJay011379 in forum C Programming
    Replies: 1
    Last Post: 01-29-2003, 08:51 PM
  4. I need help with passing pointers in function calls
    By vien_mti in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 10:00 AM
  5. Passing an array of structs to a function
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 10-03-2001, 12:02 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21