.net 无法在C++;windows应用程序 我正在编写一个C++应用程序,我想给INI文件写一个整数值,这样每次运行应用程序时都能保留它。
但我无法在我的程序中使用WriteProfileInt()API,每当我使用它时,它都会给我以下错误:- “WriteProfileInt”:找不到标识符 但是GetProfileInt()工作正常,有人能建议我该怎么做吗? 我正在使用Visual Studio 2013 这是我正在使用的示例代码:-.net 无法在C++;windows应用程序 我正在编写一个C++应用程序,我想给INI文件写一个整数值,这样每次运行应用程序时都能保留它。,.net,winforms,winapi,c++-cli,.net,Winforms,Winapi,C++ Cli,但我无法在我的程序中使用WriteProfileInt()API,每当我使用它时,它都会给我以下错误:- “WriteProfileInt”:找不到标识符 但是GetProfileInt()工作正常,有人能建议我该怎么做吗? 我正在使用Visual Studio 2013 这是我正在使用的示例代码:- public ref class main_form : public System::Windows::Forms::Form { public: int i2c_addr; i
public ref class main_form : public System::Windows::Forms::Form
{
public:
int i2c_addr;
int temp;
main_form(void)
{
InitializeComponent();
}
void InitializeComponent(void)
{
WriteProfileInt(_T("device"),_T("i2c_address"),8);
temp = GetProfileInt(_T("device"),_T("i2c_address"),0);
this->i2c_addr = temp;
}
}
但是它给了我writeprofile(_T(“设备”),_T(“i2c_地址”),8的错误
请帮助我进一步进行此操作。在API级别,您需要执行以下操作:
char bf[50];
sprintf(bf,"%d", my_int_value);
WriteProfileString("MyApp", "MySection", bf); // will write to the registry
WritePrivateProfileString("C:\\myprog\\myprog.ini", "MySection", bf); // will write to the ini file
希望这有帮助您的代码试图将时钟拨回21年。回到Windows 3.11,Windows的最后一个版本仍然有Win.ini配置文件 这再也行不通了。winapi仍然支持GetProfileInt()来模拟Win.ini文件中的一些常见条目,并保持旧代码运行。但是WriteProfileInt()已被完全删除,因此没有希望假装.ini文件仍然存在并且可能正常工作。向后兼容性在Windows中是非常传奇的,但责任在某个地方停止了。你知道在哪里了
System.ini和Win.ini在功能上已被注册表取代。您可以使用它,或许,它提供对注册表的访问。在.NET中,建议使用应用程序设置来保持配置文件的基础。从C++/CLI来看并不方便,但是IDE不像其他语言那样具有设置设计器。将配置保存在XML文件中通常是一个不错的选择,使用System.XML命名空间中的类。请显示您的代码。public ref class main_form:public System::Windows::Forms::Forms{public:int i2c_addr;int temp;public:Thread^myThread;main_form(void){InitializeComponent()}void InitializeComponent(void){writeprofile(_T(“设备”),_T(“i2c_地址”),5);temp=GetProfileInt(_T(“设备”),_T(“i2c_地址”),0)你可以用代码来更新你的原始帖子。使用链接来添加代码。你也没有弄错这个问题。你不是在写C++应用程序,而是在使用.NETFramework。也不要使用<代码> GETPrimeSHIGRIGE> <代码>或
GetPrivateProfileString
和WritePrivateProfileString
!不,你不会。除非你是一个时间旅行者。自Windows 3时代以来,从未使用过WriteProfileString
。它写入WIN.INI文件le,这些应用程序不需要修改。您正在寻找的函数是WritePrivateProfileString
。而且您也不会使用窄字符串。Windows已经完全使用Unicode十多年了,现在是开始使用该程序的时候了。公平地说,WritePrivateProfileString
将编码与文件匹配,但是您仍然应该调用广域变量。此函数不写入任何profile.ini,如果这是有意的,它会写入注册表。如果不是,并且用户希望写入文件,则所有这些API函数都附带“Private”版本。它是一个方便的函数,用于简化从注册表的写入和读取。