how to store settings in resource

前端 未结 2 1954
深忆病人
深忆病人 2020-12-22 03:02

i am trying to store some settings in resource of my application but failed i dont want to use ini file or registry methods i am using this code

    var
         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-22 03:49

    The documentation for BeginUpdateResource clearly states why your code doesn't work (emphasis added):

    pFileName [in]

    LPCTSTR

    The binary file in which to update resources. An application must be able to obtain write-access to this file; the file referenced by pFileName cannot be currently executing. If pFileName does not specify a full path, the system searches for the file in the current directory.

    You might have been able to deduce the cause of the error yourself if you were checking the API function's return value and calling GetLastError on failure, like the documentation advises.

    You can store settings in a resource, but you can't store settings in a resource of the program whose settings you're trying to store. And now that we've established that you're not allowed to store settings in the program itself, you may as well just abandon the resource idea and use a more conventional method of storing settings in an external location, such as the registry, an INI file, or whatever. You might still wish to read a set of default settings from a resource if you find that the external location doesn't yet have any settings, as might happen after a fresh install.

提交回复
热议问题