Can I force a compiler error if certain functions are called?

前端 未结 6 898
花落未央
花落未央 2021-01-11 13:19

I have v1 and v2 versions of my software. v1 uses the registry to save settings, with lots of calls to GetProfileInt, etc. v2 now uses an sqlite db to save settings.

<
6条回答
  •  自闭症患者
    2021-01-11 13:57

    Since this answer is accepted I might as well include the solution the asker actually used:

    jacobsee discovered the deprecated pragma

    #pragma deprecated(GetProfileInt)
    

    Original answer:

    You may be able to declare them as deprecated using __declspec(deprecated). It would look like this:

    UINT __declspec(deprecated) WINAPI GetProfileInt(
      __in  LPCTSTR lpAppName,
      __in  LPCTSTR lpKeyName,
      __in  INT nDefault
    );
    

    You'll have to do so from a header that is included in every translation unit you care about. Doing so will result in a warning any time a translation unit that includes the deprecated declaration uses that function.

    If you want a compiler error and if your project doesn't already treat warnings as errors then you'll have to turn that on, and maybe fix all the warnings you've been ignoring. (These are good practices whether you use this solution or not.)

提交回复
热议问题