CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Nov 2005
    Posts
    76

    Win32 API support in MFC Dialog based application.

    Dear Gurus,

    I belive that MFC supports win32 API's. But the function "OpenSCManager() " is giving me the error, i included header file "Windows.h" also.

    My question is whether we can use the "OpenSCManager()" function in MFC Dialog based applicaton.

    Thank You,
    Surender.

  2. #2
    Join Date
    Oct 2006
    Posts
    616

    Re: Win32 API support in MFC Dialog based application.

    MFC is just a framework built on top of the Win32 API. When using MFC there shouldn't be any trouble using Win32 API functions.

    Have you checked this function requirements in the msdn database ?
    Requires Windows Vista, Windows XP, or Windows 2000 Professional. Server Requires Windows Server 2008, Windows Server 2003, or Windows 2000 Server. Header Declared in Winsvc.h; include Windows.h.

    Library Use Advapi32.lib.

    DLL Requires Advapi32.dll.

    Unicode Implemented as OpenSCManagerW (Unicode) and OpenSCManagerA (ANSI).
    have you included the correct libs ? do you have access to the right dll ?

    Regards,
    Zachm

  3. #3
    Join Date
    Nov 2005
    Posts
    76

    Re: Win32 API support in MFC Dialog based application.

    HI Zachm,

    Those libraries are there. To make sure that OpenSCManager() function working i have crated two dumy projects.

    project 1: I have created a project using "Win32 console application" from the project menu. Here the OpenSCManager() function is working.

    project 2: Created a project using "MFC Appwizard(exe)" . Her in this project the function OpenSCManager is not working.

    This is the problem. Is there ang project settings i am missing...

    pls suggest me hat i have to do.


    Suren

  4. #4
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Win32 API support in MFC Dialog based application.

    Quote Originally Posted by A_Surender
    HI Zachm,

    Those libraries are there.
    If they were, there would be no error.

    First, what is the error that you're getting? You never mentioned anything except "it doesn't work". That is not enough information for us to tell you what is wrong.

    Second, in the linker settings, are those libraries specified? If not, then add those libraries.

    Third, including a header file only allows the source code to compile. After the compiling, the linker must find these functions implemented somewhere. If the linker can't find those functions, then you get a linker error. So just because you included a header file doesn't really mean anything when it comes to the link step when creating the executable.

    Regards,

    Paul McKenzie

  5. #5
    Join Date
    Nov 2005
    Posts
    76

    Re: Win32 API support in MFC Dialog based application.

    Hi,

    I am sorry iam replying very lately.

    The problem was at complie time. It saya the "Identifier is Undeclared". somehow that problem got solved by the time i returned from homtown.


    Thank you for responding

  6. #6
    Join Date
    Mar 2013
    Posts
    1

    Re: Win32 API support in MFC Dialog based application.

    goto stdafx.h and comment the following line

    #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers

  7. #7
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Win32 API support in MFC Dialog based application.

    OpenSCManager() is available from Windows 2000 only.

    If you're using a (very) old version of VS2010, then it won't be targetting above Win2000 by default, in fact, your platform SDK may not even have this function at all.

    I would expect you will need VS2003 at least and in that version, you will need to set your platform targetting to Win2000 at least.

    IIRC, in VS2005 you still needed to explicitely set windows version targetting to Win2000 as it targets Win98 by default.

  8. #8
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Win32 API support in MFC Dialog based application.

    Quote Originally Posted by OReubens View Post
    OpenSCManager() is available from Windows 2000 only.

    I never used this API though, but my old MSDN from October 2000 show me the following information:
    OpenSCManager
    ...
    Requirements
    Windows NT/2000: Requires Windows NT 3.1 or later.
    Header: Declared in Winsvc.h; include Windows.h.
    Library: Use Advapi32.lib.
    Unicode: Implemented as Unicode and ANSI versions on Windows NT/2000.
    Victor Nijegorodov

  9. #9
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: Win32 API support in MFC Dialog based application.

    @VictorN & OReubens
    [ off-topic ]
    I noticed that newer versions of MSDN tend to eliminate references to older Windows versions. Possible, they want to place them in the Dark (Windows Programming) Ages.
    For example, have a look at OpenSCManager function (Windows).
    It states as minimum required OS Windows XP or Windows Server 2003.

    Probably, 390 days from now, the "minimum required" for OpenSCManager will be Windows Vista or Windows Server 2008.
    And so on...

    Name:  Windows XP - End of Support.jpg
Views: 1332
Size:  5.2 KB

    But, without having a look in MSDN 2000, I'm sure it is supported in older NT versions, simply because I used OpenSCManager more than 15 years ago.


    @A_Surender
    [ on-topic ]

    Do not include <Windows.h> in MFC applications. That usually generates a compiler error.
    For OpenSCManager and related, include <Winsvc.h>, which also can be found in OpenSCManager documentation, under "Requirements".
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured